ScummVM API documentation
Tetraedge::micropather::MicroPather Class Reference

#include <micropather.h>

Public Types

enum  { SOLVED, NO_SOLUTION, START_END_SAME, NOT_CACHED }
 

Public Member Functions

 MicroPather (Graph *graph, unsigned allocate=250, unsigned typicalAdjacent=6, bool cache=true)
 
int Solve (void *startState, void *endState, Common::Array< void * > *path, float *totalCost)
 
int SolveForNearStates (void *startState, Common::Array< StateCost > *near, float maxCost)
 
void Reset ()
 
void StatesInPool (Common::Array< void * > *stateVec)
 
void GetCacheData (CacheData *data)
 

Detailed Description

Create a MicroPather object to solve for a best path. Detailed usage notes are on the main page.

Constructor & Destructor Documentation

◆ MicroPather()

Tetraedge::micropather::MicroPather::MicroPather ( Graph graph,
unsigned  allocate = 250,
unsigned  typicalAdjacent = 6,
bool  cache = true 
)

Construct the pather, passing a pointer to the object that implements the Graph callbacks.

Parameters
graphThe "map" that implements the Graph callbacks.
allocateHow many states should be internally allocated at a time. This can be hard to get correct. The higher the value, the more memory MicroPather will use.
  • If you have a small map (a few thousand states?) it may make sense to pass in the maximum value. This will cache everything, and MicroPather will only need one main memory allocation. For a chess board, allocate would be set to 8x8 (64)
  • If your map is large, something like 1/4 the number of possible states is good.
  • If your state space is huge, use a multiple (5-10x) of the normal path. "Occasionally" call Reset() to free unused memory.
typicalAdjacentUsed to determine cache size. The typical number of adjacent states to a given state. (On a chessboard, 8.) Higher values use a little more memory.
cacheTurn on path caching. Uses more memory (yet again) but at a huge speed advantage if you may call the pather with the same path or sub-path, which is common for pathing over maps in games.

Member Function Documentation

◆ Solve()

int Tetraedge::micropather::MicroPather::Solve ( void *  startState,
void *  endState,
Common::Array< void * > *  path,
float *  totalCost 
)

Solve for the path from start to end.

Parameters
startStateInput, the starting state for the path.
endStateInput, the ending state for the path.
pathOutput, a vector of states that define the path. Empty if not found.
totalCostOutput, the cost of the path, if found.
Returns
Success or failure, expressed as SOLVED, NO_SOLUTION, or START_END_SAME.

◆ SolveForNearStates()

int Tetraedge::micropather::MicroPather::SolveForNearStates ( void *  startState,
Common::Array< StateCost > *  near,
float  maxCost 
)

Find all the states within a given cost from startState.

Parameters
startStateInput, the starting state for the path.
nearAll the states within 'maxCost' of 'startState', and cost to that state.
maxCostInput, the maximum cost that will be returned. (Higher values return larger 'near' sets and take more time to compute.)
Returns
Success or failure, expressed as SOLVED or NO_SOLUTION.

◆ Reset()

void Tetraedge::micropather::MicroPather::Reset ( )

Should be called whenever the cost between states or the connection between states changes. Also frees overhead memory used by MicroPather, and calling will free excess memory.


The documentation for this class was generated from the following file: