Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Niko committed Mar 25, 2023
1 parent f41b3bc commit 64288d5
Showing 1 changed file with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit 64288d5

Please sign in to comment.