Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.

Creating New Modules

Jeremy Lorelli edited this page Nov 7, 2019 · 2 revisions

Creating New Modules

Certain subsystems have their own modules. These include: inputsystem, shadeapixxx, vphysics, soundsystem, and more. Creating a new module is as simple as implementing the interface that is required. Usually, you can implement an interface by simply inheriting an interface class that's defined somewhere in the public/ folder.

For example, to implement inputsystem, you'd do something like this:

class CMyInputSystem : public CTier2AppSystem<IInputsystem>
{
    /* Override your methods here... */
};

Note the use of CTier2AppSystem. It provides some utilities in addition to CTier1AppSystem, which can be nice. You can implement InitReturnVal_t Init() and void Shutdown() to implement your own init/shutdown code. Example:

class CMyInputSystem : public CTier2AppSystem<IInputsystem>
{
    /* Override your methods here... */
    virtual InitReturnVal_t Init();
    virtual void Shutdown();
};

In your source file, put the following code:

static CMyInputSystem g_InputSystem;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CMyInputSystem, IInputSystem, INPUTSYSTEM_INTERFACE_VERSION, g_InputSystem);

Here we're creating a static global called g_InputSystem which will hold an instance of our interface class. EXPOSE_SINGLE_INTERFACE_GLOBALVAR will expose g_InputSystem, which can be then accessed by calling CreateInterface with INPUTSYSTEM_INTERFACE_VERSION. You can pretty much ignore the last part though. Loading the interface into the engine is usually done in the launcher DLL/SO (it can be done anywhere though), but you need not worry about this unless you're creating a brand-new module that the engine didn't previously rely on. If you've just created a new inputsystem (and given you haven't changed any methods in the interface), you can just replace the previous inputsystem library with yours, and the engine will load it up. The same goes for any other module the engine loads.

Clone this wiki locally