Advertisement
epitaque_

Untitled

Jul 8th, 2015
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. // Desired functionality: Loop through all elements in the std::unordered_set container (ObjectStack)
  2. // and run the PhysicsTick() function on each object
  3.  
  4. // I can't make a simple range-based for loop though because the PhysicsTick() function sometimes deletes objects
  5. // and then it throws errors.
  6.  
  7. // So my solution is to break after it deletes an object and then start a new loop at the next iterator
  8. // (I make it recursive to achieve this)
  9.  
  10. // This solution probably isn't optimal though
  11.  
  12. void QuadTree::RunPhysicsTick(unsigned int StartingPoint)
  13. {
  14.     int hacky_iterator = 0;
  15.     for (Object* it : ObjectStack)
  16.     {
  17.         if (hacky_iterator >= StartingPoint)
  18.         {
  19.             it->PhysicsTick();
  20.             if (!IsExisting(it))
  21.             {
  22.                 cout << "Breaking because !IsExisting(it) = " << !IsExisting(it) << endl;
  23.                 break;
  24.                 RunPhysicsTick(hacky_iterator);
  25.                 return;
  26.             }
  27.         }
  28.         hacky_iterator++;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement