IdAASLocal::WalkPathToGoal

From modwiki

Jump to: navigation, search

idAASLocal::WalkPathToGoal

With WalkPathToGoal we start to get into some of the AAS details and it starts to get fun ;) As far as I can tell, WalkPathToGoal is only called from PathToGoal in the 1.3 sdk. WalkPathToGoal

 
/*
============
idAASLocal::WalkPathToGoal
 
  FIXME: don't stop optimizing on first failure ?
============
*/
bool idAASLocal::WalkPathToGoal( aasPath_t &path, int areaNum,const idVec3 &origin,
		int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const {
	int i, travelTime, curAreaNum, lastAreas[4], lastAreaIndex, endAreaNum;
	idReachability *reach;
	idVec3 endPos;

Quick description of each variable TODO:

Next the path is initialized.

 
 
	path.type = PATHTYPE_WALK;
	path.moveGoal = origin;
	path.moveAreaNum = areaNum;
	path.secondaryGoal = origin;
	path.reachability = NULL;

The path type is set to PATHTYPE_WALK. All available options are listed below for reference.

 
enum {
	PATHTYPE_WALK,
	PATHTYPE_WALKOFFLEDGE,
	PATHTYPE_BARRIERJUMP,
	PATHTYPE_JUMP
};

If we don’t have an aas file or we are already in the goalAreaNum set the moveGoal to the goal position vector passed in and return true, there is a WalkPathToGoal.

 
if ( file == NULL || areaNum == goalAreaNum ) {
	path.moveGoal = goalOrigin;
	return true;
}


 
lastAreas[0] = lastAreas[1] = lastAreas[2] = lastAreas[3] = areaNum;
lastAreaIndex = 0;
curAreaNum = areaNum;

These variables will be used while looping below, lets just take a look.

 
for ( i = 0; i < maxWalkPathIterations; i++ ) {

We are entering a pretty long for loop that is used to iteratively walk nodes in the path to perform path smoothing and optimization. maxWalkPathIterations is declared at the top of AAS_pathing, here is that declaration as well as some other ones that we will need soon.

 
#define SUBSAMPLE_WALK_PATH		1
 
const int		maxWalkPathIterations		= 10;
const float		maxWalkPathDistance		= 500.0f;
const float		walkPathSampleDistance		= 8.0f;

So loop 10 times to return the next ten reachabilities in the path and see if we can walk directly to them.

 
if ( !idAASLocal::RouteToGoalArea( curAreaNum, path.moveGoal, goalAreaNum,
		travelFlags, travelTime, &reach ) ) {
	break;
}

Each iteration through the loop we make a call to RouteToGoalArea. We pass in the curAreaNum which is(the area we are currently in or know we can get to) , path.moveGoal which is where we want to get to, goalAreaNum – the area that contains the moveGoal, travelFlags – flags that represent the type of travel allowed like TFL_WALK, travelTime, by reference, so that RouteToGoal can set it for us, and reach, well, its address, cause pointers to pointers to objects are fun (ok, RouteToGoal will set reach as well)

RouteToGoalArea will use the information passed to find the best route to the goal and set the reachability that gets you there as well as the travel time it should take. Because routes are cached in memory per goal area after being calculated each successive call to the routine is just a quick lookup to what was calculated on the first call to it. by calling it inside a loop we can walk up the path and smooth out movement.

 
if ( !reach ) {
	return false;
}

At any time in the loop if RouteToGoalArea can’t give us the next reachability to get to the goal we return false indicating failure to WalkPathToGoal. If we have a reachability to the next section of the path then we continue on processing.

 
// no need to check through the first area
if ( areaNum != curAreaNum ) {

TODO: Finish this routine up


 
 
#define SUBSAMPLE_WALK_PATH		1
 
const int		maxWalkPathIterations		= 10;
const float		maxWalkPathDistance		= 500.0f;
const float		walkPathSampleDistance		= 8.0f; 
 
Personal tools
Main
id Tech 5