Merge branch 'NewChaseDir-opt' of https://github.com/Edward850/zdoom

This commit is contained in:
Christoph Oelckers 2015-02-08 09:06:53 +01:00
commit 0688247ee1

View file

@ -670,33 +670,39 @@ bool P_TryWalk (AActor *actor)
void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay) void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
{ {
dirtype_t d[3]; dirtype_t d[2];
int tdir; int tdir;
dirtype_t olddir, turnaround; dirtype_t olddir, turnaround;
bool attempts[NUMDIRS-1]; // We don't need to attempt DI_NODIR.
memset(&attempts, false, sizeof(attempts));
olddir = (dirtype_t)actor->movedir; olddir = (dirtype_t)actor->movedir;
turnaround = opposite[olddir]; turnaround = opposite[olddir];
if (deltax>10*FRACUNIT) if (deltax>10*FRACUNIT)
d[1]= DI_EAST; d[0]= DI_EAST;
else if (deltax<-10*FRACUNIT) else if (deltax<-10*FRACUNIT)
d[1]= DI_WEST; d[0]= DI_WEST;
else
d[0]=DI_NODIR;
if (deltay<-10*FRACUNIT)
d[1]= DI_SOUTH;
else if (deltay>10*FRACUNIT)
d[1]= DI_NORTH;
else else
d[1]=DI_NODIR; d[1]=DI_NODIR;
if (deltay<-10*FRACUNIT)
d[2]= DI_SOUTH;
else if (deltay>10*FRACUNIT)
d[2]= DI_NORTH;
else
d[2]=DI_NODIR;
// try direct route // try direct route
if (d[1] != DI_NODIR && d[2] != DI_NODIR) if (d[0] != DI_NODIR && d[1] != DI_NODIR)
{ {
actor->movedir = diags[((deltay<0)<<1) + (deltax>0)]; actor->movedir = diags[((deltay<0)<<1) + (deltax>0)];
if (actor->movedir != turnaround && P_TryWalk(actor)) if (actor->movedir != turnaround)
return; {
attempts[actor->movedir] = true;
if (P_TryWalk(actor))
return;
}
} }
// try other directions // try other directions
@ -704,18 +710,19 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
{ {
if ((pr_newchasedir() > 200 || abs(deltay) > abs(deltax))) if ((pr_newchasedir() > 200 || abs(deltay) > abs(deltax)))
{ {
swapvalues (d[1], d[2]); swapvalues (d[0], d[1]);
} }
if (d[0] == turnaround)
d[0] = DI_NODIR;
if (d[1] == turnaround) if (d[1] == turnaround)
d[1] = DI_NODIR; d[1] = DI_NODIR;
if (d[2] == turnaround)
d[2] = DI_NODIR;
} }
if (d[1] != DI_NODIR) if (d[0] != DI_NODIR && attempts[d[0]] == false)
{ {
actor->movedir = d[1]; actor->movedir = d[0];
attempts[d[0]] = true;
if (P_TryWalk (actor)) if (P_TryWalk (actor))
{ {
// either moved forward or attacked // either moved forward or attacked
@ -723,9 +730,10 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
} }
} }
if (d[2] != DI_NODIR) if (d[1] != DI_NODIR && attempts[d[1]] == false)
{ {
actor->movedir = d[2]; actor->movedir = d[1];
attempts[d[1]] = true;
if (P_TryWalk (actor)) if (P_TryWalk (actor))
return; return;
} }
@ -733,9 +741,10 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
if (!(actor->flags5 & MF5_AVOIDINGDROPOFF)) if (!(actor->flags5 & MF5_AVOIDINGDROPOFF))
{ {
// there is no direct path to the player, so pick another direction. // there is no direct path to the player, so pick another direction.
if (olddir != DI_NODIR) if (olddir != DI_NODIR && attempts[olddir] == false)
{ {
actor->movedir = olddir; actor->movedir = olddir;
attempts[olddir] = true;
if (P_TryWalk (actor)) if (P_TryWalk (actor))
return; return;
} }
@ -746,9 +755,10 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
{ {
for (tdir = DI_EAST; tdir <= DI_SOUTHEAST; tdir++) for (tdir = DI_EAST; tdir <= DI_SOUTHEAST; tdir++)
{ {
if (tdir != turnaround) if (tdir != turnaround && attempts[tdir] == false)
{ {
actor->movedir = tdir; actor->movedir = tdir;
attempts[tdir] = true;
if ( P_TryWalk(actor) ) if ( P_TryWalk(actor) )
return; return;
} }
@ -758,16 +768,17 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
{ {
for (tdir = DI_SOUTHEAST; tdir != (DI_EAST-1); tdir--) for (tdir = DI_SOUTHEAST; tdir != (DI_EAST-1); tdir--)
{ {
if (tdir != turnaround) if (tdir != turnaround && attempts[tdir] == false)
{ {
actor->movedir = tdir; actor->movedir = tdir;
attempts[tdir] = true;
if ( P_TryWalk(actor) ) if ( P_TryWalk(actor) )
return; return;
} }
} }
} }
if (turnaround != DI_NODIR) if (turnaround != DI_NODIR && attempts[turnaround] == false)
{ {
actor->movedir =turnaround; actor->movedir =turnaround;
if ( P_TryWalk(actor) ) if ( P_TryWalk(actor) )