Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/howto/ClassHierarchy


Ignore:
Timestamp:
Oct 10, 2008, 1:17:51 AM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/howto/ClassHierarchy

    v1 v1  
     1= HowTo: Adding a new class to the hierarchy =
     2[[TracNav(TracNav/TOC_Development)]]
     3[[TOC]]
     4
     5The 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 ==
     8If 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
     10If 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{{{
     14class MyClass : public BaseObject
     15{
     16    public:
     17        MyClass();
     18};
     19
     20or
     21
     22class MyClass : public SomeOtherObject
     23{
     24    public:
     25        MyClass();
     26};
     27}}}
     28
     29*.cc file:
     30{{{
     31CreateFactory(MyClass); // optional
     32
     33// Constructor:
     34MyClass::MyClass()
     35{
     36    RegisterObject(MyClass);
     37}
     38}}}
     39
     40== Interfaces ==
     41Interfaces 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
     43Interfaces have to inherit virtually from [wiki:OrxonoxClass] and call '''RegisterRootObject('''''InterfaceName''''')''' in the constructor.
     44
     45*.h file:
     46{{{
     47class MyInterface : virtual public OrxonoxClass
     48{
     49    public:
     50        MyInterface();
     51};
     52}}}
     53
     54*.cc file:
     55{{{
     56// Constructor:
     57MyInterface::MyInterface()
     58{
     59    RegisterRootObject(MyInterface);
     60}
     61}}}