MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / removeItem

Method removeItem

Engine/source/forest/forestCell.cpp:350–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350bool ForestCell::removeItem( ForestItemKey key, const Point3F &keyPos, bool deleteIfEmpty )
351{
352 PROFILE_SCOPE( ForestCell_removeItem );
353
354 AssertFatal( key != 0, "ForestCell::removeItem() - Got null key!" );
355
356 // If this cell has no items then check the children.
357 if ( mItems.empty() )
358 {
359 // Let the child deal with it.
360 U32 index = _getSubCell( keyPos.x, keyPos.y );
361 if ( !mSubCells[index]->removeItem( key, keyPos, deleteIfEmpty ) )
362 {
363 // For debugging lets make sure we didn't pick the wrong subCell...
364
365 return false;
366 }
367
368 // If requested by the caller delete our empty subcells.
369 // Note that by deleting SubCell[0] we have become a leaf with no items
370 // and will return true to our parent's isEmpty test.
371 if ( deleteIfEmpty &&
372 mSubCells[0]->isEmpty() &&
373 mSubCells[1]->isEmpty() &&
374 mSubCells[2]->isEmpty() &&
375 mSubCells[3]->isEmpty() )
376 {
377 SAFE_DELETE( mSubCells[0] );
378 SAFE_DELETE( mSubCells[1] );
379 SAFE_DELETE( mSubCells[2] );
380 SAFE_DELETE( mSubCells[3] );
381 }
382 }
383 else
384 {
385 // First see if we can find it.
386 U32 index;
387 if ( !findIndexByKey( key, &index ) )
388 return false;
389
390 // Erase it.
391 mItems.erase( index );
392 }
393
394 // Do a full bounds update on the next request.
395 mIsDirty = true;
396
397 // PhysicsBody is now invalid and must be rebuilt later.
398 SAFE_DELETE( mPhysicsRep[0] );
399 SAFE_DELETE( mPhysicsRep[1] );
400
401 // Destroy batches so we recreate it on
402 // the next next render.
403 freeBatches();
404
405 return true;
406}
407

Callers 4

colladaImport.cppFile · 0.45
fillGuiTreeViewMethod · 0.45
enumColladaForImportFunction · 0.45
enumDTSForImportFunction · 0.45

Calls 3

emptyMethod · 0.45
isEmptyMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected