The CryENGINE input system

There are several aspects of the input system in CryENGINE, but in general it can be broken down into two components. The component that takes care of the actual input devices, such as the mouse and keyboard, and the component that handles the input events coming from these devices. Before we get into the intricacies of the input system, we will take a quick look at the layer of abstraction between the actual input devices and the systems using them.

A layer of abstraction

The source code that interfaces with the individual devices is separated into its own DLL called CryInput. This library handles the actual communication with the input devices and their drivers. Support for a new input device would usually be implemented inside this library. Currently supported input devices are the mouse, keyboard, the Xbox 360 controller, and the PlayStation 3 controller.

The CryInput DLL provides a layer of abstraction between the devices themselves and the systems that react with them. The input system queries the states of all devices regularly, or listens to their events, and then sends out input events to the rest of the engine. Classes in all other DLLs can listen to these inputs and choose to react to them.

This abstraction makes handling inputs very easy on the game side. Mouse movements are different from keystrokes on the keyboard or buttons on a gamepad, and differentiating between the different types of data can be a tedious task. CryInput unifies this data by running it through the same input event system. This means that input from a range of completely different devices can be handled in the same way. The game code does not need to worry about how to access the various input devices and deal with drivers and interfaces, since the low level implementation of the input system takes care of that part.

A layer of abstraction

CryInput takes care of the communication with the actual input devices

The abstraction of input devices also works to our advantage when we send events to input devices, for example, to trigger force feedback on a game controller. The game logic can play rumble effects without first requesting which controllers are attached and whether they support force feedback or not. The individual device-specific code is handled by the low level input system.

The input event system

Classes and systems anywhere in CryENGINE can listen and react to events coming from the input system. There are two kinds of events that are distributed: Input events and Action events.

The Input events are generated directly from the input system. The Action events are sent from the Game Actions system inside CryAction. They represent another layer of abstraction between the input system and the game logic.

To be able to receive and react to the input of Action events, classes can register themselves as input listeners or Action listeners, or both. The differences between the direct input events and Action events will be explained in the next section.

Tip

The common interfaces for these input events can be found in the files IInput.h and IActionMapManager.h, and they are called IInputEventListener and IActionListener.