= HowTo: Adding a new class to the hierarchy = [[TracNav(TracNav/TOC_Development)]] [[TOC]] 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. == Objects == 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. 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]). *.h file: {{{ #include "core/BaseObject.h" class MyClass : public BaseObject { public: MyClass(); }; or #include "objects/SomeOtherObject.h" class MyClass : public SomeOtherObject { public: MyClass(); }; }}} *.cc file: {{{ #include "core/CoreIncludes.h" CreateFactory(MyClass); // optional // Constructor: MyClass::MyClass() { RegisterObject(MyClass); } }}} == Interfaces == 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). Interfaces have to inherit virtually from [wiki:OrxonoxClass] and call '''RegisterRootObject('''''InterfaceName''''')''' in the constructor. *.h file: {{{ #include "core/OrxonoxClass.h" class MyInterface : virtual public OrxonoxClass { public: MyInterface(); }; }}} *.cc file: {{{ #include "core/CoreIncludes.h" // Constructor: MyInterface::MyInterface() { RegisterRootObject(MyInterface); } }}}