[365] | 1 | /** |
---|
[443] | 2 | @file CoreIncludes.h |
---|
[447] | 3 | @brief Definition of macros and typedefs. |
---|
[365] | 4 | |
---|
| 5 | Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface |
---|
| 6 | or the BaseObject itself, it needs the macro RegisterRootObject(class) instead. |
---|
| 7 | |
---|
| 8 | To allow the object being created through the factory, use the CreateFactory(class) macro outside |
---|
| 9 | the of the class implementation, so it gets executed before main(). |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | // All needed header-files |
---|
[197] | 13 | #include "Identifier.h" |
---|
[218] | 14 | #include "Factory.h" |
---|
[244] | 15 | #include "ClassFactory.h" |
---|
[221] | 16 | #include "Iterator.h" |
---|
[197] | 17 | #include "OrxonoxClass.h" |
---|
[434] | 18 | #include "ConfigValueContainer.h" |
---|
[453] | 19 | #include "Debug.h" |
---|
[219] | 20 | |
---|
[450] | 21 | #include "OgreVector2.h" |
---|
[434] | 22 | #include "OgreVector3.h" |
---|
| 23 | #include "OgreColourValue.h" |
---|
[460] | 24 | #include "OgreQuaternion.h" |
---|
| 25 | #include "OgreMatrix3.h" |
---|
[219] | 26 | |
---|
[447] | 27 | |
---|
| 28 | // Some typedefs |
---|
[434] | 29 | namespace orxonox |
---|
| 30 | { |
---|
[450] | 31 | typedef Ogre::Vector2 Vector2; |
---|
[434] | 32 | typedef Ogre::Vector3 Vector3; |
---|
| 33 | typedef Ogre::ColourValue ColourValue; |
---|
[460] | 34 | typedef Ogre::Radian Radian; |
---|
| 35 | typedef Ogre::Real Real; |
---|
| 36 | typedef Ogre::Quaternion Quaternion; |
---|
| 37 | typedef Ogre::Matrix3 Matrix3; |
---|
[434] | 38 | } |
---|
| 39 | |
---|
[447] | 40 | |
---|
| 41 | /** |
---|
| 42 | @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. |
---|
| 43 | @param ClassName The name of the class |
---|
| 44 | @param bRootClass True if the class is directly derived from OrxonoxClass |
---|
| 45 | */ |
---|
[244] | 46 | #define InternRegisterObject(ClassName, bRootClass) \ |
---|
| 47 | this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \ |
---|
[219] | 48 | if (Identifier::isCreatingHierarchy() && this->getParents()) \ |
---|
| 49 | this->getParents()->add(this->getIdentifier()); \ |
---|
[224] | 50 | ClassIdentifier<ClassName>::addObject(this) |
---|
[219] | 51 | |
---|
[447] | 52 | /** |
---|
| 53 | @brief Intern macro, containing the specific part of RegisterRootObject. |
---|
| 54 | @param ClassName The name of the class |
---|
| 55 | */ |
---|
[244] | 56 | #define InternRegisterRootObject(ClassName) \ |
---|
| 57 | if (Identifier::isCreatingHierarchy() && !this->getParents()) \ |
---|
| 58 | this->setParents(new IdentifierList()); \ |
---|
| 59 | InternRegisterObject(ClassName, true) |
---|
[220] | 60 | |
---|
[447] | 61 | /** |
---|
| 62 | @brief RegisterObject - with and without debug output. |
---|
| 63 | @param ClassName The name of the class |
---|
| 64 | */ |
---|
[244] | 65 | #define RegisterObject(ClassName) \ |
---|
[453] | 66 | COUT(4) << "*** Register Object: " << #ClassName << "\n"; \ |
---|
[244] | 67 | InternRegisterObject(ClassName, false) |
---|
[219] | 68 | |
---|
[447] | 69 | /** |
---|
| 70 | @brief RegisterRootObject - with and without debug output. |
---|
| 71 | @param ClassName The name of the class |
---|
| 72 | */ |
---|
[244] | 73 | #define RegisterRootObject(ClassName) \ |
---|
[453] | 74 | COUT(4) << "*** Register Root-Object: " << #ClassName << "\n"; \ |
---|
[244] | 75 | InternRegisterRootObject(ClassName) |
---|
[219] | 76 | |
---|
[447] | 77 | /** |
---|
| 78 | @brief Returns the Identifier of the given class. |
---|
| 79 | @param ClassName The name of the class |
---|
| 80 | */ |
---|
[219] | 81 | #define Class(ClassName) \ |
---|
| 82 | ClassIdentifier<ClassName>::getIdentifier() |
---|
| 83 | |
---|
[447] | 84 | /** |
---|
| 85 | @brief Creates the entry in the Factory. |
---|
| 86 | @param ClassName The name of the class |
---|
| 87 | */ |
---|
[219] | 88 | #define CreateFactory(ClassName) \ |
---|
[457] | 89 | bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create(#ClassName) |
---|
[219] | 90 | |
---|
[447] | 91 | /** |
---|
| 92 | @brief Returns the Identifier with either a given name or a given network ID through the factory. |
---|
| 93 | @param StringOrInt The name or the network ID of the class |
---|
| 94 | */ |
---|
[365] | 95 | #define ID(StringOrInt) \ |
---|
| 96 | Factory::getIdentifier(StringOrInt) |
---|
[434] | 97 | |
---|
[447] | 98 | /** |
---|
| 99 | @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file). |
---|
| 100 | @param varname The name of the variable |
---|
| 101 | @param defvalue The default-value of the variable |
---|
| 102 | */ |
---|
[434] | 103 | #define SetConfigValue(varname, defvalue) \ |
---|
| 104 | ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ |
---|
| 105 | if (!container##varname) \ |
---|
| 106 | { \ |
---|
| 107 | container##varname = new ConfigValueContainer(this->getIdentifier()->getName(), #varname, defvalue); \ |
---|
| 108 | this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \ |
---|
| 109 | } \ |
---|
[450] | 110 | varname = container##varname->getValue(varname) |
---|