MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / Clear

Method Clear

Source/Utils/micropather.cpp:274–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272
273
274void PathNodePool::Clear()
275{
276#ifdef TRACK_COLLISION
277 // Collision tracking code.
278 int collide=0;
279 for( unsigned i=0; i<HashSize(); ++i ) {
280 if ( hashTable[i] && (hashTable[i]->child[0] || hashTable[i]->child[1]) )
281 ++collide;
282 }
283 //printf( "PathNodePool %d/%d collision=%d %.1f%%\n", nAllocated, HashSize(), collide, 100.0f*(float)collide/(float)HashSize() );
284 totalCollide += collide;
285#endif
286
287 Block* b = blocks;
288 while( b ) {
289 Block* temp = b->nextBlock;
290 if ( b != firstBlock ) {
291 free( b );
292 }
293 b = temp;
294 }
295 blocks = firstBlock; // Don't delete the first block (we always need at least that much memory.)
296
297 // Set up for new allocations (but don't do work we don't need to. Reset/Clear can be called frequently.)
298 if ( nAllocated > 0 ) {
299 freeMemSentinel.next = &freeMemSentinel;
300 freeMemSentinel.prev = &freeMemSentinel;
301
302 memset( hashTable, 0, sizeof(PathNode*)*HashSize() );
303 for( unsigned i=0; i<allocate; ++i ) {
304 freeMemSentinel.AddBefore( &firstBlock->pathNode[i] );
305 }
306 }
307 nAvailable = allocate;
308 nAllocated = 0;
309 cacheSize = 0;
310}
311
312
313PathNodePool::Block* PathNodePool::NewBlock()

Callers 3

GetPathNodeMethod · 0.45
ResetMethod · 0.45
SolveForNearStatesMethod · 0.45

Calls 1

AddBeforeMethod · 0.80

Tested by

no test coverage detected