Changeset 4932 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Jul 22, 2005, 12:08:51 PM (19 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/defs/class_id.h
r4839 r4932 188 188 CL_TRACK_ELEMENT = 0x00000b0b, 189 189 CL_NUMBER = 0x00000b0c, 190 CL_FAST_FACTORY = 0x00000c01, 190 191 191 192 -
orxonox/trunk/src/defs/debug.h
r4885 r4932 66 66 #define DEBUG_MODULE_TRACK_MANAGER 2 67 67 #define DEBUG_MODULE_GARBAGE_COLLECTOR 0 68 #define DEBUG_MODULE_OBJECT_MANAGER 068 #define DEBUG_MODULE_OBJECT_MANAGER 2 69 69 #define DEBUG_MODULE_LIGHT 0 70 70 #define DEBUG_MODULE_PLAYER 1 -
orxonox/trunk/src/util/loading/factory.h
r4885 r4932 48 48 49 49 static void registerFactory( Factory* factory); 50 /** sets the Next factory in the list @param nextFactory the next factory */51 inline void setNext( Factory* nextFactory) { this->next = nextFactory; };52 50 /** @returns the first factory */ 53 51 static Factory* getFirst() { return Factory::first; }; 54 /** @returns the next factory */ 55 Factory* getNext() const { return this->next; }; 52 53 protected: 54 /** sets the Next factory in the list @param nextFactory the next factory */ 55 inline void setNext( Factory* nextFactory) { this->next = nextFactory; }; 56 /** @returns the next factory */ 57 Factory* getNext() const { return this->next; }; 56 58 57 59 private: -
orxonox/trunk/src/util/object_manager.cc
r4931 r4932 24 24 25 25 26 27 28 /** 29 * constructor, sets everything to zero and define factoryName 30 */ 31 FastFactory::FastFactory (const char* fastFactoryName, ClassID classID) 32 { 33 this->setClassID(CL_FAST_FACTORY, "FastFactory"); 34 this->setName(fastFactoryName); 35 36 this->storedClassID = classID; 37 this->next = NULL; 38 39 FastFactory::registerFastFactory(this); 40 } 41 42 /** a reference to the First FastFactory */ 43 FastFactory* FastFactory::first = NULL; 44 45 /** 46 * destructor 47 * clear the Q 48 */ 49 FastFactory::~FastFactory () 50 { 51 if (this == first) 52 this->first = NULL; 53 54 if (this->next) 55 delete this->next; 56 } 57 58 /** 59 * add a FastFactory to the FastFactory Queue 60 * @param factory a FastFactory to be registered 61 */ 62 void FastFactory::registerFastFactory( FastFactory* factory) 63 { 64 PRINTF(3)("Registered FastFactory for '%s'\n", factory->getName()); 65 66 if( FastFactory::first == NULL) 67 FastFactory::first = factory; 68 else 69 { 70 FastFactory* tmpFac = FastFactory::first; 71 while( tmpFac->next != NULL) 72 { 73 tmpFac = tmpFac->next; 74 } 75 tmpFac->setNext(factory); 76 } 77 } 78 79 80 81 82 83 84 85 86 87 88 89 90 26 91 /** 27 92 * standard constructor … … 32 97 this->setName("ObjectManager"); 33 98 34 this->managedObjectList = new tList<BaseObject>*[CL_NUMBER];35 for(int i = 0; i < CL_NUMBER; ++i)36 {37 this->managedObjectList[i] = NULL;38 }39 99 } 40 100 … … 54 114 55 115 /** 56 * adds an element to the list of dead objects57 * @param index: The type of object to add58 * @param object: pointer to the object at hand59 */60 void ObjectManager::addToDeadList(int index, BaseObject* object)61 {62 if( likely(this->managedObjectList[index] != NULL))63 this->managedObjectList[index]->add(object);64 else65 PRINTF(0)(" Critical: unable to add object to the list nr. %i: no list initialized - ignoring\n", index);66 }67 68 /**69 * resurects an object70 * @param index: the type of resource to load71 * @param number: how many of them72 73 @todo if it is unable to get an object from the deadList, it should create it74 */75 BaseObject* ObjectManager::getFromDeadList(int index, int number)76 {77 if( likely(this->managedObjectList[index] != NULL))78 {79 BaseObject* obj = this->managedObjectList[index]->firstElement();80 this->managedObjectList[index]->remove(obj);81 if( unlikely(obj == NULL))82 {83 PRINTF(0)("Critical: there was no object anymore in the dead list! This could result in Segfaults\n");84 }85 return obj;86 }87 else88 PRINTF(0)(" Critical: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index);89 return NULL;90 }91 92 /**93 116 * outputs some simple debug information about the ObjectManage 94 117 */ … … 96 119 { 97 120 PRINT(0)("\n==========================| ObjectManager::debug() |===\n"); 98 99 100 101 121 /* PRINT(0)("= Number of registerable classes: %i\n", CL_NUMBER ); 122 PRINT(0)("= Currently cached objects: \n"); 123 for(int i = 0; i < CL_NUMBER; ++i) 124 { 102 125 if( this->managedObjectList[i] != NULL) 103 126 PRINT(0)("= o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize()); 104 127 else 105 128 PRINT(0)("= o Class Nr. %i has cached 0 object(s)\n", i); 106 } 129 }*/ 107 130 PRINT(0)("=======================================================\n"); 108 131 } 109 132 110 133 111 112 /**113 * constructor114 115 set everything to zero and define factoryName116 */117 FastObject::FastObject (const char* fastObjectName, ClassID classID)118 {119 this->setClassID(CL_FACTORY, "FastObject");120 this->setName(fastObjectName);121 122 this->storedClassID = classID;123 this->next = NULL;124 125 FastObject::registerFastObject(this);126 }127 128 /** a reference to the First FastObject */129 FastObject* FastObject::first = NULL;130 131 /**132 * destructor133 134 clear the Q135 */136 FastObject::~FastObject ()137 {138 // printf("%s\n", this->factoryName);139 // FastObject* tmpDel = this->next;140 // this->next = NULL;141 if (this->next)142 delete this->next;143 }144 145 /**146 * add a FastObject to the FastObject Queue147 * @param factory a FastObject to be registered148 */149 void FastObject::registerFastObject( FastObject* factory)150 {151 PRINTF(4)("Registered FastObject for '%s'\n", factory->getName());152 153 if( FastObject::first == NULL)154 FastObject::first = factory;155 else156 {157 FastObject* tmpFac = FastObject::first;158 while( tmpFac->next != NULL)159 {160 tmpFac = tmpFac->next;161 }162 tmpFac->setNext(factory);163 }164 } -
orxonox/trunk/src/util/object_manager.h
r4931 r4932 26 26 class GarbageCollector; 27 27 28 29 /** 30 * Creates a FastFactory to a Loadable FastFactory. 31 */ 32 #define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \ 33 tFastFactory<CLASS_NAME>* global_##CLASS_NAME##_FastFactory = new tFastFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID) 34 35 //! A struct, that holds Lists of Objects of a certain type. 36 typedef struct FastObjectMember 37 { 38 BaseObject* objectPointer; 39 40 FastObjectMember* next; 41 }; 42 43 //! The FastFactory is a fast loadable object creator, and Dynamic List of dead object handler. 44 class FastFactory : public BaseObject { 45 46 public: 47 FastFactory (const char* fastFactoryName, ClassID classID); 48 virtual ~FastFactory (); 49 50 51 BaseObject* resurect(ClassID classID); 52 void kill(ClassID classID, BaseObject* object); 53 54 virtual BaseObject* fabricate(ClassID classID) = NULL; 55 56 static void registerFastFactory(FastFactory* fastFactory); 57 static void registerFastFactory(const char* fastFactoryName, ClassID classID); 58 59 /** @returns the first FastFactory */ 60 static FastFactory* getFirst() { return FastFactory::first; }; 61 62 protected: 63 /** sets the Next factory in the list @param nextFactory the next factory */ 64 inline void setNext( FastFactory* nextFastFactory) { this->next = nextFastFactory; }; 65 /** @returns the next FastFactory */ 66 FastFactory* getNext() const { return this->next; }; 67 68 protected: 69 ClassID storedClassID; //!< The classID of the specified class. 70 71 private: 72 static FastFactory* first; //!< A pointer to the first FastFactory. 73 74 FastFactory* next; //!< pointer to the next FastFactory. 75 }; 76 77 /** 78 * a FastFactory that is able to load any kind of Object from a ClassID 79 * (this is a Functor) 80 */ 81 template<class T> class tFastFactory : public FastFactory 82 { 83 public: 84 tFastFactory(const char* fastFactoryName, ClassID fastFactory); 85 86 private: 87 virtual BaseObject* fabricate(ClassID classID); 88 }; 89 90 /** 91 * construnts a FastFactory with 92 * @param fastFactoryName the name of the FastFactory 93 * @param fastFactory the ID of the class 94 */ 95 template<class T> 96 tFastFactory<T>::tFastFactory(const char* fastFactoryName, ClassID fastFactory) : FastFactory(fastFactoryName, fastFactory) 97 { 98 PRINTF(5)("Class: %s loadable as a FastFactory\n", this->getName()); 99 } 100 101 template<class T> 102 BaseObject* tFastFactory<T>::fabricate(ClassID classID) 103 { 104 if (this->storedClassID == classID) 105 return new T (); 106 else if( getNext() != NULL) 107 return getNext()->fabricate(classID); 108 else 109 return NULL; 110 } 111 112 113 114 115 //////////////////// 116 // OBJECT MANAGER // 117 //////////////////// 118 28 119 //! the object manager itself 29 120 class ObjectManager : public BaseObject { … … 35 126 36 127 void registerClass(ClassID classID); 37 38 /** a class handled by the objectManage */39 void addToDeadList(int index, BaseObject* object);40 BaseObject* getFromDeadList(int index, int number = 1);41 128 42 129 BaseObject* resurect(); … … 52 139 static ObjectManager* singletonRef; //!< The singleton reference to the only reference of this class 53 140 54 tList<BaseObject>** managedObjectList; //!< A list of managed objects (handles different types and lists of them)55 141 }; 56 142 57 143 58 144 59 /**60 * Creates a factory to a Loadable FastObject.61 */62 #define CREATE_FAST_OBJECT(CLASS_NAME, CLASS_ID) \63 tFastObject<CLASS_NAME>* global_##CLASS_NAME##_FastObject = new tFastObject<CLASS_NAME>(#CLASS_NAME, CLASS_ID)64 65 //! The FastObject is a loadable object handler66 class FastObject : public BaseObject {67 68 public:69 FastObject (const char* fastObjectName = NULL, ClassID classID = CL_NULL);70 virtual ~FastObject ();71 72 virtual BaseObject* fabricate(ClassID classID) = NULL;73 74 static void registerFastObject(FastObject* fastObject);75 /** sets the Next factory in the list @param nextFactory the next factory */76 inline void setNext( FastObject* nextFastObject) { this->next = nextFastObject; };77 /** @returns the first FastObject */78 static FastObject* getFirst() { return FastObject::first; };79 /** @returns the next FastObject */80 FastObject* getNext() const { return this->next; };81 82 protected:83 ClassID storedClassID; //!< The classID of the specified class.84 85 private:86 FastObject* next; //!< pointer to the next FastObject.87 static FastObject* first; //!< A pointer to the first FastObject.88 };89 90 /**91 * a FastObject that is able to load any kind of Object92 * (this is a Functor)93 */94 template<class T> class tFastObject : public FastObject95 {96 public:97 tFastObject(const char* fastObjectName, ClassID fastObject);98 99 private:100 virtual BaseObject* fabricate(ClassID fastObject);101 };102 103 /**104 * construnts a FastObject with105 * @param fastObjectName the name of the FastObject106 * @param fastObject the ID of the class107 */108 template<class T>109 tFastObject<T>::tFastObject(const char* fastObjectName, ClassID fastObject) : FastObject(fastObjectName, fastObject)110 {111 PRINTF(5)("Class: %s loadable as a FastObject\n", this->getName());112 }113 114 template<class T>115 BaseObject* tFastObject<T>::fabricate(ClassID fastObject)116 {117 // if(this->classID == fastObject)118 //return new T ();119 //else if( getNext() != NULL)120 // return getNext()->fabricate();121 // else122 return NULL;123 }124 125 145 #endif /* _OBJECT_MANAGER_H */ -
orxonox/trunk/src/world_entities/weapons/projectile.cc
r4927 r4932 31 31 * standard constructor 32 32 */ 33 Projectile::Projectile ( Weapon* weapon) : WorldEntity()33 Projectile::Projectile () : WorldEntity() 34 34 { 35 35 this->setClassID(CL_PROJECTILE, "Projectile"); 36 36 37 this->weapon = weapon;38 37 this->lifeCycle = 0.0; 39 38 this->lifeSpan = 0.75f; /* sec */ -
orxonox/trunk/src/world_entities/weapons/projectile.h
r4927 r4932 25 25 26 26 class Vector; 27 class Weapon;28 27 class ParticleEmitter; 29 28 … … 31 30 { 32 31 public: 33 Projectile ( Weapon* weapon);32 Projectile (); 34 33 virtual ~Projectile (); 35 34 … … 57 56 58 57 Vector flightDirection; //!< direction in which the shoot flighs 59 Weapon* weapon; //!< weapon the shoot belongs to.60 58 61 59 Vector velocity; //!< velocity of the projectile. -
orxonox/trunk/src/world_entities/weapons/test_bullet.cc
r4892 r4932 21 21 #include "model.h" 22 22 #include "vector.h" 23 #include "object_manager.h" 23 24 24 25 using namespace std; 25 26 27 CREATE_FAST_FACTORY(TestBullet, CL_TEST_BULLET); 26 28 27 29 /** 28 30 * standard constructor 29 31 */ 30 TestBullet::TestBullet ( Weapon* weapon) : Projectile(weapon)32 TestBullet::TestBullet () : Projectile() 31 33 { 32 34 this->setClassID(CL_TEST_BULLET, "TestBullet"); -
orxonox/trunk/src/world_entities/weapons/test_bullet.h
r4892 r4932 15 15 { 16 16 public: 17 TestBullet ( Weapon* weapon);17 TestBullet (); 18 18 virtual ~TestBullet (); 19 19 -
orxonox/trunk/src/world_entities/weapons/test_gun.cc
r4931 r4932 35 35 #include "object_manager.h" 36 36 37 CREATE_FAST_OBJECT(TestGun, CL_TEST_GUN);38 37 39 38 using namespace std; … … 97 96 this->weaponSource = new SoundSource(this->fireSound, this); 98 97 this->weaponSource->setRolloffFactor(.1);*/ 99 Projectile* p = new TestBullet( this);98 Projectile* p = new TestBullet(); 100 99 101 100 // ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); … … 156 155 void TestGun::fire() 157 156 { 158 Projectile* pj = new TestBullet( this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));157 Projectile* pj = new TestBullet();//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS)); 159 158 // weaponSource->play(); 160 159
Note: See TracChangeset
for help on using the changeset viewer.