Match original collision rounding through populated dynamic reclip
This commit is contained in:
1 parent
135ff3642a
commit
bf876e9c3c
22 files changed
+701
-14
No files matched your search
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Capture populated-grid dynamic/static component state from copied originals."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import struct
|
||||
from pathlib import Path
|
||||
from dynamic_context import generate
|
||||
from checkpoint_script_state import find_case
|
||||
|
||||
CASES=('nearer_wall','equal_dynamic_face','far_wall','two_near_first','two_far_first',
|
||||
'nearer_callback_root','inhibit_static_visit','geometry_off_visits','forced_primitive_mode',
|
||||
'stale_ceiling_callback','ceiling_response','wall_and_ceiling','retained_first','retained_second')
|
||||
|
||||
|
||||
def differences(expected,actual,path=''):
|
||||
"""Exact float32 comparison; report missing/extra fields, never use epsilon."""
|
||||
if isinstance(expected,dict) and isinstance(actual,dict):
|
||||
if expected.keys()!=actual.keys():return [dict(path=path,reason='fields differ')]
|
||||
return [d for key in expected for d in differences(expected[key],actual[key],path+'.'+key)]
|
||||
if isinstance(expected,list) and isinstance(actual,list):
|
||||
if len(expected)!=len(actual):return [dict(path=path,reason='length differs')]
|
||||
return [d for i,(a,b) in enumerate(zip(expected,actual)) for d in differences(a,b,path+f'[{i}]')]
|
||||
if isinstance(expected,(int,float)) and isinstance(actual,(int,float)):
|
||||
same=struct.pack('<f',expected)==struct.pack('<f',actual)
|
||||
else:same=expected==actual
|
||||
return [] if same else [dict(path=path,original=expected,managed=actual)]
|
||||
|
||||
|
||||
def compare(output,managed):
|
||||
native=json.loads((output/'observations.json').read_text());actual=json.loads(managed.read_text())
|
||||
if any(tuple(c['name'] for c in data['cases'])!=CASES for data in (native,actual)):
|
||||
raise ValueError('Case sequence changed')
|
||||
cases=[dict(name=a['name'],differences=differences(a,b)) for a,b in zip(native['cases'],actual['cases'])]
|
||||
if any([s['index'] for s in data['diagnostic_steps']]!=list(range(12)) for data in (native,actual)):
|
||||
raise ValueError('Kernel trace incomplete')
|
||||
steps=[dict(index=a['index'],differences=differences(a,b)) for a,b in zip(native['diagnostic_steps'],actual['diagnostic_steps'])]
|
||||
result=dict(exact_cases=sum(not c['differences'] for c in cases),total_cases=len(cases),
|
||||
cases=cases,diagnostic_steps=steps,scope='Exact parsed float32 comparisons, no tolerance. Differences are unresolved, not accepted source parity.')
|
||||
(output/'comparison.json').write_text(json.dumps(result,indent=2)+'\n')
|
||||
return result
|
||||
|
||||
|
||||
def prepare(original,output):
|
||||
result=generate(original,output)
|
||||
source=output/'dynamic_context_probe.c'
|
||||
source.write_text(source.read_text().split('int main(void)')[0])
|
||||
(output/'dynamic_reclip_probe.c').write_text(Path(__file__).with_name('dynamic_reclip_probe.c').read_text())
|
||||
return result
|
||||
|
||||
|
||||
def capture(output,directory):
|
||||
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
source=json.loads((output/'source.json').read_text())
|
||||
metadata=json.loads((directory/'capture.json').read_text())
|
||||
log=(directory/'wine.log').read_text()
|
||||
if metadata['captures'][-1]['wineExit']!=0 or 'DYNAMIC_RECLIP_COMPLETE' not in log:
|
||||
raise ValueError('Incomplete component execution')
|
||||
for filename,key in [('Neutron.exe','sha256'),('OMT2.dll','omt_sha256')]:
|
||||
if sha(find_case(directory/'game',filename))!=source[key]:raise ValueError('Copied source mismatch')
|
||||
if json.loads((directory/'probe-identity.json').read_text())['sha256']!=sha(output/'probe.exe'):
|
||||
raise ValueError('Probe identity mismatch')
|
||||
cases=[json.loads(line[7:]) for line in log.splitlines() if line.startswith('RECLIP ')]
|
||||
if tuple(c['name'] for c in cases)!=CASES:raise ValueError('Case sequence changed')
|
||||
files=[directory/'wine.log',directory/'capture.json',directory/'probe-identity.json',output/'source.json',
|
||||
*(output/name for name in ('dynamic_reclip_probe.c','dynamic_context_probe.c','collision_dispatch_probe.c',
|
||||
'collision_response_probe.c','collision_response_relocations.h','probe.exe'))]
|
||||
steps=[json.loads(line[12:]) for line in log.splitlines() if line.startswith('KERNEL_STEP ')]
|
||||
if [s['index'] for s in steps]!=list(range(12)):raise ValueError('Incomplete diagnostic kernel trace')
|
||||
result=dict(cases=cases,diagnostic_steps=steps,provenance={str(p):sha(p) for p in files},
|
||||
scope='Complete copied dynamic query/static dispatcher/kernel; synthetic actors/callbacks/transforms and populated grid. Not full scene or real actor execution.')
|
||||
(output/'observations.json').write_text(json.dumps(result,indent=2)+'\n')
|
||||
return dict(cases=len(cases),scope=result['scope'])
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
cli=argparse.ArgumentParser(description=__doc__)
|
||||
cli.add_argument('original',type=Path);cli.add_argument('--output',type=Path,required=True)
|
||||
mode=cli.add_mutually_exclusive_group()
|
||||
mode.add_argument('--capture',type=Path);mode.add_argument('--managed',type=Path);args=cli.parse_args()
|
||||
print(json.dumps(compare(args.output,args.managed) if args.managed else
|
||||
capture(args.output,args.capture) if args.capture else prepare(args.original,args.output),indent=2))
|
||||
@@ -0,0 +1,83 @@
|
||||
/* Complete original dynamic box + populated static grid; bounded actor fixtures.
|
||||
* Included source is generated without its standalone main. Originals untouched. */
|
||||
#include "dynamic_context_probe.c"
|
||||
static unsigned char stale_polygon[0x30];
|
||||
static char events[4096];
|
||||
static unsigned event_length,kernel_zero,kernel_lower;
|
||||
static int tracing;
|
||||
static unsigned trace_steps;
|
||||
static void vector_json(Vec p){printf("[%.9g,%.9g,%.9g,%.9g]",p.x,p.y,p.z,p.w);}
|
||||
|
||||
static int polygon_id(void *p) {
|
||||
if(!p)return -1;
|
||||
if(p==stale_polygon)return 99;
|
||||
if(p==polygon[0])return 0;
|
||||
if(p==polygon[1])return 1;
|
||||
require(0,"unknown fixture polygon");return -2;
|
||||
}
|
||||
static void event(unsigned slot,void*p) {
|
||||
int count=snprintf(events+event_length,sizeof(events)-event_length,
|
||||
"%s%x:%d:%u",event_length?",":"",slot,polygon_id(p),*(unsigned*)AT(0x695d74));
|
||||
require(count>0&&event_length+(unsigned)count<sizeof(events),"event bound");
|
||||
event_length+=(unsigned)count;
|
||||
}
|
||||
static void TC response370(void*self,Vec n,void*p){event(0x370,p);on_contact(self,n,p);}
|
||||
static void TC response374(void*self,Vec n,void*p){event(0x374,p);on_contact(self,n,p);}
|
||||
static void TC publish(void*self,Vec p){event(0x314,NULL);set_root(self,p);}
|
||||
static unsigned observe_kernel(Vec a,Vec b,Vec c,Vec n,Vec previous,Vec*current,float radius,int edges) {
|
||||
Vec input=*current;
|
||||
if(*(unsigned*)AT(0x695d74))kernel_lower++;else kernel_zero++;
|
||||
memcpy(AT(0x47bd80),kernel_prefix,5);
|
||||
unsigned result=((Kernel)AT(0x47bd80))(a,b,c,n,previous,current,radius,edges);
|
||||
if(tracing&&trace_steps<12){
|
||||
printf("KERNEL_STEP {\"index\":%u,\"input\":",trace_steps++);vector_json(input);
|
||||
printf(",\"output\":");vector_json(*current);
|
||||
printf(",\"contact\":%u,\"face\":%.9g,\"edge\":%.9g,\"hit\":",result&255,
|
||||
*(float*)AT(0x695d5c),*(float*)AT(0x5cfbe0));vector_json(*(Vec*)AT(0x5cfbe8));puts("}");
|
||||
}
|
||||
hook_jump(AT(0x47bd80),observe_kernel);return result;
|
||||
}
|
||||
static void setup(void) {
|
||||
reset();event_length=kernel_zero=kernel_lower=trace_steps=0;events[0]=0;tracing=0;
|
||||
memset(stale_polygon,0,sizeof(stale_polygon));
|
||||
*(Vec*)(stale_polygon+8)=(Vec){0,0,1,0};*(void**)AT(0x695d4c)=stale_polygon;
|
||||
sphere_table[0x370/4]=(uintptr_t)response370;sphere_table[0x374/4]=(uintptr_t)response374;
|
||||
sphere_table[0x314/4]=(uintptr_t)publish;
|
||||
}
|
||||
static void z_wall(unsigned id,float z) {
|
||||
add_triangle(id,(Vec){-100,-100,z,1},(Vec){-100,100,z,1},
|
||||
(Vec){100,100,z,1},(Vec){0,0,1,0});
|
||||
}
|
||||
static void result(const char*name) {
|
||||
int hit=((int(__cdecl*)(void*,void*))AT(0x47a5e0))(box_object,sphere_object)&255;
|
||||
Vec h=*(Vec*)AT(0x5cfbe8);
|
||||
printf("RECLIP {\"name\":\"%s\",\"contact\":%d,\"root\":[%.9g,%.9g,%.9g,%.9g],\"face\":%.9g,\"edge\":%.9g,\"hit\":[%.9g,%.9g,%.9g,%.9g],\"last\":%d,\"dynamicCallbacks\":%u,\"staticCallbacks\":%u,\"setters\":%u,\"passes\":%u,\"visits\":%u,\"mode\":%u,\"kernelZero\":%u,\"kernelLower\":%u,\"events\":\"%s\"}\n",
|
||||
name,hit,sphere_root.x,sphere_root.y,sphere_root.z,sphere_root.w,
|
||||
*(float*)AT(0x695d5c),*(float*)AT(0x5cfbe0),h.x,h.y,h.z,h.w,
|
||||
polygon_id(*(void**)AT(0x695d4c)),dynamic_callbacks,static_callbacks,setters,
|
||||
*(unsigned*)AT(0x695d78),*(unsigned*)AT(0x695d70),*(unsigned*)AT(0x695d74),
|
||||
kernel_zero,kernel_lower,events);
|
||||
}
|
||||
int main(void) {
|
||||
setbuf(stdout,NULL);map_copy();
|
||||
memcpy(kernel_prefix,AT(0x47bd80),5);hook_jump(AT(0x47bd80),observe_kernel);
|
||||
setup();z_wall(0,35);result("nearer_wall");
|
||||
setup();z_wall(0,10);result("equal_dynamic_face");
|
||||
setup();z_wall(0,0);result("far_wall");
|
||||
setup();z_wall(0,35);z_wall(1,30);result("two_near_first");
|
||||
setup();z_wall(0,30);z_wall(1,35);result("two_far_first");
|
||||
setup();z_wall(0,35);mutate=1;result("nearer_callback_root");
|
||||
setup();z_wall(0,35);inhibit=1;result("inhibit_static_visit");
|
||||
setup();z_wall(0,35);*(unsigned char*)AT(0x4f69e5)=0;result("geometry_off_visits");
|
||||
setup();z_wall(0,35);sphere_object[0x42c]=1;result("forced_primitive_mode");
|
||||
setup();z_wall(0,0);*(Vec*)(stale_polygon+8)=(Vec){0,-1,0,0};result("stale_ceiling_callback");
|
||||
setup();z_wall(0,0);sphere_root.y=30;
|
||||
add_triangle(1,(Vec){-100,35,-100,1},(Vec){-100,35,100,1},(Vec){100,35,100,1},(Vec){0,-1,0,0});
|
||||
result("ceiling_response");
|
||||
setup();z_wall(0,35);sphere_previous.y=-30;
|
||||
add_triangle(1,(Vec){-100,5,-100,1},(Vec){100,5,100,1},(Vec){100,5,-100,1},(Vec){0,-1,0,0});
|
||||
tracing=1;result("wall_and_ceiling");
|
||||
setup();z_wall(0,35);result("retained_first");
|
||||
sphere_previous=(Vec){0,0,50,1};sphere_root=(Vec){0,0,15,1};result("retained_second");
|
||||
puts("DYNAMIC_RECLIP_COMPLETE");return 0;
|
||||
}
|
||||
Reference in new issue
Block a user