Skip to content

Duplicate normal requestPath() calls while already waiting for the same destination in AIUpdateInterface::requestPath #2430

@diqezit

Description

@diqezit

The same unit can repeatedly call requestPath() for the same regular point while already waiting for the same path. This causes unnecessary duplicate requests to be sent to the pathfinder and create churn. Avoid repeated queueForPath() calls if the request not actually changes

File GeneralsGameCode\GeneralsMD\Code\GameEngine\Source\GameLogic\Object\Update\AIUpdate.cpp

/* Requests a path to be found.  Note that if it is possible to do it without having to use the
pathfinder (air units just move point to point) it generates the path immediately.  Otherwise the path
will be processed when we get to the front of the pathfind queue. jba */
//-------------------------------------------------------------------------------------------------
void AIUpdateInterface::requestPath( Coord3D *destination, Bool isFinalGoal )
{

	if (m_locomotorSet.getValidSurfaces() == 0) {
		DEBUG_CRASH(("Attempting to path immobile unit."));
	}

	// we are already waiting for same normal path request
	// do not requeue pathfinding for identical destination
	if (m_waitingForPath &&
		m_requestedVictimID == INVALID_ID &&
		!m_isAttackPath &&
		!m_isApproachPath &&
		!m_isSafePath &&
		m_isFinalGoal == isFinalGoal)
	{
		Real dx = m_requestedDestination.x - destination->x;
		Real dy = m_requestedDestination.y - destination->y;
		Real dz = m_requestedDestination.z - destination->z;
		Real distSqr = sqr(dx) + sqr(dy) + sqr(dz);

		if (distSqr <= 1.0f) return;
	}


not changing the rest because it's the same

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions