- Timestamp:
- Jul 23, 2005, 1:08:39 AM (19 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/fast_factory.cc
r4940 r4941 178 178 else 179 179 { 180 FastObjectMember* tmpC = deadList;180 FastObjectMember* tmpC = this->deadList; 181 181 this->deadList = this->deadList->next; 182 182 -
orxonox/trunk/src/util/fast_factory.h
r4940 r4941 23 23 #include "base_object.h" 24 24 25 26 // FORWARD DECLARATION //27 class GarbageCollector;28 template<class T>29 class tList;30 31 25 /** 32 * Creates a FastFactory to a Loadable FastFactory.26 * Creates a FastFactory to a Createable FastFactory. 33 27 */ 34 //#define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \35 //tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = new tFastFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)28 #define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \ 29 tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = tFastFactory<CLASS_NAME>::getFastFactory(CLASS_ID, #CLASS_NAME) 36 30 37 31 //! A struct, that holds Lists of Objects of a certain type. 38 struct FastObjectMember32 typedef struct FastObjectMember 39 33 { 40 34 BaseObject* objectPointer; //!< Pointer to the Object Stored in this Class (if it is the DeadList, else it is bork) … … 65 59 66 60 void prepare(unsigned int count); 67 // retrival functions for fast Ineraction68 //FastFactory* getFastFactory(ClassID classID);69 61 70 62 static void flushAll(bool hardFLUSH = false); … … 110 102 FastFactory* next; //!< pointer to the next FastFactory. 111 103 }; 104 105 112 106 113 107 /** … … 157 151 } 158 152 159 160 153 /** 161 154 * fabricates an Object of Class T, that corresponds to classID. -
orxonox/trunk/src/util/garbage_collector.cc
r4938 r4941 37 37 this->setClassID(CL_GARBAGE_COLLECTOR, "GarbageCollector"); 38 38 this->setName("GarbageCollector"); 39 40 this->collectedObjects = NULL; 41 this->unusedContainers = NULL; 39 42 40 43 this->time = 0; … … 81 84 82 85 /** 86 * collect an Object, that should be scheduled for clearing. 87 * @param object the Object to schedule. 88 */ 89 void GarbageCollector::collect(BaseObject* object) 90 { 91 printf("TEST\n"); 92 State::getWorldEntityList()->remove(dynamic_cast<WorldEntity*>(object)); 93 FastObjectMember* tmpC; 94 if (unlikely(this->unusedContainers == NULL)) 95 { 96 tmpC = new FastObjectMember; 97 } 98 else 99 { 100 tmpC = this->unusedContainers; 101 this->unusedContainers = this->unusedContainers->next; 102 } 103 104 tmpC->next = this->collectedObjects; 105 tmpC->objectPointer = object; 106 this->collectedObjects = tmpC; 107 } 108 109 /** 83 110 * this ticks the GarbageCollector to give it the time pulse 84 111 * @param time: the time passed since last tick … … 92 119 93 120 121 void GarbageCollector::update() 122 { 123 if (this->time < this->delay) 124 { 125 return; 126 } 127 if (this->collectedObjects == NULL) 128 return; 129 else 130 { 131 FastObjectMember* tmpC = this->collectedObjects; 132 FastObjectMember* moveC; 133 while (tmpC != NULL) 134 { 135 WorldEntity* entity = dynamic_cast<WorldEntity*>(tmpC->objectPointer); 136 //State::getWorldEntityList()->remove(entity); 137 entity->remove(); 138 FastFactory::kill(entity, true); 139 140 moveC = tmpC->next; 141 tmpC->next = this->unusedContainers; 142 this->unusedContainers = tmpC; 143 tmpC = moveC; 144 } 145 this->collectedObjects = NULL; 146 } 147 } 148 94 149 /** 95 150 * this updated the gargabe collection, if the time is ready 96 151 */ 97 void GarbageCollector::update()98 {99 if( this->time < this->delay)100 return;101 /* garbage collect */102 PRINTF(3)("=============================\n");103 PRINTF(3)("Processing Garbage Collection\n");104 PRINTF(3)("=============================\n");105 int counter = 0;106 107 tList<WorldEntity>* list = State::getWorldEntityList();108 109 tIterator<WorldEntity>* iterator = list->getIterator();110 WorldEntity* entity = iterator->nextElement();111 while( entity != NULL)112 {113 if( entity->isFinalized())114 {115 PRINTF(4)("= finalizing object\n");116 ++counter;117 118 /* first remove out of entity list */119 list->remove(entity);120 /* second remove out of pnode tree */121 entity->remove();122 /* then finaly delete reference */123 //delete entity;124 //FastFactory::kill();125 //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity);126 }127 entity = iterator->nextElement();128 }129 130 PRINTF(3)("= collected %i unused objects\n", counter);131 PRINTF(3)("=============================\n");132 133 //ObjectManager::getInstance()->debug();134 135 /* reset time to count again up to this->delay */136 this->time = 0;137 }152 // void GarbageCollector::update() 153 // { 154 // if( this->time < this->delay) 155 // return; 156 // /* garbage collect */ 157 // PRINTF(3)("=============================\n"); 158 // PRINTF(3)("Processing Garbage Collection\n"); 159 // PRINTF(3)("=============================\n"); 160 // int counter = 0; 161 // 162 // tList<WorldEntity>* list = State::getWorldEntityList(); 163 // 164 // tIterator<WorldEntity>* iterator = list->getIterator(); 165 // WorldEntity* entity = iterator->nextElement(); 166 // while( entity != NULL) 167 // { 168 // if( entity->isFinalized()) 169 // { 170 // PRINTF(4)("= finalizing object\n"); 171 // ++counter; 172 // 173 // /* first remove out of entity list */ 174 // list->remove(entity); 175 // /* second remove out of pnode tree */ 176 // entity->remove(); 177 // /* then finaly delete reference */ 178 // //delete entity; 179 // //FastFactory::kill(); 180 // //ObjectManager::getInstance()->addToDeadList(entity->getClassID() & CL_MASK_LOWLEVEL_CLASS, entity); 181 // } 182 // entity = iterator->nextElement(); 183 // } 184 // 185 // PRINTF(3)("= collected %i unused objects\n", counter); 186 // PRINTF(3)("=============================\n"); 187 // 188 // //ObjectManager::getInstance()->debug(); 189 // 190 // /* reset time to count again up to this->delay */ 191 // this->time = 0; 192 // } -
orxonox/trunk/src/util/garbage_collector.h
r4836 r4941 1 1 /*! 2 \file garbage_collector.h3 *Definition of the proto class template, used quickly start work4 5 6 7 8 */2 * @file garbage_collector.h 3 * Definition of the proto class template, used quickly start work 4 * @todo Example: this shows how to use simply add a Marker that here has to be done something. 5 * 6 * The Protoclass exists, to help you quikly getting the run for how to develop in orxonox. 7 * It is an example for the CODING-CONVENTION, and a starting-point for every class. 8 */ 9 9 10 10 #ifndef _GARBAGE_COLLECTOR_H … … 13 13 #include "base_object.h" 14 14 15 #include "fast_factory.h" 15 16 16 17 //! this class maintains the garbage collection. … … 30 31 void forceCollection(); 31 32 33 void collect(BaseObject* object); 34 32 35 void tick(float time); 33 36 void update(); … … 38 41 private: 39 42 static GarbageCollector* singletonRef; //!< The reference to this class (singleton) 40 float delay; //!< this is the delay to wait until collection 43 44 FastObjectMember* collectedObjects; //!< A list of recently collected Objects, that want to be deleted. 45 FastObjectMember* unusedContainers; //!< A list of unused containers. 46 float delay; //!< this is the delay to wait until collection. 41 47 float time; //!< the current time 42 48 -
orxonox/trunk/src/world_entities/weapons/projectile.cc
r4932 r4941 24 24 #include "model.h" 25 25 #include "vector.h" 26 27 #include "garbage_collector.h" 26 28 27 29 using namespace std; … … 93 95 PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); 94 96 PRINTF(5)("FINALIZE===========================\n"); 95 this->finalize(); 97 //this->finalize(); 98 GarbageCollector::getInstance()->collect(this); 96 99 } 97 100 } -
orxonox/trunk/src/world_entities/weapons/test_bullet.cc
r4933 r4941 21 21 #include "model.h" 22 22 #include "vector.h" 23 #include " object_manager.h"23 #include "garbage_collector.h" 24 24 25 25 using namespace std; … … 68 68 PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); 69 69 PRINTF(5)("FINALIZE===========================\n"); 70 this->finalize(); 70 // this->finalize(); 71 GarbageCollector::getInstance()->collect(this); 72 71 73 } 72 74 }
Note: See TracChangeset
for help on using the changeset viewer.