KarmaEngine
Game Engine for practical learning and research purposes
|
Basic input class for game devices. More...
#include <Input.h>
Public Types | |
using | EventCallbackFn = std::function<void(Event&)> |
Public Member Functions | |
Input (InputData &inputDatRef) | |
A constructor for initializing the Input class. | |
~Input () | |
Destructor. | |
virtual void | SetEventCallback (const EventCallbackFn &callback, Window *window)=0 |
Set the event callback for the Input. | |
void | SetGamepadMapping () |
Set the gamepad mapping based on a database (../Resources/Misc/GameControllerDB.txt) The mapping is done by taking XBox controller as a reference. For the need of such mapping please see https://www.glfw.org/docs/3.3/input_guide.html#gamepad_mapping. | |
Static Public Member Functions | |
static bool | IsKeyPressed (int keycode) |
Polling function for inquiry of key press. | |
static bool | IsMouseButtonPressed (int button) |
Polling function for inquiry of mouse button press. | |
static bool | IsMouseButtonReleased (int button) |
Polling function for the inquiry of mouse button release. | |
static bool | IsControllerButtonPressed (int button, int cID) |
Polling function for the inquiry of game controller button pressed action. | |
static float | ControllerAxisPivotVal (int axis, int cID) |
Polling function for the inquiry of the Axis pivot value (analog stick deflection for instance) | |
static std::pair< float, float > | GetMousePosition () |
Polling function for the inquiry of mouse position (abscissa, ordinate) | |
static float | GetMouseX () |
Polling function for the inquiry of abscissa. | |
static float | GetMouseY () |
Polling function for the inquiry of ordinate. | |
static InputRegisteringAPI | GetAPI () |
Getter for API (enum) in use for input. | |
static void | DeInit () |
Deinitialize the Input system. | |
static void | Init () |
Initialize the Input system for Karma. | |
static std::shared_ptr< Input > | GetInputInstance () |
Getter for the Input instance. | |
static void | DisplayControllerDevices () |
For debugging purposes, a function to print out the number of connected devices. | |
Protected Member Functions | |
virtual bool | IsKeyPressedImpl (int keycode)=0 |
Declaration of IsKeyPressed function to be implemented. | |
virtual bool | IsMouseButtonPressedImpl (int button)=0 |
Declaration of IsMouseButtonPressed function to be implemeted. | |
virtual bool | IsMouseButtonReleasedImpl (int button)=0 |
Declaration of IsMouseButtonReleased function to be implemented. | |
virtual bool | IsControllerButtonPressedImpl (int button, int cID)=0 |
Declaration of IsControllerButtonPressed function to be implemented. | |
virtual float | ControllerAxisPivotValImpl (int axis, int cID)=0 |
Declaration of ControllerAxisPivotVal function to be implemented. | |
virtual std::pair< float, float > | GetMousePositionImpl ()=0 |
Declaration of GetMousePosition function to be implemented. | |
virtual float | GetMouseXImpl ()=0 |
Declaration of GetMouseX function to be implemented. | |
virtual float | GetMouseYImpl ()=0 |
Declaration of GetMouseY function to be implemented. | |
const std::list< std::shared_ptr< ControllerDevice > > & | GetControllerDevices () const |
Getter for connected controller devices. | |
void | AddControllerDevice (std::shared_ptr< ControllerDevice > device) |
Add to the cache supplied device. | |
Static Protected Member Functions | |
static void | SetConnectedJoySticks () |
Create a list of connected joysticks (gamepads) | |
Static Protected Attributes | |
static std::list< std::shared_ptr< ControllerDevice > > | m_ControllerDevices |
Basic input class for game devices.
Karma::Input::Input | ( | InputData & | inputDatRef | ) |
A constructor for initializing the Input class.
Does the following stuff
Set the gamepad mapping based on a database (../Resources/Misc/GameControllerDB.txt) The mapping is done by taking XBox controller as a reference. For the need of such mapping
please see https://www.glfw.org/docs/3.3/input_guide.html#gamepad_mapping
Karma::Input::~Input | ( | ) |
Destructor.
|
protected |
Add to the cache supplied device.
device | The device supplied to the function |
|
inlinestatic |
Polling function for the inquiry of the Axis pivot value (analog stick deflection for instance)
axis | The horizontal/vertical directional deflection of the axis (GLFW axes). GLFW_GAMEPAD_AXIS_LEFT_Y is an example |
cID | The ID of the attached controller, defined in GLFW |
|
protectedpure virtual |
Declaration of ControllerAxisPivotVal function to be implemented.
axis | The horizontal/vertical directional deflection of the axis (GLFW axes). GLFW_GAMEPAD_AXIS_LEFT_Y is an example. |
cID | The ID of the attached controller, defined in GLFW |
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
inlinestatic |
Deinitialize the Input system.
|
static |
For debugging purposes, a function to print out the number of connected devices.
|
inlinestatic |
|
inlineprotected |
Getter for connected controller devices.
|
inlinestatic |
Getter for the Input instance.
|
inlinestatic |
Polling function for the inquiry of mouse position (abscissa, ordinate)
|
protectedpure virtual |
Declaration of GetMousePosition function to be implemented.
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
inlinestatic |
Polling function for the inquiry of abscissa.
|
protectedpure virtual |
Declaration of GetMouseX function to be implemented.
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
inlinestatic |
Polling function for the inquiry of ordinate.
|
protectedpure virtual |
Declaration of GetMouseY function to be implemented.
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
static |
|
inlinestatic |
Polling function for the inquiry of game controller button pressed action.
button | The integer corresponding to gamepad controller button For instance GLFW_GAMEPAD_BUTTON_A macro |
cID | The controller device ID, defined in GLFW |
|
protectedpure virtual |
Declaration of IsControllerButtonPressed function to be implemented.
button | The integer corresponding to gamepad controller button. For instance GLFW_GAMEPAD_BUTTON_A macro. |
cID | The controller device ID, defined in GLFW |
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
inlinestatic |
Polling function for inquiry of key press.
keycode | GLFW defined code for keys, for instance GLFW_KEY_SPACE macro https://www.glfw.org/docs/3.3/group__keys.html |
|
protectedpure virtual |
Declaration of IsKeyPressed function to be implemented.
keycode | GLFW defined code for keys, for instance GLFW_KEY_SPACE macro https://www.glfw.org/docs/3.3/group__keys.html |
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
inlinestatic |
Polling function for inquiry of mouse button press.
button | The integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro |
|
protectedpure virtual |
Declaration of IsMouseButtonPressed function to be implemeted.
button | The integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro. |
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
inlinestatic |
Polling function for the inquiry of mouse button release.
button | The integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro |
|
protectedpure virtual |
Declaration of IsMouseButtonReleased function to be implemented.
button | The integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro. |
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
|
staticprotected |
Create a list of connected joysticks (gamepads)
|
pure virtual |
Set the event callback for the Input.
callback | The function to be called when Input event is receieved from GLFW. Usually Application::OnEvent(), which dispatches the Events, is fed into as lambda for instance in glfwSetJoystickCallback. |
window | The handle of GLFW window |
Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.
void Karma::Input::SetGamepadMapping | ( | ) |
Set the gamepad mapping based on a database (../Resources/Misc/GameControllerDB.txt) The mapping is done by taking XBox controller as a reference. For the need of such mapping please see https://www.glfw.org/docs/3.3/input_guide.html#gamepad_mapping.
The code is like so