| 1 | = HowTo: Adding a new class to the hierarchy = |
| 2 | [[TracNav(TracNav/TOC_Development)]] |
| 3 | [[TOC]] |
| 4 | |
| 5 | The class hierarchy in Orxonox is controlled by [wiki:Identifier Identifiers]. Every class has it's identifier. This page explains how a new class is added correctly to the class hierarchy. |
| 6 | |
| 7 | == Objects == |
| 8 | If you want to create a new object (an object in the sense of a game-related class), you have to inherit directly or indirectly from [wiki:BaseObject] and call '''RegisterObject('''''ClassName''''')''' (see [wiki:CoreIncludes]) in the constructor of this class. |
| 9 | |
| 10 | If you want this class to be [wiki:Loader loadable] from an [wiki:XMLPort XML-file], add '''CreateFactory('''''ClassName''''')''' outside of the code. This creates a mapping between the string "ClassName" and the class itself (see [wiki:Factory]). |
| 11 | |
| 12 | *.h file: |
| 13 | {{{ |
| 14 | class MyClass : public BaseObject |
| 15 | { |
| 16 | public: |
| 17 | MyClass(); |
| 18 | }; |
| 19 | |
| 20 | or |
| 21 | |
| 22 | class MyClass : public SomeOtherObject |
| 23 | { |
| 24 | public: |
| 25 | MyClass(); |
| 26 | }; |
| 27 | }}} |
| 28 | |
| 29 | *.cc file: |
| 30 | {{{ |
| 31 | CreateFactory(MyClass); // optional |
| 32 | |
| 33 | // Constructor: |
| 34 | MyClass::MyClass() |
| 35 | { |
| 36 | RegisterObject(MyClass); |
| 37 | } |
| 38 | }}} |
| 39 | |
| 40 | == Interfaces == |
| 41 | Interfaces in Orxonox aren't objects by themselfes, but provide functions and features for real objects. Those objects inherit from the interfaces, additionally to [wiki:BaseObject] (or a derivative). |
| 42 | |
| 43 | Interfaces have to inherit virtually from [wiki:OrxonoxClass] and call '''RegisterRootObject('''''InterfaceName''''')''' in the constructor. |
| 44 | |
| 45 | *.h file: |
| 46 | {{{ |
| 47 | class MyInterface : virtual public OrxonoxClass |
| 48 | { |
| 49 | public: |
| 50 | MyInterface(); |
| 51 | }; |
| 52 | }}} |
| 53 | |
| 54 | *.cc file: |
| 55 | {{{ |
| 56 | // Constructor: |
| 57 | MyInterface::MyInterface() |
| 58 | { |
| 59 | RegisterRootObject(MyInterface); |
| 60 | } |
| 61 | }}} |