Game Develop C++ Platform: About Extension.cpp

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
About Extension.cpp

An extension has to define ( Usually in a file called Extension.cpp for the C++ Platform ) a class that is derived from the ExtensionBase class. This class contains, in its constructor, the declarations of everything that is provided by the extension.

# Declaring the extension information

The declarations are made using the methods provided by gd::PlatformExtension ( ExtensionBase is itself a subclass of gd::PlatformExtension, provided by Game Develop Core. See the Game Develop Core documentation if you need more information ).

The first declaration if often the information about the extension :

Extension()
{
SetExtensionInformation("TextObject",
_("Text object"),
_("Extension allowing to use an object displaying a text."),
"Florian Rival",
"zlib/libpng License ( Open Source )");

The first parameter is the name of the extension. Choose carefully the name of the extension, as projects are directly referring to it.

# Declaring actions, conditions and expressions

Actions are declared like this :

AddAction("Name",
_("Name displayed to users"),
_("Description"),
_("Sentence displayed in event editor"),
_("Category"),
"path-to-an-24-by-24-icon-file.png",
"path-to-an-16-by-16-icon-file.png")
.AddParameter("theTypeOfTheParameter", _("Parameter1"))
.AddParameter("theTypeOfTheParameter", _("Parameter2"))
.codeExtraInformation.SetFunctionName("MyFunctionName").SetIncludeFile("MyExtension/MyIncludeFile.h");

Declare conditions and expressions in a similar way.
Parameters are added using gd::InstructionMetadata::AddParameter. See the function documentation for more information ( In the Game Develop Core documentation ).
See also gd::InstructionMetadata::ExtraInformation class documentation for more information about SetFunctionName and similar functions.

# Declaring objects

When declaring an object, extensions must provide two classes: A class deriving from gd::Object, which is the object that will be used for storage and at edittime, and another class deriving from RuntimeObject, which will be used by the game engine.
Objects are declared like this :

gd::ObjectMetadata & obj = AddObject("Name",
_("Name displayed to users"),
_("Description"),
"path-to-an-32-by-32-icon.png",
&FunctionForCreatingTheObject,
&FunctionForDestroyingTheObject);
AddRuntimeObject(obj, "RuntimeObjectName", CreateRuntimeObjectName, DestroyRuntimeObjectName);

"FunctionForCreatingTheObject" and "FunctionForDestroyingTheObject" are two functions that must be provided with the object, the first one to create a new instance of the object and the second to delete an object instance. See implementation example in TextObject extension.
The C++ platform also requires that you call AddRuntimeObject to declares the RuntimeObject class associated to the object being declared:
You must pass as parameter the name of the class inheriting from RuntimeObject and two functions used to create and destroy an instance of the RuntimeObject.

You can then declare the actions, conditions, and expressions related to the objects, using the AddAction/AddCondition/AddExpression methods provided by obj. You will also want to specify where the object is located using gd::ObjectMetadata::SetIncludeFile. For example:

obj.SetIncludeFile("TextObject/TextObject.h");

# Declaring events

Events are declared like this :

AddEvent("Name",
_("Name displayed to users"),
"Description",
"Group",
"path-to-a-16-by-16-icon.png",
boost::shared_ptr<gd::BaseEvent>(new EventClassName))

The event must be able to generate the code when events are being translated to C++:
This is done by calling SetCodeGenerator. For example:

AddEvent("Standard",
_("Standard event"),
_("Standard event: Actions are run if conditions are fulfilled."),
"",
"res/eventaddicon.png",
boost::shared_ptr<gd::BaseEvent>(new gd::StandardEvent))
.SetCodeGenerator(boost::shared_ptr<gd::EventMetadata::CodeGenerator>(codeGen));

# Declaring the automatisms

Automatisms are declared like objects:

gd::AutomatismMetadata & aut = AddAutomatism("Name",
_("Name displayed to users"),
_("DefaultNameUsedInEditor"),
_("Description."),
"Group",
"path-to-a-32-by-32-icon.png",
"AutomatismClassName",
boost::shared_ptr<gd::Automatism>(new AutomatismClassName),
boost::shared_ptr<gd::AutomatismsSharedData>(new AutomatismSharedDataClassName));

( The last line can be replaced by boost::shared_ptr<gd::AutomatismsSharedData>() if no shared data are being used ).
You can then declare the actions, conditions, and expressions related to the automatism like objects:
Call AddAction/AddCondition/AddExpression on the aut object.

# Excluding elements declaration from runtime

When your extension is compiled for runtime ( as opposed to edittime ), Game Develop does not known anything about action/condition or even events classes.
You have then to exclude all actions/conditions/expressions/events declaration from extension at runtime ( Only Extension/Object/Automatisms declarations have to be kept ).

Use the GD_IDE_ONLY define to achieve this goal, as demonstrated in this skeleton of a complete extension declaration:

class Extension : public ExtensionBase
{
public:
Extension()
{
SetExtensionInformation("MyExtension",
_("Extension name"),
_("Extension declaration"),
"Author",
"license");
#if defined(GD_IDE_ONLY)
AddAction(...);
AddCondition(...);
AddExpression(...);
#endif
{
gd::ObjectMetadata & obj = AddObject("ObjectName",
_("Object name"),
_("Description"),
"CppPlatform/Extensions/myicon.png",
&CreateMyObject,
&DestroyMyObject,
"ObjectClassName");
AddRuntimeObject(obj, "RuntimeObjectName", CreateRuntimeObjectName, DestroyRuntimeObjectName);
#if defined(GD_IDE_ONLY)
obj.SetIncludeFile("MyExtension/MyIncludeFile.h");
obj.AddAction(...);
obj.AddCondition(...);
obj.AddExpression(...);
#endif
}
{
gd::AutomatismMetadata & aut = AddAutomatism("AutomatismName",
_("Automatism name"),
"defaultGDname",
_("Description"),
"",
"CppPlatform/Extensions/myicon.png",
"PhysicsAutomatism",
boost::shared_ptr<gd::Automatism>(new AutomatismClassName),
boost::shared_ptr<gd::AutomatismsSharedData>(new AutomatismSharedDataClassName));
#if defined(GD_IDE_ONLY)
automatismInfo.SetIncludeFile("MyExtension/MyIncludeFile.h");
aut.AddAction(...);
aut.AddCondition(...);
aut.AddExpression(...);
#endif
}
GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION();
};
virtual ~Extension() {};
};
// Used by Game Develop to create the extension class
// -- Do not need to be modified. --
extern "C" ExtensionBase * GD_EXTENSION_API CreateGDExtension() {
return new Extension;
}
// Used by Game Develop to destroy the extension class
// -- Do not need to be modified. --
extern "C" void GD_EXTENSION_API DestroyGDExtension(ExtensionBase * p) {
delete p;
}