From d855bd66b301ebd8ad969e6816a4c190d9e3ec8f Mon Sep 17 00:00:00 2001 From: Edward Richardson Date: Thu, 17 Apr 2014 00:46:33 +1200 Subject: [PATCH 1/2] 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 --- src/p_enemy.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 8b1dd951b..3be53cd64 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -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,20 +1614,22 @@ bool P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params) { pnum = actor->LastLookPlayerNumber; } - stop = (pnum - 1) & (MAXPLAYERS-1); for (;;) { - pnum = (pnum + 1) & (MAXPLAYERS-1); - if (!playeringame[pnum]) - continue; - - if (actor->TIDtoHate == 0) + // [ED850] Each and every player should only ever be checked once. + if (c++ < MAXPLAYERS) { - actor->LastLookPlayerNumber = pnum; - } + pnum = (pnum + 1) & (MAXPLAYERS - 1); + if (!playeringame[pnum]) + continue; - if (++c == MAXPLAYERS-1 || pnum == stop) + if (actor->TIDtoHate == 0) + { + actor->LastLookPlayerNumber = pnum; + } + } + else { // done looking if (actor->target == NULL) From 897d87a6a3841a0e484cc5de1e1b411848a3c6a8 Mon Sep 17 00:00:00 2001 From: Edward Richardson Date: Thu, 17 Apr 2014 01:13:18 +1200 Subject: [PATCH 2/2] Invisibility would could P_LookForPlayers early --- src/p_enemy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 3be53cd64..e187dfb7c 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -1693,11 +1693,11 @@ bool P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params) && P_AproxDistance (player->mo->velx, player->mo->vely) < 5*FRACUNIT) { // Player is sneaking - can't detect - return false; + continue; } if (pr_lookforplayers() < 225) { // Player isn't sneaking, but still didn't detect - return false; + continue; } } }