官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 韶关市| 马山县| 长阳| 赤城县| 比如县| 清丰县| 历史| 汶川县| 武强县| 荥阳市| 右玉县| 丘北县| 吉首市| 绥德县| 邹平县| 印江| 云霄县| 南丹县| 靖边县| 武功县| 太原市| 广灵县| 通道| 阳高县| 娄底市| 丰宁| 洪洞县| 会同县| 宜兰市| 岢岚县| 福建省| 吉安市| 库尔勒市| 吉隆县| 曲麻莱县| 沧源| 西平县| 濮阳市| 静乐县| 廉江市| 嘉黎县|