Skip to content

Commit

Permalink
SV_PushMove(): Really take into account a variable num_pushable_ent_c…
Browse files Browse the repository at this point in the history
…ache in SV_Pushmove() (if possible), simplify edicts iteration
  • Loading branch information
vsonnier committed Sep 9, 2024
1 parent ff970d1 commit d8d896e
Showing 1 changed file with 18 additions and 47 deletions.
65 changes: 18 additions & 47 deletions Quake/sv_phys.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ cvar_t sv_gameplayfix_elevators = {"sv_gameplayfix_elevators", "2", CVAR_ARCHIVE

static void SV_PushMove (edict_t *pusher, float movetime)
{
int i, e;
int i;
edict_t *check, *block;
vec3_t mins, maxs, move;
vec3_t entorig, pushorig;
Expand Down Expand Up @@ -490,31 +490,24 @@ static void SV_PushMove (edict_t *pusher, float movetime)
const bool fast_pushers = (sv_fastpushmove.value > 0.f);

// beware, we skip entity 0:
const int effective_num_edicts = (fast_pushers ? num_pushable_ent_cache : qcvm->num_edicts - 1);
check = NEXT_EDICT (qcvm->edicts);

for (e = 0; e < effective_num_edicts; e++)
int e = -1;

while (true)
{
if (fast_pushers)
{
check = pushable_ent_cache[e];
}
// TBC :does qcvm->num_edicts always constant here, i.e is there edicts allocs possible in this loop ?
if (e >= (fast_pushers ? num_pushable_ent_cache - 1 : qcvm->num_edicts - 1 - 1))
break;

e++;
check = (fast_pushers ? pushable_ent_cache[e] : NEXT_EDICT (check));

if (check->free)
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}

if (!fast_pushers)
{
if (check->v.movetype == MOVETYPE_PUSH || check->v.movetype == MOVETYPE_NONE || check->v.movetype == MOVETYPE_NOCLIP)
{
check = NEXT_EDICT (check);
continue;
}
}
if (check->v.movetype == MOVETYPE_PUSH || check->v.movetype == MOVETYPE_NONE || check->v.movetype == MOVETYPE_NOCLIP)
continue;

qboolean riding = false;

Expand All @@ -523,30 +516,18 @@ static void SV_PushMove (edict_t *pusher, float movetime)
{
if (check->v.absmin[0] >= maxs[0] || check->v.absmin[1] >= maxs[1] || check->v.absmin[2] >= maxs[2] || check->v.absmax[0] <= mins[0] ||
check->v.absmax[1] <= mins[1] || check->v.absmax[2] <= mins[2])
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}

// see if the ent's bbox is inside the pusher's final position
if (pusher->v.skin < 0)
{ // a more precise check...
if (!SV_ClipMoveToEntity (pusher, check->v.origin, check->v.mins, check->v.maxs, check->v.origin, CONTENTMASK_ANYSOLID).startsolid)
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}
}
else
{
if (!SV_TestEntityPosition (check))
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}

riding = false;
}
Expand Down Expand Up @@ -590,32 +571,21 @@ static void SV_PushMove (edict_t *pusher, float movetime)
if (block)
{ // fail the move
if (check->v.mins[0] == check->v.maxs[0])
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}

if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
{ // corpse
check->v.mins[0] = check->v.mins[1] = 0;
VectorCopy (check->v.mins, check->v.maxs);
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}
continue;
}

// try moving the entity up a bit if it's blocked by the pusher while also standing on it
if (riding && block == pusher && (sv_gameplayfix_elevators.value >= 2.f || (sv_gameplayfix_elevators.value && e <= svs.maxclients)))
{
check->v.origin[2] += DIST_EPSILON;
if (!SV_TestEntityPosition (check))
{
if (!fast_pushers)
check = NEXT_EDICT (check);
continue;
}
}

VectorCopy (entorig, check->v.origin);
Expand All @@ -642,9 +612,7 @@ static void SV_PushMove (edict_t *pusher, float movetime)
}
break;
} // end if block
if (!fast_pushers)
check = NEXT_EDICT (check);
} // foreach pushable entities
} // foreach pushable entities
}

/*
Expand Down Expand Up @@ -1270,6 +1238,9 @@ static void intercept_allocs_in_pr_execute_program (edict_t *e)
assert (!e->free);

pushable_ent_cache[num_pushable_ent_cache++] = e;

if (developer.value)
Con_DPrintf ("SV_PushMove(): allocated EDICT %d\n", NUM_FOR_EDICT (e));
}

/*
Expand Down

0 comments on commit d8d896e

Please sign in to comment.