diff --git a/psx-modding-toolchain/games/CrashTeamRacing/decompile/General/THREAD/THREAD_CollidePointWithSelf.c b/psx-modding-toolchain/games/CrashTeamRacing/decompile/General/THREAD/THREAD_CollidePointWithSelf.c index c55a9fbff..45893b1f0 100644 --- a/psx-modding-toolchain/games/CrashTeamRacing/decompile/General/THREAD/THREAD_CollidePointWithSelf.c +++ b/psx-modding-toolchain/games/CrashTeamRacing/decompile/General/THREAD/THREAD_CollidePointWithSelf.c @@ -12,27 +12,38 @@ struct Need_New_Name int radius; // 0x10 - short distComp[4]; + short distX; + short distY; + short distZ; + short padding; }; void THREAD_CollidePointWithSelf(struct Thread* th, struct Need_New_Name* buf) { struct Instance* inst; - int distComp[3], dist; - int i; + int distX; + int distY; + int distZ; + int dist; // if collision disabled, or thread is dead, quit if((th->flags & 0x1800) != 0) return; inst = th->inst; - dist = 0; - for(i = 0; i < 3; i++) - { - distComp[i] = (int)buf->pos[i]-(int)inst->matrix.t[i]; - if((distComp[i]*distComp[i]) > 0x10000000) return; - dist += distComp[i]*distComp[i]; - } + // Do not try to optimize this with loops, + // it will not compile to less assembly, + // 180 bytes is as low as this will go + + distX = (int)buf->pos[0]-(int)inst->matrix.t[0]; + distY = (int)buf->pos[1]-(int)inst->matrix.t[1]; + distZ = (int)buf->pos[2]-(int)inst->matrix.t[2]; + + if(distX*distX >= 0x10000000) return; + if(distY*distY >= 0x10000000) return; + if(distZ*distZ >= 0x10000000) return; + + dist = distX*distX + distY*distY + distZ*distZ; // if outside hit radius if(dist >= buf->radius) return; @@ -43,8 +54,7 @@ void THREAD_CollidePointWithSelf(struct Thread* th, struct Need_New_Name* buf) // save the thread collided with buf->th = th; - for(i = 0; i < 3; i++) - { - buf->distComp[i] = (short)distComp[i]; - } + buf->distX = (short)distX; + buf->distY = (short)distY; + buf->distZ = (short)distZ; } \ No newline at end of file