OSK Logo OSK.Hub

Inputs

Source: GitHub GitHub

Packages: NuGet NuGet

Summary

An input system is responsible for a wide variety of requirements, ranging from input signaling and receiving to interpreting input state and responding to it, there is a vast amount of logic that can be required to fully configure and implement a good input system. Petra’s input framework aims to reduce the complexity of most of the challenging parts and to provide an API and SDK that requires only configuration to get setup and running.

The input libraries attempt to be flexible while providing as much rich information as possible when interacting and responding to user input, across a wide range of devices. To ensure the libraries are reusable across a wide variety of applications, Petra’s input system is split into 4 layers: Abstractions, Core, Configuration Extensions and Device extensions. Additionally, an integration layer is required for it to fully operate within a particular game engine to trigger the required input event to process; i.e. a core tenant of the shared logic is that the application integration layer will handle the actual input reading and that the core logic will merely interpret, track state, and respond to events as needed. The following sections will dive into each layer and their responsibilities.

Abstractions

The abstractions layer is meant to provide all the needed interfaces and data models to run an input system implementation. Petra provides an implementation of such an input system, but users can develop their own. Some of the key data structures are:

Input configurations are a collection of supported device configurations. Think of an input configuration as a complete set of controllers that can be used to create input schemes. For example, you can create an input scheme for a keyboard or keyboard & mouse, which would result in 2 different input configurations, one for the single keyboard and one for the keyboard and mouse. The current input system configuration is setup to create the list of known and supported input configurations utilizing the pre-defined input schemes. It is essential that if you want to support more than a single input configuration that you at least define an input scheme with the expected input configurations desired. The reason behind this requirement is to ensure that if a user has not yet defined their own custom scheme for the input configuration that they are able to still interact with the application using a default scheme provided by your application.

As input system configurations can become quite complex, the InputSystemConfigurationValidator is a tool that is used to validate that these configurations are valid and sufficient to be the source of truth for the system executing from it. Petra’s services will utilize this tool during initialization, but external input systems can and use this tool to validate the configuration they are utilizing is valid.

Core

The core logic provides an input system that is capable of processing various capabilities, responding to and transmitting application notifications and handling the APIs required to run a complete system - from user and device management to input scheme editing, the Petra input system aims to provide a complete, cohesive set of logic to respond and interact with user input. Some of the key data structures are:

Petra’s input system comes with some input capabilities built-in and will be updated as the need arises to include others:

Each capability will add various InputDetails and/or InputFeatures that can be used during action execution by an application responding to an input as it may need.

The core logic can be added to any DI container using AddInputSystem extension.

Configuration Extensions

The configuration extension projects provides a more DI friendly and manageable way to create an input system configuration. This can be accessed through the InputSystemConfigurationFactory. Using a fluent style approach, various aspects of configuration can be easily created and applied. There are three builders that are available to setup the configuration:

Device Extensions

The device extensions serves primarily to define concrete and/or base implementations for Devices and their related inputs. Other libraries may define their own sets of these, but Petra comes with Gamepad, Keyboard, and Mouse support provided through base classes that an engine integration may use. The key files here include:

Engine Support

Godot

Petra provides an integration with the Godot game engine. This is handled utilizing an input manager and configuring an input manager configuration in the Godot editor. Most of the core input manager logic is set within a base class that can be extended by different applications if the implementation provided is insufficient for some reason.

To fully utilize this library in a godot scene: