SDL - Game slow downs

Hi at all! I'm making a game using the SDL 2.0 library. I store all the pointers of game instances inside a std::vector. So, before rendering the scene, I call the update function for all the instances, then delete all the instances that have been pushed to queue, then set their pointers to nullptr... later, I sort the vector by the drawing depth of instances and finally render the scene by calling the draw function. So, there are 4 for loops inside the main loop. Everything works, but when the games goes on, that vector becomes large and slow to process. Then, the game slows down! So, this is the question:
- There is any method or technique to rearrange a std::vector without taking too much time?
Thanks in advance!
Last edited on
It's all that sorting. You've got yourself an exponentially complex algorithm there.

Perhaps if you held those things in a sorted container, you wouldn't need to keep resorting them. There are a few around (like map and so on), you just need to define what what your sort order is and let the container sort itself.
Topic archived. No new replies allowed.