883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
93 lines
6.2 KiB
Python
93 lines
6.2 KiB
Python
"""One new478 liquid family; old Ocean36/Area313/terrain checks are reused."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
from collections import Counter
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
from map_asset_preflight import _adt_split_chunk, _adt_split_records, adt_root_still_river_candidate
|
|
J=Path('runtime/continuation-20261026/openworld-Still-River-liquid-contract')
|
|
inputs=json.loads(Path('runtime/continuation-20261026/Root-named-openworld-area-status/held-outdoor-liquid-operands.json').read_text())['rows']
|
|
OUT=J/'private-ROOT-candidates';OUT.mkdir(exist_ok=True)
|
|
progress=J/'completed-new-candidate-rows.jsonl';heldfile=J/'held-new-candidate-rows.jsonl'
|
|
passed=[json.loads(x) for x in progress.read_text().splitlines()] if progress.exists() else []
|
|
held=[json.loads(x) for x in heldfile.read_text().splitlines()] if heldfile.exists() else []
|
|
done={r['source_reference'] for r in passed+held}
|
|
|
|
def enc(rows):return b''.join(_adt_split_chunk(t,p)+z for t,p,z in rows)
|
|
|
|
def verify(old,new):
|
|
before,after=_adt_split_records(old),_adt_split_records(new)
|
|
assert [(t,p,z) for t,p,z in before if t not in ('MHDR','MH2O','MCNK')]==[(t,p,z) for t,p,z in after if t not in ('MHDR','MH2O','MCNK')]
|
|
ha=next(p for t,p,z in before if t=='MHDR');hb=next(p for t,p,z in after if t=='MHDR')
|
|
assert all(ha[n*4:n*4+4]==hb[n*4:n*4+4] for n in range(16) if n not in (9,10,11))
|
|
offset=0
|
|
for t,p,z in after:
|
|
if t in ('MFBO','MH2O','MTXF'):assert struct.unpack_from('<I',hb,{'MFBO':9,'MH2O':10,'MTXF':11}[t]*4)[0]==offset-20
|
|
offset+=8+len(p)+len(z)
|
|
liquid=next(p for t,p,z in after if t=='MH2O')
|
|
a=[p for t,p,z in before if t=='MCNK'];b=[p for t,p,z in after if t=='MCNK'];assert len(a)==len(b)==256
|
|
instances=still=0
|
|
for original,changed in zip(a,b):
|
|
wa=struct.unpack_from('<32I',original);wb=struct.unpack_from('<32I',changed)
|
|
assert wb[0]==wa[0]&~0x3c and wb[24:26]==(0,0)
|
|
assert all(wa[n]==wb[n] for n in range(1,32) if n not in (22,24,25,29))
|
|
ca,cb=_adt_split_records(original[128:]),_adt_split_records(changed[128:])
|
|
assert [(t,p,z) for t,p,z in ca if t!='MCLQ']==cb
|
|
offset=128;child={}
|
|
for t,p,z in cb:child[t]=offset+8;offset+=8+len(p)+len(z)
|
|
assert wb[22]==child.get('MCSE',0) and wb[29]==child.get('MCCV',0)
|
|
x,y=wa[1:3];off,count,attrs=struct.unpack_from('<3I',liquid,(y*16+x)*12)
|
|
expected=(wa[0]&0x3c).bit_count();assert count==expected
|
|
if not count:assert(off,attrs)==(0,0);continue
|
|
blocks=next(p for t,p,z in ca if t=='MCLQ')
|
|
for layer in range(count):
|
|
block=blocks[layer*804:(layer+1)*804]
|
|
typ,fmt,lo,hi,ox,oy,w,h,exists,vertex=struct.unpack_from('<HHffBBBBII',liquid,off+layer*24)
|
|
wet=[(n,f) for n,f in enumerate(block[656:720]) if f&15!=15]
|
|
assert typ==({0:1,1:2}[wet[0][1]&3]) and (fmt,ox,oy,w,h)==(0,0,0,8,8)
|
|
assert liquid[off+layer*24+4:off+layer*24+12]==block[:8]
|
|
assert struct.unpack_from('<Q',liquid,exists)[0]==sum(1<<n for n,f in wet)
|
|
assert struct.unpack_from('<QQ',liquid,attrs)==(sum(1<<n for n,f in wet if f&0x40),sum(1<<n for n,f in wet if f&0x80))
|
|
assert liquid[vertex:vertex+324]==b''.join(block[12+v*8:16+v*8] for v in range(81))
|
|
assert liquid[vertex+324:vertex+405]==bytes(block[8+v*8] for v in range(81))
|
|
instances+=1;still+=typ==1
|
|
return instances,still
|
|
|
|
sample=None
|
|
for row in inputs:
|
|
if row['source_reference'] in done:continue
|
|
# Exclude already-completed Ocean36 by frozen owning input membership, not rerun.
|
|
old=Path(row['input_ROOT']).read_bytes();authority=any(t=='MH2O' for t,p,z in _adt_split_records(old))
|
|
try:new,audit=adt_root_still_river_candidate(old,source_legacy_authoritative=authority)
|
|
except ValueError as e:
|
|
r=dict(source_reference=row['source_reference'],reason=str(e));held.append(r)
|
|
with heldfile.open('a') as f:f.write(json.dumps(r)+'\n')
|
|
continue
|
|
instances,still=verify(old,new);assert instances==audit['instances'] and still==audit['Still_instances']
|
|
path=OUT/(Path(row['source_reference']).stem+'.root.adt');path.write_bytes(new)
|
|
r=dict(source_reference=row['source_reference'],input_ROOT=row['input_ROOT'],output_ROOT=str(path),bytes=len(new),sha256=hashlib.sha256(new).hexdigest(),audit=audit)
|
|
passed.append(r)
|
|
with progress.open('a') as f:f.write(json.dumps(r,separators=(',',':'))+'\n')
|
|
if sample is None:sample=(old,authority)
|
|
assert passed
|
|
if sample is None:
|
|
old=Path(passed[0]['input_ROOT']).read_bytes();sample=(old,any(t=='MH2O' for t,p,z in _adt_split_records(old)))
|
|
raw,authority=sample;top=_adt_split_records(raw)
|
|
ci=next(n for n,(t,p,z) in enumerate(top) if t=='MCNK' and struct.unpack_from('<I',p)[0]&0x3c)
|
|
cell=top[ci][1];children=_adt_split_records(cell[128:]);mi=next(n for n,r in enumerate(children) if r[0]=='MCLQ');block=children[mi][1]
|
|
refusals=[]
|
|
def refuse(label,payload):
|
|
parts=list(children);parts[mi]=('MCLQ',payload,b'');records=list(top);records[ci]=('MCNK',cell[:128]+enc(parts),b'')
|
|
try:adt_root_still_river_candidate(enc(records),source_legacy_authoritative=authority)
|
|
except ValueError:refusals.append(label)
|
|
else:raise AssertionError(label)
|
|
wet=next(n for n,f in enumerate(block[656:720]) if f&15!=15)
|
|
for label,offset,value in [('flow_count',720,struct.pack('<I',1)),('unqualified_flow_tail',724,b'\x01'),('unsupported_Magma',656+wet,b'\x42'),('union_high3',9,b'\x01'),('nonfinite_height',12,struct.pack('<f',float('nan'))),('inverted_bounds',0,struct.pack('<2f',10.,-10.))]:
|
|
b=bytearray(block);b[offset:offset+len(value)]=value;refuse(label,bytes(b))
|
|
report=dict(status='PASS_CHANGED_STILL_RIVER_HEIGHT_DEPTH_CONSTRUCTOR_AND_NEW_BATCH',input_denominator=len(inputs),accepted_tiles=len(passed),held_tiles=len(held),instances=sum(r['audit']['instances'] for r in passed),Still_instances=sum(r['audit']['Still_instances'] for r in passed),Ocean_instances=sum(r['audit']['Ocean_instances'] for r in passed),held_reasons=dict(Counter(r['reason'] for r in held)),refusals=refusals,all_nonliquid_payloads_preserved=True,height_depth_and_bounds_bytes_exact=True,Source_exports=0,SDK_checks=0,native_actions=0,runtime_acceptance=False,native_shading_equivalence=False)
|
|
(J/'focused-result.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
(J/'candidate-manifest.json').write_text(json.dumps(dict(status=report['status'],rows=passed,held=held),indent=2)+'\n')
|
|
print(report['status'],len(passed),'tiles;',len(held),'held')
|