Create a MicroPather object to solve for a best path. Detailed usage notes are on the main page. */
| 357 | on the main page. |
| 358 | */ |
| 359 | class MicroPather |
| 360 | { |
| 361 | friend class micropather::PathNode; |
| 362 | |
| 363 | public: |
| 364 | enum |
| 365 | { |
| 366 | SOLVED, |
| 367 | NO_SOLUTION, |
| 368 | START_END_SAME, |
| 369 | |
| 370 | // internal |
| 371 | NOT_CACHED |
| 372 | }; |
| 373 | |
| 374 | /** |
| 375 | Construct the pather, passing a pointer to the object that implements |
| 376 | the Graph callbacks. |
| 377 | |
| 378 | @param graph The "map" that implements the Graph callbacks. |
| 379 | @param allocate How many states should be internally allocated at a time. This |
| 380 | can be hard to get correct. The higher the value, the more memory |
| 381 | MicroPather will use. |
| 382 | - If you have a small map (a few thousand states?) it may make sense |
| 383 | to pass in the maximum value. This will cache everything, and MicroPather |
| 384 | will only need one main memory allocation. For a chess board, allocate |
| 385 | would be set to 8x8 (64) |
| 386 | - If your map is large, something like 1/4 the number of possible |
| 387 | states is good. |
| 388 | - If your state space is huge, use a multiple (5-10x) of the normal |
| 389 | path. "Occasionally" call Reset() to free unused memory. |
| 390 | @param typicalAdjacent Used to determine cache size. The typical number of adjacent states |
| 391 | to a given state. (On a chessboard, 8.) Higher values use a little |
| 392 | more memory. |
| 393 | @param cache Turn on path caching. Uses more memory (yet again) but at a huge speed |
| 394 | advantage if you may call the pather with the same path or sub-path, which |
| 395 | is common for pathing over maps in games. |
| 396 | */ |
| 397 | MicroPather( Graph* graph, unsigned allocate = 250, unsigned typicalAdjacent=6, bool cache=true ); |
| 398 | ~MicroPather(); |
| 399 | |
| 400 | /** |
| 401 | Solve for the path from start to end. |
| 402 | |
| 403 | @param startState Input, the starting state for the path. |
| 404 | @param endState Input, the ending state for the path. |
| 405 | @param path Output, a vector of states that define the path. Empty if not found. |
| 406 | @param totalCost Output, the cost of the path, if found. |
| 407 | @return Success or failure, expressed as SOLVED, NO_SOLUTION, or START_END_SAME. |
| 408 | */ |
| 409 | int Solve( cPosition* startState, cPosition* endState, MP_VECTOR< cPosition >* path, float* totalCost ); |
| 410 | |
| 411 | /** |
| 412 | Find all the states within a given cost from startState. |
| 413 | |
| 414 | @param startState Input, the starting state for the path. |
| 415 | @param near All the states within 'maxCost' of 'startState', and cost to that state. |
| 416 | @param maxCost Input, the maximum cost that will be returned. (Higher values return |
nothing calls this directly
no outgoing calls
no test coverage detected