Skip to content

Input Manager

Twarit Waikar edited this page Dec 13, 2018 · 2 revisions

Rubeus: Input Manager

Created by SDSLabs with ❤️

The Rubeus Engine's Input Manager takes heavy inspiration from how Unreal Engine 4 handles inputs. Currently, the Input Manager is present inside the Rubeus::Engine pointer object and requires polling for connecting responses to different inputs.

Jargon

  • RInputManager maintains keybindings for the users to poll later. Multiple keys can be added to respond to a single keybinding. However, support for polling single key presses (not even through keybindings) is possible and recommended only for inputs which are less frequently required to be polled to the input manager.

How to use the Input Manager?

Let's see how to use the Input Manager in C++ code. You would expect to see the step which adds keybindings inside begin() functions of your levels and objects. The later steps are more suited to be written inside tick() functions.

Rubeus::Engine->getCurrentLevelInputManager()->addKeyToKeyBinding("Jump", Rubeus::EKeyboardKeys::__SPACE);

Have a look at what keys are available for use under the documentation for EKeyboardKeys

  • After all keybindings have been added, use polling inside tick() functions to add input controls. v2.0 will add sync response from InputManager which will be better on performance.
if (Rubeus::Engine->getCurrentLevelInputManager()->isKeyBindingPressed("Jump"))
{
    // Do whatever you like to happen when "Jump" is active
    Rubeus::Engine->load(*Rubeus::Engine->getCurrentLevel()->InstantiatedLevels["sample_level"]);
}

There are functionalities available such as mouse button inputs, scrolling inputs, disabling/enabling all inputs (for narrative scenes), disabling specific keybindings and adding multiple keys to a keybinding. Have a read at the documentation for RInputManager.

Contributor's Guide

Rubeus' Input Manager uses a simple unordered map for keybindings (strings) to keys (arrays of keycodes) store keybindings. Keys are represented by integer keycodes as defined by GLFW. GLFW is given a key-callback function that sets the status of whether a key is pressed or not inside the KeyMap.