I also have an EntityManager class that keeps a list of pointers to all the game objects created. The idea being that this list will be used for updating and drawing all game objects to the screen.
I find myself struggling to find the best way to design all of this.
How do I make sure all game objects are added to the EntityManager list?
How do I make sure that when an object is deleted, all other game objects that might have a pointer to said object are not now referencing deallocated memory?
During cleanup I delete all the Entity objects in EntityManager, and therefore they all need to be heap objects created with the new keyword. How do I make sure none of the pointers point to a stack object?
Right now I am doing this project alone, and ultimately the easy way out to most of these questions is for me to just remember things and don't make mistakes.
"Just dont forget that all entity objects need to be made using new."
"Just dont forget to add all Entities you make to the EntityManager list."
But that is bad programming right? What if I was on a development team...that wouldnt fly! The other devs would not know all the catch clauses of what not to do and what may cause a bug with my code. Thats the whole point of classes and privacy and encapsulation ect...to make code that is hard to break and easy to organize.
I'm trying to improve my skill as a designer and programmer...am I overcomplicating this? Somebody help me.
Edited by Kaanin25, 14 June 2012 - 04:42 PM.