/*! \file object_manager.h * this manager will ceep track of the objects in the world This is specially designed to: - Give an interface to the world data - separate the world data from the world build,update,draw process - recycle deleted objects: specific for Projectils since there is a lot of world entity creation/deletion (and this needs a lot of time) - control the garbage collector TO ADD SUPPORT FOR A CLASS do the following steps: 1. include the hader file : #include "class_header.h" 2. add the class to the type enum classID {}; in class_id.h 3. define a function void mCache( ClassName ) in class ObjectManager */ #ifndef _OBJECT_MANAGER_H #define _OBJECT_MANAGER_H #include "base_object.h" #include "projectile.h" #include "list.h" class GarbageCollector; //! This defines the "template" macro function for cache(...) #define mCache( Class ) \ cache(ClassID index, int number, Class * copyObject) \ { \ this->managedObjectList[index] = new tList(); \ for(int i = 0; i < number; ++i)\ {\ this->managedObjectList[index]->add(new Class (*copyObject));\ }\ } //! the object manager itself class ObjectManager : public BaseObject { public: virtual ~ObjectManager(); /** @returns a Pointer to the only object of this Class */ inline static ObjectManager* getInstance() { if (!singletonRef) singletonRef = new ObjectManager(); return singletonRef; }; void registerClass(ClassID classID); /** a class handled by the objectManage */ void mCache(Projectile); void addToDeadList(int index, BaseObject* object); BaseObject* getFromDeadList(int index, int number = 1); void debug() const; private: ObjectManager(); private: static ObjectManager* singletonRef; //!< The singleton reference to the only reference of this class tList** managedObjectList; //!< A list of managed objects (handles different types and lists of them) }; #endif /* _OBJECT_MANAGER_H */