Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 4 (modified by landauf, 3 years ago) (diff)

fixed links

HowTo: Adding a new class to the hierarchy

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.

Features available to classes in the 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 doc/BaseObject and call RegisterObject(ClassName) (see doc/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 doc/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 doc/BaseObject (or a derivative).

Interfaces have to inherit virtually from doc/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);
}