Memory manager for the PathNodes. */
| 270 | |
| 271 | /* Memory manager for the PathNodes. */ |
| 272 | class PathNodePool |
| 273 | { |
| 274 | public: |
| 275 | PathNodePool( unsigned allocate, unsigned typicalAdjacent ); |
| 276 | ~PathNodePool(); |
| 277 | |
| 278 | // Free all the memory except the first block. Resets all memory. |
| 279 | void Clear(); |
| 280 | |
| 281 | // Essentially: |
| 282 | // pNode = Find(); |
| 283 | // if ( !pNode ) |
| 284 | // pNode = New(); |
| 285 | // |
| 286 | // Get the PathNode associated with this state. If the PathNode already |
| 287 | // exists (allocated and is on the current frame), it will be returned. |
| 288 | // Else a new PathNode is allocated and returned. The returned object |
| 289 | // is always fully initialized. |
| 290 | // |
| 291 | // NOTE: if the pathNode exists (and is current) all the initialization |
| 292 | // parameters are ignored. |
| 293 | PathNode* GetPathNode( unsigned frame, |
| 294 | cPosition _state, |
| 295 | float _costFromStart, |
| 296 | float _estToGoal, |
| 297 | PathNode* _parent ); |
| 298 | |
| 299 | // Get a pathnode that is already in the pool. |
| 300 | PathNode* FetchPathNode( cPosition state ); |
| 301 | |
| 302 | // Store stuff in cache |
| 303 | bool PushCache( const NodeCost* nodes, int nNodes, int* start ); |
| 304 | |
| 305 | // Get neighbors from the cache |
| 306 | // Note - always access this with an offset. Can get re-allocated. |
| 307 | void GetCache( int start, int nNodes, NodeCost* nodes ); |
| 308 | |
| 309 | // Return all the allocated states. Useful for visuallizing what |
| 310 | // the pather is doing. |
| 311 | void AllStates( unsigned frame, MP_VECTOR< cPosition >* stateVec ); |
| 312 | |
| 313 | private: |
| 314 | struct Block |
| 315 | { |
| 316 | Block* nextBlock; |
| 317 | PathNode pathNode[1]; |
| 318 | }; |
| 319 | |
| 320 | unsigned Hash( cPosition voidval ); |
| 321 | unsigned HashSize() const { return 1<<hashShift; } |
| 322 | unsigned HashMask() const { return ((1<<hashShift)-1); } |
| 323 | void AddPathNode( unsigned key, PathNode* p ); |
| 324 | Block* NewBlock(); |
| 325 | PathNode* Alloc(); |
| 326 | |
| 327 | PathNode** hashTable; |
| 328 | Block* firstBlock; |
| 329 | Block* blocks; |
nothing calls this directly
no outgoing calls
no test coverage detected