Changeset 4930 in orxonox.OLD for orxonox/trunk/src/util/object_manager.h
- Timestamp:
- Jul 22, 2005, 2:11:21 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.