Changeset 4930 in orxonox.OLD for orxonox/trunk/src/util
- Timestamp:
- Jul 22, 2005, 2:11:21 AM (19 years ago)
- Location:
- orxonox/trunk/src/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/object_manager.cc
r4836 r4930 19 19 #include "list.h" 20 20 21 #include "debug.h" 21 22 22 23 using namespace std; … … 106 107 PRINT(0)("=======================================================\n"); 107 108 } 109 110 /** 111 * constructor 112 113 set everything to zero and define factoryName 114 */ 115 FastObject::FastObject (const char* fastObjectName, ClassID classID) 116 { 117 this->setClassID(CL_FACTORY, "FastObject"); 118 this->setName(fastObjectName); 119 120 this->storedClassID = classID; 121 this->next = NULL; 122 123 FastObject::registerFastObject(this); 124 } 125 126 /** a reference to the First FastObject */ 127 FastObject* FastObject::first = NULL; 128 129 /** 130 * destructor 131 132 clear the Q 133 */ 134 FastObject::~FastObject () 135 { 136 // printf("%s\n", this->factoryName); 137 // FastObject* tmpDel = this->next; 138 // this->next = NULL; 139 if (this->next) 140 delete this->next; 141 } 142 143 /** 144 * add a FastObject to the FastObject Queue 145 * @param factory a FastObject to be registered 146 */ 147 void FastObject::registerFastObject( FastObject* factory) 148 { 149 PRINTF(4)("Registered FastObject for '%s'\n", factory->getName()); 150 151 if( FastObject::first == NULL) 152 FastObject::first = factory; 153 else 154 { 155 FastObject* tmpFac = FastObject::first; 156 while( tmpFac->next != NULL) 157 { 158 tmpFac = tmpFac->next; 159 } 160 tmpFac->setNext(factory); 161 } 162 } -
orxonox/trunk/src/util/object_manager.h
r4836 r4930 10 10 11 11 TO ADD SUPPORT FOR A CLASS do the following steps: 12 1. include the hader file : #include "class_ header.h"12 1. include the hader file : #include "class_id.h" 13 13 2. add the class to the type enum classID {}; in class_id.h 14 14 3. define a function void mCache( ClassName ) in class ObjectManager … … 21 21 22 22 #include "base_object.h" 23 #include "projectile.h"24 #include "list.h"25 23 24 template<class T> class tList; 26 25 class GarbageCollector; 27 28 29 //! This defines the "template" macro function for cache(...)30 #define mCache( Class ) \31 cache(ClassID index, int number, Class * copyObject) \32 { \33 this->managedObjectList[index] = new tList<BaseObject>(); \34 for(int i = 0; i < number; ++i)\35 {\36 this->managedObjectList[index]->add(new Class (*copyObject));\37 }\38 }39 40 41 26 42 27 //! the object manager itself … … 51 36 52 37 /** a class handled by the objectManage */ 53 void mCache(Projectile);54 38 void addToDeadList(int index, BaseObject* object); 55 39 BaseObject* getFromDeadList(int index, int number = 1); 40 41 BaseObject* resurect(); 42 void kill(BaseObject* object); 43 56 44 57 45 void debug() const; … … 68 56 69 57 58 /** 59 * Creates a factory to a Loadable Class. 60 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 61 */ 62 #define CREATE_FAST_FACTORY(CLASS_NAME, CLASS_ID) \ 63 tObject<CLASS_NAME>* global_##CLASS_NAME##_Object = new tObject<CLASS_NAME>(#CLASS_NAME, CLASS_ID) 64 65 //! The Factory is a loadable object handler 66 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 factory */ 78 static FastObject* getFirst() { return FastObject::first; }; 79 /** @returns the next factory */ 80 FastObject* getNext() const { return this->next; }; 81 82 private: 83 FastObject* next; //!< pointer to the next factory. 84 static FastObject* first; //!< A pointer to the first factory. 85 ClassID storedClassID; //!< The classID of the specified class. 86 }; 87 88 /** 89 * a factory that is able to load any kind of Object 90 (this is a Functor) 91 */ 92 template<class T> class tFastObject : public FastObject 93 { 94 public: 95 tFastObject(const char* fastObjectName, ClassID fastObject); 96 97 private: 98 virtual BaseObject* fabricate(ClassID fastObject); 99 }; 100 101 /** 102 * construnts a factory with 103 * @param factoryName the name of the factory 104 */ 105 template<class T> 106 tFastObject<T>::tFastObject(const char* fastObjectName, ClassID fastObject) : FastObject(fastObjectName, fastObject) 107 { 108 PRINTF(5)("Class: %s loadable as a FastObject\n", this->getName()); 109 } 110 111 template<class T> 112 BaseObject* tFastObject<T>::fabricate(ClassID fastObject) 113 { 114 if(this->classID == fastObject) 115 return new T ( root); 116 else if( getNext() != NULL) 117 return getNext()->fabricate( root); 118 else 119 return NULL; 120 } 121 70 122 #endif /* _OBJECT_MANAGER_H */
Note: See TracChangeset
for help on using the changeset viewer.