Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Last active December 15, 2015 12:09
Show Gist options
  • Save Shaptic/5258087 to your computer and use it in GitHub Desktop.
Save Shaptic/5258087 to your computer and use it in GitHub Desktop.
CQuadTree::RRemove()
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