Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 1 (modified by landauf, 16 years ago) (diff)

HowTo: Adding a new class to the hierarchy

TracNav(TracNav/TOC_Development)?

Table of Contents

  1. Objects
  2. Interfaces

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:

class MyClass : public BaseObject
{
    public:
        MyClass();
};

or

class MyClass : public SomeOtherObject
{
    public:
        MyClass();
};

*.cc file:

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:

class MyInterface : virtual public OrxonoxClass
{
    public:
        MyInterface();
};

*.cc file:

// Constructor:
MyInterface::MyInterface()
{
    RegisterRootObject(MyInterface);
}