Changeset 4938 in orxonox.OLD for orxonox/trunk/src/util/object_manager.h
- Timestamp:
- Jul 22, 2005, 11:57:38 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/object_manager.h
r4937 r4938 1 1 /*! 2 \file object_manager.h 3 * this manager will ceep track of the objects in the world 4 5 This is specially designed to: 6 - Give an interface to the world data 7 - separate the world data from the world build,update,draw process 8 - recycle deleted objects: specific for Projectils since there is a lot of world entity creation/deletion (and this needs a lot of time) 9 - control the garbage collector 10 11 TO ADD SUPPORT FOR A CLASS do the following steps: 12 1. include the hader file : #include "class_id.h" 13 2. add the class to the type enum classID {}; in class_id.h 14 3. define a function void mCache( ClassName ) in class ObjectManager 15 2 * @file object_manager.h 3 * The ObjectManager (FastFactory) is designed, to automatically generate and remove 4 * (without to much overhead) many instances of different classes. 5 * 6 * It is especially usefull for objects, that come only for a short time into existence, 7 * and get killed after a small amount of time (like shots). 8 * 9 * The Creation of an Object is usually done in the Weapon Class, where one subscribes 10 * a Projectile with: 11 * this->bulletFactory = tFastFactory<TestBullet>::getFastFactory(CL_TEST_BULLET, "TestBullet"); 12 * (this might change over time). 13 * Then you can at loading time initialize an amount of the class with something like: 14 * this->bulletFactory->prepare(100); // creates 100 entities of TestBullet (dead ones) 15 * afterwards one can just retrieve an Object form the Class with 16 * this->bulletFactory->resurrect(); // this returns a BaseObject an Object of the class. 16 17 */ 17 18 … … 21 22 22 23 #include "base_object.h" 23 #include "class_id.h"24 24 25 26 // FORWARD DECLARATION // 27 class GarbageCollector; 25 28 template<class T> class tList; 26 class GarbageCollector;27 28 29 29 30 /** … … 36 37 struct FastObjectMember 37 38 { 38 BaseObject* objectPointer;39 BaseObject* objectPointer; //!< Pointer to the Object Stored in this Class (if it is the DeadList, else it is bork) 39 40 40 FastObjectMember* next;41 FastObjectMember* next; //!< the next stored FastObjectMember. (or NULL if this is the last one stored in either the deadList or the unusedContainers) 41 42 }; 42 43 43 44 //! The FastFactory is a fast loadable object creator, and Dynamic List of dead object handler. 44 45 /** 46 * The ObjectManager (FastFactory) is designed, to automatically generate and remove 47 * (without to much overhead) many instances of different classes. 48 * 45 49 * FastFactory is needed to glue all the tFastFactory<T>'s together. 46 * Furthermore one can retrieve the corresponding tFastFactory over47 * t FastFactory<T>* = FastFacroty::getFastFactory(ID);50 * It is also the general class that implements the necessary functions 51 * to generate, resurrect kill and stuff... 48 52 */ 49 53 class FastFactory : public BaseObject { … … 53 57 54 58 // functions to push and pop elements of this class 55 BaseObject* resurect(ClassID classID); 56 void kill(ClassID classID, BaseObject* object); 59 BaseObject* resurrect(); 60 static BaseObject* resurrect(ClassID classID); 61 void kill(BaseObject* object); 62 static void kill(BaseObject* object, ClassID classID); 57 63 58 virtual void fabricate() = NULL;59 64 void prepare(unsigned int count); 60 65 // retrival functions for fast Ineraction … … 76 81 77 82 // virtual BaseObject* fabricate(ClassID classID) = NULL; 78 83 virtual void fabricate() = NULL; 79 84 static FastFactory* searchFastFactory(ClassID classID, const char* fastFactoryName = NULL); 80 85 … … 104 109 static tFastFactory<T>* getFastFactory(ClassID classID, const char* fastFactoryName = NULL); 105 110 106 T* resurect();107 111 private: 108 112 tFastFactory(ClassID classID, const char* fastFactoryName); 109 113 110 114 virtual void fabricate(); 111 112 private:113 115 }; 114 116 … … 149 151 } 150 152 151 template<class T>152 T* tFastFactory<T>::resurect()153 {154 PRINTF(4)("Resurecting Object of type %s\n", this->getName());155 if (unlikely(this->deadList == NULL))156 {157 PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \158 "Fabricating a new %s", this->getName(), this->getName());159 this->fabricate();160 return resurect();161 }162 else163 {164 FastObjectMember* tmpC = deadList;165 this->deadList = this->deadList->next;166 153 167 tmpC->next = this->unusedContainers;168 this->unusedContainers = tmpC;169 154 170 return dynamic_cast<T*>(tmpC->objectPointer); 171 } 172 } 155 156 157 158 159 173 160 174 161 //////////////////// … … 186 173 void registerClass(ClassID classID); 187 174 188 BaseObject* resur ect();175 BaseObject* resurrect(); 189 176 void kill(BaseObject* object); 190 177
Note: See TracChangeset
for help on using the changeset viewer.