Version 2 (modified by landauf, 16 years ago) (diff) |
---|
HowTo: Adding a new class to the hierarchy
TracNav(TracNav/TOC_Development)?
Table of Contents
The class hierarchy in Orxonox is controlled by 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 BaseObject? and call RegisterObject(ClassName) (see CoreIncludes?) in the constructor of this class.
If you want this class to be loadable? from an XML-file, add CreateFactory(ClassName) outside of the code. This creates a mapping between the string "ClassName" and the class itself (see 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 BaseObject? (or a derivative).
Interfaces have to inherit virtually from 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); }