Last active
December 15, 2015 12:09
-
-
Save Shaptic/5258087 to your computer and use it in GitHub Desktop.
CQuadTree::RRemove()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CQuadTree::RRemove(CEntity* pEnt, QTNode* pStart) | |
{ | |
// Leaf node? | |
if(pStart->pChildren == nullptr) | |
{ | |
// Iterate over the entities and remove a match (if any). | |
for(auto i : pStart->nodeObjects) | |
{ | |
// Is this the object we are looking for? | |
if(*i == pEnt) | |
{ | |
// Erase and break out. | |
nodeObjects.erase(i); | |
return true; | |
} | |
} | |
// No match :( | |
return false; | |
} | |
// Branch with children. | |
else | |
{ | |
// Recurse on all children. | |
for(size_t i = 0; i < 4; ++i) | |
{ | |
// Only break out if there was a match found, because if | |
// we broke out regardless we wouldn't get to all the kids! | |
if(this->RRemove(pBody, pStart->pChildren[i])) return true; | |
} | |
} | |
// No match found ever. | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment