How to Implement a Player Extension

Player extensions are main ways of handling input in Limon Engine. Input from player is first handled by PhysicalPlayer class, which governs look around and movement, then all input information is passed to selected extension, so it can handle custom interactions, like pickups, shooting etc. On the other side, any interaction send by other entities to player is directly passed to player extension for handling.

PlayerExtensionInterface Class

PlayerExtensionInterface(LimonAPI *limonAPI)

The constructor of the interface.

Note

All Player Extension must have the same signature, no other parameters should be required.

void processInput(const InputStates &inputState, long time)

Called each frame with updated input information, and time of frame in milliseconds.

void interact(std::vector<LimonAPI::ParameterRequest> &interactionData)

Called by other entities to interact with player.

std::string getName() const

Returns the name of the Player Extension.

Warning

The name must be unique, or the results will be undefined.

InputStates Class Usage

InputStates is a thin wrapper around SDL2 input events. It has 4 main methods that can be used:

  1. getInputStatus: Allows checking if a key is down or up, for keys used by engine. 3 buttons of mouse is included.
  2. getInputEvents: Allows if a key state changed in last frame, for keys used by engine. 3 buttons of mouse is included.
  3. getRawKeyStates: Allows to check all key states for current frame.
  4. getMouseChange: Allows checking for relative or absolute position of the mouse, depending of the mode(Menu player uses absolute).

Full list of supported keys can be checked from src/InputStates.h

How to enable Dynamic Library discovery

Limon engine will try to load custom player extensions on engine startup, from libcustomTriggers file (extension based on platform). If the file is found, engine will check for a method with following signature:

void registerPlayerExtensions(std::map<std::string, PlayerExtensionInterface*(*)(LimonAPI*)>* playerExtensionMap)

This method should fill the actorMap passed, with all the custom actors, like this:

(*playerExtensionMap)["$EXTENSION_NAME1$"] = &createPlayerExtension<$ExtensionClass1$>;
(*playerExtensionMap)["$EXTENSION_NAME2$"] = &createPlayerExtension<$ExtensionClass2$>;