Files
Neutron/tools/binary/collision_dispatch_probe.c
T

73 lines
3.9 KiB
C

/* Executes copied original dispatcher/kernel only, with synthetic grid/actor
* fixtures. Reuses the guarded in-memory mapper; no game entry point is run. */
#define main isolated_kernel_main
#include "collision_response_probe.c"
#undef main
#define TC __attribute__((thiscall))
typedef struct Node {struct Node *next,*previous;void *value;} Node;
typedef void (__cdecl *Dispatch)(void*,Vec*,Vec,int);
static unsigned callbacks;
static Vec callback_normal;
static void *callback_polygon;
static float TC radius(void *actor) { (void)actor;return 10; }
static void TC normal(void *actor,Vec value,void *polygon) {
(void)actor;callbacks++;callback_normal=value;callback_polygon=polygon;
}
static Node sentinels[260*260];
static unsigned char actor[0x500],polygon[2][0x30],shape[2][0x90],corners[2][60];
static Vec points[2][3];
static void empty_grid(void) {
for(unsigned i=0;i<260*260;i++) {
sentinels[i].next=sentinels[i].previous=&sentinels[i];
*(Node**)AT(0x509b24+i*12)=&sentinels[i];
}
}
static int cell(float value) {return (short)(int)(value*.0020000000949949026+130);}
static void add_triangle(unsigned id,Vec a,Vec b,Vec c,Vec n) {
points[id][0]=a;points[id][1]=b;points[id][2]=c;
*(Vec*)(polygon[id]+8)=n;*(void**)(polygon[id]+0x24)=corners[id];
*(void**)(shape[id]+0x68)=points[id];
for(unsigned j=0;j<3;j++)*(unsigned*)(corners[id]+20*j)=j;
float minx=fminf(a.x,fminf(b.x,c.x)),maxx=fmaxf(a.x,fmaxf(b.x,c.x));
float minz=fminf(a.z,fminf(b.z,c.z)),maxz=fmaxf(a.z,fmaxf(b.z,c.z));
for(int x=cell(minx);x<=cell(maxx);x++)for(int z=cell(minz);z<=cell(maxz);z++) {
require(x>=0&&x<260&&z>=0&&z<260,"fixture grid bounds");
Node *s=&sentinels[260*x+z],*node=calloc(1,sizeof(Node));
void **registration=calloc(1,0x1c);require(node&&registration,"fixture nodes");
registration[0]=polygon[id];registration[1]=shape[id];node->value=registration;
node->next=s;node->previous=s->previous;s->previous->next=node;s->previous=node;
}
}
static void wall(void) {
add_triangle(0,(Vec){-100,-100,0,1},(Vec){-100,100,0,1},(Vec){100,100,0,1},(Vec){0,0,1,0});
}
static void run(const char *name,Vec p,Vec delta,int edges,int lower) {
*(float*)AT(0x695d5c)=130000;*(float*)AT(0x5cfbe0)=10;
*(void**)AT(0x695d4c)=NULL;*(unsigned*)AT(0x695d70)=0;*(unsigned*)AT(0x695d78)=0;
callbacks=0;callback_polygon=NULL;memset(&callback_normal,0,sizeof(Vec));actor[0x42c]=lower;
((Dispatch)AT(0x47b4b0))(actor,&p,delta,edges);
int last=callback_polygon==polygon[0]?0:callback_polygon==polygon[1]?1:-1;
printf("CASE %s root=%.9g,%.9g,%.9g passes=%u visits=%u callbacks=%u last=%d normal=%.9g,%.9g,%.9g\n",
name,p.x,p.y,p.z,*(unsigned*)AT(0x695d78),*(unsigned*)AT(0x695d70),callbacks,last,
callback_normal.x,callback_normal.y,callback_normal.z);
require(isfinite(p.x)&&isfinite(p.y)&&isfinite(p.z)&&callbacks<=1,"finite terminal publication");
}
int main(void) {
setbuf(stdout,NULL);map_copy();
uintptr_t table[0x400/4]={0};table[0x260/4]=(uintptr_t)radius;
table[0x370/4]=table[0x374/4]=(uintptr_t)normal;*(uintptr_t*)actor=(uintptr_t)table;
*(unsigned char*)AT(0x4f69e5)=1;*(unsigned char*)AT(0x695d46)=0;
empty_grid();wall();
run("face_retry",(Vec){0,20,20,1},(Vec){0,0,-15,0},1,0);
run("edge_retry",(Vec){105,100,20,1},(Vec){0,0,-15,0},1,0);
run("edge_disabled",(Vec){105,100,20,1},(Vec){0,0,-15,0},0,0);
run("zero_delta",(Vec){0,20,20,1},(Vec){0,0,0,0},1,0);
run("forced_zero",(Vec){0,20,20,1},(Vec){0,0,0,0},1,1);
add_triangle(1,(Vec){0,-100,-100,1},(Vec){0,-100,100,1},(Vec){0,100,100,1},(Vec){1,0,0,0});
run("corner_retry",(Vec){20,20,20,1},(Vec){-30,0,-30,0},1,0);
empty_grid();add_triangle(0,(Vec){-100,100,-100,1},(Vec){100,100,100,1},(Vec){100,100,-100,1},(Vec){0,-1,0,0});
run("ceiling_retry",(Vec){0,80,0,1},(Vec){0,15,0,0},1,0);
puts("DISPATCH_COMPONENT_COMPLETE: copied source with synthetic grid/callback fixtures");
return 0;
}