mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
Merge branch 'NewChaseDir-opt' of https://github.com/Edward850/zdoom
This commit is contained in:
commit
0688247ee1
1 changed files with 35 additions and 24 deletions
|
@ -670,33 +670,39 @@ bool P_TryWalk (AActor *actor)
|
|||
|
||||
void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
|
||||
{
|
||||
dirtype_t d[3];
|
||||
dirtype_t d[2];
|
||||
int tdir;
|
||||
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;
|
||||
turnaround = opposite[olddir];
|
||||
|
||||
if (deltax>10*FRACUNIT)
|
||||
d[1]= DI_EAST;
|
||||
d[0]= DI_EAST;
|
||||
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
|
||||
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
|
||||
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)];
|
||||
if (actor->movedir != turnaround && P_TryWalk(actor))
|
||||
return;
|
||||
if (actor->movedir != turnaround)
|
||||
{
|
||||
attempts[actor->movedir] = true;
|
||||
if (P_TryWalk(actor))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 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)))
|
||||
{
|
||||
swapvalues (d[1], d[2]);
|
||||
swapvalues (d[0], d[1]);
|
||||
}
|
||||
|
||||
if (d[0] == turnaround)
|
||||
d[0] = DI_NODIR;
|
||||
if (d[1] == turnaround)
|
||||
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))
|
||||
{
|
||||
// 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))
|
||||
return;
|
||||
}
|
||||
|
@ -733,9 +741,10 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
|
|||
if (!(actor->flags5 & MF5_AVOIDINGDROPOFF))
|
||||
{
|
||||
// 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;
|
||||
attempts[olddir] = true;
|
||||
if (P_TryWalk (actor))
|
||||
return;
|
||||
}
|
||||
|
@ -746,9 +755,10 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
|
|||
{
|
||||
for (tdir = DI_EAST; tdir <= DI_SOUTHEAST; tdir++)
|
||||
{
|
||||
if (tdir != turnaround)
|
||||
if (tdir != turnaround && attempts[tdir] == false)
|
||||
{
|
||||
actor->movedir = tdir;
|
||||
attempts[tdir] = true;
|
||||
if ( P_TryWalk(actor) )
|
||||
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--)
|
||||
{
|
||||
if (tdir != turnaround)
|
||||
if (tdir != turnaround && attempts[tdir] == false)
|
||||
{
|
||||
actor->movedir = tdir;
|
||||
attempts[tdir] = true;
|
||||
if ( P_TryWalk(actor) )
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (turnaround != DI_NODIR)
|
||||
if (turnaround != DI_NODIR && attempts[turnaround] == false)
|
||||
{
|
||||
actor->movedir =turnaround;
|
||||
if ( P_TryWalk(actor) )
|
||||
|
|
Loading…
Reference in a new issue