Fixed P_LookForPlayers scanning redundancies

- Players could be scanned multiple times, repeating expensive tests
- Players could be skipped completely and become invisible as a result
This commit is contained in:
Edward Richardson 2014-04-17 00:46:33 +12:00
parent 4270838613
commit d855bd66b3

View file

@ -1542,7 +1542,6 @@ bool P_LookForEnemies (AActor *actor, INTBOOL allaround, FLookExParams *params)
bool P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params)
{
int c;
int stop;
int pnum;
player_t* player;
bool chasegoal = params? (!(params->flags & LOF_DONTCHASEGOAL)) : true;
@ -1615,11 +1614,13 @@ bool P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params)
{
pnum = actor->LastLookPlayerNumber;
}
stop = (pnum - 1) & (MAXPLAYERS-1);
for (;;)
{
pnum = (pnum + 1) & (MAXPLAYERS-1);
// [ED850] Each and every player should only ever be checked once.
if (c++ < MAXPLAYERS)
{
pnum = (pnum + 1) & (MAXPLAYERS - 1);
if (!playeringame[pnum])
continue;
@ -1627,8 +1628,8 @@ bool P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params)
{
actor->LastLookPlayerNumber = pnum;
}
if (++c == MAXPLAYERS-1 || pnum == stop)
}
else
{
// done looking
if (actor->target == NULL)