gecko0307 / dagon

3D game engine for D
https://gecko0307.github.io/dagon
Other
321 stars 30 forks source link

Input manager #52

Closed Timu5 closed 5 years ago

Timu5 commented 5 years ago

This adds InputManager class which take care of mapping between virtual name and actual device key code, button or axis. This allows to remap inputs without changing code. InputManager supports keyboard, mouse and game controller devices. Mapping are called "bindings" and are stored inside input.conf file(example below). One can map unlimited numbers of inputs to single name. There are two types of bindings: button bindings(keyboard, mouse button, controller button) and axis bindings(mouse axis, controlled axis, virtual axis created from 2 buttons).

Input manager instance is member of event manager and event listener, and therefor can be easily accessed from code. Input manager provides methods to get values for mappings: bool getButton(string name) // returns true if button currently pressed, false otherwise bool getButtonUp(string name) // returns true in frame when button is depressed bool getButtonDown(string name) // returns true in frame when button is pressed float getAxis(string name) // return float between -1 and 1 for specific axis (for virtual axis returns -1, 0 or 1)

Example input.conf file: upDownAxis: "ga_lefty, va(kb_down, kb_up)"; myButton: "kb_p, gb_leftshoulder";

Detailed binding format description can be found at beginning of parseBinding method in input.d file.

This also adds tracking of up and down event to EventManager, fix some problems with gamepad detection, update gamecontrollerdb.txt and generalize Configuration class.

Example usage of InputManager can be found in Dagoban especially in input.conf and game.d