Skip to content

Commit

Permalink
Minor refactor ( add BoundsIntersect function ) (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamdi authored Sep 27, 2023
1 parent 5ec8c29 commit b7f6eb8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
9 changes: 9 additions & 0 deletions rehlds/engine/mathlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,12 @@ qboolean VectorCompare(const vec_t *v1, const vec_t *v2)
}

#endif // #if !defined(REHLDS_SSE)

qboolean BoundsIntersect(const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2)
{
if (mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2])
return FALSE;
if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
return FALSE;
return TRUE;
}
1 change: 1 addition & 0 deletions rehlds/engine/mathlib_e.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,4 @@ void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);
NOBODY void FloorDivMod(double numer, double denom, int *quotient, int *rem);
NOBODY int GreatestCommonDivisor(int i1, int i2);
NOBODY fixed16_t Invert24To16(fixed16_t val);
qboolean BoundsIntersect(const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2);
9 changes: 1 addition & 8 deletions rehlds/engine/sv_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ void SV_AddLinksToPM_(areanode_t *node, float *pmove_mins, float *pmove_maxs)
edict_t *check;
int e;
physent_t *ve;
int i;
link_t *next;
float *fmax;
float *fmin;
Expand Down Expand Up @@ -588,13 +587,7 @@ void SV_AddLinksToPM_(areanode_t *node, float *pmove_mins, float *pmove_maxs)
if (check->v.flags & FL_CLIENT)
SV_GetTrueMinMax(e - 1, &fmin, &fmax);

for (i = 0; i < 3; i++)
{
if (fmin[i] > pmove_maxs[i] || fmax[i] < pmove_mins[i])
break;
}

if (i != 3)
if (!BoundsIntersect(pmove_mins, pmove_maxs, fmin, fmax))
continue;

if (check->v.solid || check->v.skin != -16)
Expand Down
28 changes: 4 additions & 24 deletions rehlds/engine/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,7 @@ void SV_TouchLinks(edict_t *ent, areanode_t *node)
if (touch->v.solid != SOLID_TRIGGER)
continue;

if (ent->v.absmin[0] > touch->v.absmax[0]
|| ent->v.absmin[1] > touch->v.absmax[1]
|| ent->v.absmin[2] > touch->v.absmax[2]
|| ent->v.absmax[0] < touch->v.absmin[0]
|| ent->v.absmax[1] < touch->v.absmin[1]
|| ent->v.absmax[2] < touch->v.absmin[2])
if (!BoundsIntersect(ent->v.absmin, ent->v.absmax, touch->v.absmin, touch->v.absmax))
continue;

// check brush triggers accuracy
Expand Down Expand Up @@ -647,12 +642,7 @@ int SV_LinkContents(areanode_t *node, const vec_t *pos)
if (Mod_GetType(touch->v.modelindex) != mod_brush)
continue;

if (pos[0] > touch->v.absmax[0]
|| pos[1] > touch->v.absmax[1]
|| pos[2] > touch->v.absmax[2]
|| pos[0] < touch->v.absmin[0]
|| pos[1] < touch->v.absmin[1]
|| pos[2] < touch->v.absmin[2])
if (!BoundsIntersect(pos, pos, touch->v.absmin, touch->v.absmax))
continue;

int contents = touch->v.skin;
Expand Down Expand Up @@ -1216,12 +1206,7 @@ void SV_ClipToLinks(areanode_t *node, moveclip_t *clip)
if (clip->ignoretrans && touch->v.rendermode != kRenderNormal && !(touch->v.flags & FL_WORLDBRUSH))
continue;

if (clip->boxmins[0] > touch->v.absmax[0]
|| clip->boxmins[1] > touch->v.absmax[1]
|| clip->boxmins[2] > touch->v.absmax[2]
|| clip->boxmaxs[0] < touch->v.absmin[0]
|| clip->boxmaxs[1] < touch->v.absmin[1]
|| clip->boxmaxs[2] < touch->v.absmin[2])
if (!BoundsIntersect(clip->boxmins, clip->boxmaxs, touch->v.absmin, touch->v.absmax))
continue;

if (touch->v.solid != SOLID_SLIDEBOX
Expand Down Expand Up @@ -1310,12 +1295,7 @@ void SV_ClipToWorldbrush(areanode_t *node, moveclip_t *clip)
if (!(touch->v.flags & FL_WORLDBRUSH))
continue;

if (clip->boxmins[0] > touch->v.absmax[0]
|| clip->boxmins[1] > touch->v.absmax[1]
|| clip->boxmins[2] > touch->v.absmax[2]
|| clip->boxmaxs[0] < touch->v.absmin[0]
|| clip->boxmaxs[1] < touch->v.absmin[1]
|| clip->boxmaxs[2] < touch->v.absmin[2])
if (!BoundsIntersect(clip->boxmins, clip->boxmaxs, touch->v.absmin, touch->v.absmax))
continue;

if (clip->trace.allsolid)
Expand Down

0 comments on commit b7f6eb8

Please sign in to comment.