Changeset 4938 in orxonox.OLD for orxonox/trunk/src/util
- Timestamp:
- Jul 22, 2005, 11:57:38 PM (19 years ago)
- Location:
- orxonox/trunk/src/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/garbage_collector.cc
r4836 r4938 18 18 #include "garbage_collector.h" 19 19 20 #include " world.h"20 #include "state.h" 21 21 #include "world_entity.h" 22 22 #include "null_parent.h" … … 39 39 40 40 this->time = 0; 41 this->delay = 1.5f; /* clean up all 5.0 seconds */41 this->delay = 5.0f; /* clean up all 5.0 seconds */ 42 42 } 43 43 … … 104 104 PRINTF(3)("=============================\n"); 105 105 int counter = 0; 106 WorldInterface* wi = WorldInterface::getInstance(); 107 tList<WorldEntity>* list = wi->getEntityList();106 107 tList<WorldEntity>* list = State::getWorldEntityList(); 108 108 109 109 tIterator<WorldEntity>* iterator = list->getIterator(); … … 121 121 entity->remove(); 122 122 /* then finaly delete reference */ 123 delete entity; 123 //delete entity; 124 //FastFactory::kill(); 124 125 //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity); 125 126 } -
orxonox/trunk/src/util/object_manager.cc
r4937 r4938 23 23 using namespace std; 24 24 25 26 27 28 /** 29 * constructor, sets everything to zero and define factoryName25 /** 26 * Initializes a FastFactory 27 * @param classID the ClassID this Class belongs to (the top-most) 28 * @param fastFactoryName the Name of the ObjectClass-handled here 29 * @return a new FastFactory 30 30 */ 31 31 FastFactory::FastFactory (ClassID classID, const char* fastFactoryName) … … 50 50 /** 51 51 * destructor 52 * clear the Q52 * deletes all the Instances of the FastFactory. 53 53 */ 54 54 FastFactory::~FastFactory () … … 61 61 } 62 62 63 /** 64 * registers a Factory to the List of known factories. 65 * @param fastFactory The factory to add 66 * 67 * needed, to step through all the FastFactories. 68 */ 63 69 void FastFactory::registerFastFactory(FastFactory* fastFactory) 64 70 { … … 101 107 102 108 /** 103 * 109 * Removes all the stored Containers, and sets the Lists back to emptienes. 110 * @param hardFLUSH if true the containing Objects will also be deleted !! THIS IS DANGEROUS !! 104 111 */ 105 112 void FastFactory::flushAll(bool hardFLUSH) … … 116 123 /** 117 124 * ereases all the remaining containers, without deleting the stored Objects inside of them. 125 * @param hardFLUSH if the the containing Objects will also be deleted !! THIS IS DANGEROUS !! 118 126 */ 119 127 void FastFactory::flush(bool hardFLUSH) … … 140 148 } 141 149 142 143 150 /** 151 * generates count new Object of the Corresponding class. (precaching) 152 * @param count How many instances of the class should be generated. 153 */ 144 154 void FastFactory::prepare(unsigned int count) 145 155 { … … 154 164 } 155 165 156 157 BaseObject* FastFactory::resurect(ClassID classID) 166 /** 167 * gives back live to one Object. 168 * @return the Object to resurrect. 169 */ 170 BaseObject* FastFactory::resurrect() 158 171 { 159 172 PRINTF(4)("Resurecting Object of type %s\n", this->getName()); … … 163 176 "Fabricating a new %s", this->getName(), this->getName()); 164 177 this->fabricate(); 165 return this->resur ect(classID);178 return this->resurrect(); 166 179 } 167 180 else … … 177 190 } 178 191 179 180 181 void FastFactory::kill(ClassID classID, BaseObject* object) 192 /** 193 * gives back live to one Object. 194 * @param classID the class From which to resurrect an Object. 195 * @return the Object to resurrect, NULL if classID is not found. 196 */ 197 BaseObject* FastFactory::resurrect(ClassID classID) 198 { 199 FastFactory* tmpFac = FastFactory::getFirst(); 200 201 while (tmpFac != NULL) 202 { 203 if (classID == tmpFac->storedClassID) 204 return tmpFac->resurrect(); 205 tmpFac = tmpFac->next; 206 } 207 return NULL; 208 } 209 210 /** 211 * kills Object object, meaning, that it will be stored in the deadList of the FastFactory, and waiting for resurrection 212 * @param object the Object to kill. 213 */ 214 void FastFactory::kill(BaseObject* object) 182 215 { 183 216 FastObjectMember* tmpC; … … 194 227 tmpC->next = this->deadList; 195 228 tmpC->objectPointer = object; 196 } 197 198 199 229 this->deadList = tmpC; 230 } 231 232 233 void FastFactory::kill(BaseObject* object, ClassID classID) 234 { 235 236 237 } 200 238 201 239 -
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.