[670] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Fabian 'x3n' Landau |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[676] | 28 | #ifndef _CoreIncludes_H__ |
---|
| 29 | #define _CoreIncludes_H__ |
---|
| 30 | |
---|
[497] | 31 | /** |
---|
| 32 | @file CoreIncludes.h |
---|
| 33 | @brief Definition of macros and typedefs. |
---|
| 34 | |
---|
| 35 | Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface |
---|
| 36 | or the BaseObject itself, it needs the macro RegisterRootObject(class) instead. |
---|
| 37 | |
---|
| 38 | To allow the object being created through the factory, use the CreateFactory(class) macro outside |
---|
| 39 | the of the class implementation, so it gets executed before main(). |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | // All needed header-files |
---|
| 43 | #include "Identifier.h" |
---|
| 44 | #include "Factory.h" |
---|
| 45 | #include "ClassFactory.h" |
---|
| 46 | #include "Iterator.h" |
---|
| 47 | #include "OrxonoxClass.h" |
---|
| 48 | #include "ConfigValueContainer.h" |
---|
| 49 | #include "Debug.h" |
---|
| 50 | |
---|
| 51 | #include "OgreVector2.h" |
---|
| 52 | #include "OgreVector3.h" |
---|
| 53 | #include "OgreColourValue.h" |
---|
| 54 | #include "OgreQuaternion.h" |
---|
| 55 | #include "OgreMatrix3.h" |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | // Some typedefs |
---|
| 59 | namespace orxonox |
---|
| 60 | { |
---|
| 61 | typedef Ogre::Vector2 Vector2; |
---|
| 62 | typedef Ogre::Vector3 Vector3; |
---|
| 63 | typedef Ogre::ColourValue ColourValue; |
---|
| 64 | typedef Ogre::Radian Radian; |
---|
| 65 | typedef Ogre::Degree Degree; |
---|
| 66 | typedef Ogre::Real Real; |
---|
| 67 | typedef Ogre::Quaternion Quaternion; |
---|
| 68 | typedef Ogre::Matrix3 Matrix3; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. |
---|
| 74 | @param ClassName The name of the class |
---|
| 75 | @param bRootClass True if the class is directly derived from OrxonoxClass |
---|
| 76 | */ |
---|
| 77 | #define InternRegisterObject(ClassName, bRootClass) \ |
---|
| 78 | this->setIdentifier(orxonox::ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \ |
---|
| 79 | if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \ |
---|
| 80 | this->getParents()->add(this->getIdentifier()); \ |
---|
| 81 | orxonox::ClassIdentifier<ClassName>::addObject(this) |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | @brief Intern macro, containing the specific part of RegisterRootObject. |
---|
| 85 | @param ClassName The name of the class |
---|
| 86 | */ |
---|
| 87 | #define InternRegisterRootObject(ClassName) \ |
---|
| 88 | if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \ |
---|
[531] | 89 | this->setParents(new orxonox::IdentifierList()); \ |
---|
[497] | 90 | InternRegisterObject(ClassName, true) |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | @brief RegisterObject - with and without debug output. |
---|
| 94 | @param ClassName The name of the class |
---|
| 95 | */ |
---|
| 96 | #define RegisterObject(ClassName) \ |
---|
| 97 | COUT(4) << "*** Register Object: " << #ClassName << "\n"; \ |
---|
| 98 | InternRegisterObject(ClassName, false) |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | @brief RegisterRootObject - with and without debug output. |
---|
| 102 | @param ClassName The name of the class |
---|
| 103 | */ |
---|
| 104 | #define RegisterRootObject(ClassName) \ |
---|
| 105 | COUT(4) << "*** Register Root-Object: " << #ClassName << "\n"; \ |
---|
| 106 | InternRegisterRootObject(ClassName) |
---|
| 107 | |
---|
| 108 | /** |
---|
| 109 | @brief Returns the Identifier of the given class. |
---|
| 110 | @param ClassName The name of the class |
---|
| 111 | */ |
---|
| 112 | #define Class(ClassName) \ |
---|
| 113 | ClassIdentifier<ClassName>::getIdentifier() |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | @brief Creates the entry in the Factory. |
---|
| 117 | @param ClassName The name of the class |
---|
| 118 | */ |
---|
| 119 | #define CreateFactory(ClassName) \ |
---|
| 120 | bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName) |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | @brief Returns the Identifier with either a given name or a given network ID through the factory. |
---|
| 124 | @param StringOrInt The name or the network ID of the class |
---|
| 125 | */ |
---|
| 126 | #define ID(StringOrInt) \ |
---|
| 127 | orxonox::Factory::getIdentifier(StringOrInt) |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file). |
---|
| 131 | @param varname The name of the variable |
---|
| 132 | @param defvalue The default-value of the variable |
---|
| 133 | */ |
---|
| 134 | #define SetConfigValue(varname, defvalue) \ |
---|
| 135 | orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ |
---|
| 136 | if (!container##varname) \ |
---|
| 137 | { \ |
---|
[667] | 138 | container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \ |
---|
[497] | 139 | this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \ |
---|
| 140 | } \ |
---|
| 141 | varname = container##varname->getValue(varname) |
---|
[676] | 142 | |
---|
| 143 | #endif /* _CoreIncludes_H__ */ |
---|