KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::Input Class Referenceabstract

Basic input class for game devices. More...

#include <Input.h>

Inheritance diagram for Karma::Input:

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< InputGetInputInstance ()
 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
 

Detailed Description

Basic input class for game devices.

Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ Input()

Karma::Input::Input ( InputData & inputDatRef)

A constructor for initializing the Input class.

Does the following stuff

  1. 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 joystick functions provide unlabeled axes, buttons and hats, with no indication of where they are located on the device.
    Their order may also vary between platforms even with the same device.
    To solve this problem the SDL community crowdsourced the SDL_GameControllerDB project, a database of mappings from many
    different devices to an Xbox-like gamepad.
  2. Create a list of connected joysticks (gamepads)
  3. Setting a callback function containing structure pointer, for all connected joysticks (gamepads)
  4. All the above steps are taken with API modularity (assuming GLFW API for input)
Since
Karma 1.0.0

◆ ~Input()

Karma::Input::~Input ( )

Destructor.

Since
Karma 1.0.0

Member Function Documentation

◆ AddControllerDevice()

void Karma::Input::AddControllerDevice ( std::shared_ptr< ControllerDevice > device)
protected

Add to the cache supplied device.

Parameters
deviceThe device supplied to the function
Since
Karma 1.0.0

◆ ControllerAxisPivotVal()

static float Karma::Input::ControllerAxisPivotVal ( int axis,
int cID )
inlinestatic

Polling function for the inquiry of the Axis pivot value (analog stick deflection for instance)

Parameters
axisThe horizontal/vertical directional deflection of the axis (GLFW axes). GLFW_GAMEPAD_AXIS_LEFT_Y is an example
cIDThe ID of the attached controller, defined in GLFW
Returns
float value rage -1.0f to 1.0f
Note
GLFW API is used
Since
Karma 1.0.0

◆ ControllerAxisPivotValImpl()

virtual float Karma::Input::ControllerAxisPivotValImpl ( int axis,
int cID )
protectedpure virtual

Declaration of ControllerAxisPivotVal function to be implemented.

Parameters
axisThe horizontal/vertical directional deflection of the axis (GLFW axes). GLFW_GAMEPAD_AXIS_LEFT_Y is an example.
cIDThe ID of the attached controller, defined in GLFW
Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ DeInit()

static void Karma::Input::DeInit ( )
inlinestatic

Deinitialize the Input system.

Since
Karma 1.0.0

◆ DisplayControllerDevices()

void Karma::Input::DisplayControllerDevices ( )
static

For debugging purposes, a function to print out the number of connected devices.

Since
Karma 1.0.0

◆ GetAPI()

static InputRegisteringAPI Karma::Input::GetAPI ( )
inlinestatic

Getter for API (enum) in use for input.

See also
InputRegisteringAPI
Since
Karma 1.0.0

◆ GetControllerDevices()

const std::list< std::shared_ptr< ControllerDevice > > & Karma::Input::GetControllerDevices ( ) const
inlineprotected

Getter for connected controller devices.

Since
Karma 1.0.0

◆ GetInputInstance()

static std::shared_ptr< Input > Karma::Input::GetInputInstance ( )
inlinestatic

Getter for the Input instance.

Since
Karma 1.0.0

◆ GetMousePosition()

static std::pair< float, float > Karma::Input::GetMousePosition ( )
inlinestatic

Polling function for the inquiry of mouse position (abscissa, ordinate)

Note
GLFW API is used
Since
Karma 1.0.0

◆ GetMousePositionImpl()

virtual std::pair< float, float > Karma::Input::GetMousePositionImpl ( )
protectedpure virtual

Declaration of GetMousePosition function to be implemented.

Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ GetMouseX()

static float Karma::Input::GetMouseX ( )
inlinestatic

Polling function for the inquiry of abscissa.

Note
GLFW API is used
Since
Karma 1.0.0

◆ GetMouseXImpl()

virtual float Karma::Input::GetMouseXImpl ( )
protectedpure virtual

Declaration of GetMouseX function to be implemented.

Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ GetMouseY()

static float Karma::Input::GetMouseY ( )
inlinestatic

Polling function for the inquiry of ordinate.

Note
GLFW API is used
Since
Karma 1.0.0

◆ GetMouseYImpl()

virtual float Karma::Input::GetMouseYImpl ( )
protectedpure virtual

Declaration of GetMouseY function to be implemented.

Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ Init()

void Karma::Input::Init ( )
static

Initialize the Input system for Karma.

Based upon the platform, the appropriate Input instance is created.

Note
ATM the constructors are empty
Since
Karma 1.0.0

◆ IsControllerButtonPressed()

static bool Karma::Input::IsControllerButtonPressed ( int button,
int cID )
inlinestatic

Polling function for the inquiry of game controller button pressed action.

Parameters
buttonThe integer corresponding to gamepad controller button For instance GLFW_GAMEPAD_BUTTON_A macro
cIDThe controller device ID, defined in GLFW
Note
GLFW API is used
Since
Karma 1.0.0

◆ IsControllerButtonPressedImpl()

virtual bool Karma::Input::IsControllerButtonPressedImpl ( int button,
int cID )
protectedpure virtual

Declaration of IsControllerButtonPressed function to be implemented.

Parameters
buttonThe integer corresponding to gamepad controller button. For instance GLFW_GAMEPAD_BUTTON_A macro.
cIDThe controller device ID, defined in GLFW
Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ IsKeyPressed()

static bool Karma::Input::IsKeyPressed ( int keycode)
inlinestatic

Polling function for inquiry of key press.

Parameters
keycodeGLFW defined code for keys, for instance GLFW_KEY_SPACE macro https://www.glfw.org/docs/3.3/group__keys.html
Note
GLFW API is used
Since
Karma 1.0.0

◆ IsKeyPressedImpl()

virtual bool Karma::Input::IsKeyPressedImpl ( int keycode)
protectedpure virtual

Declaration of IsKeyPressed function to be implemented.

Parameters
keycodeGLFW defined code for keys, for instance GLFW_KEY_SPACE macro https://www.glfw.org/docs/3.3/group__keys.html
Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ IsMouseButtonPressed()

static bool Karma::Input::IsMouseButtonPressed ( int button)
inlinestatic

Polling function for inquiry of mouse button press.

Parameters
buttonThe integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro
Note
GLFW API is used
Since
Karma 1.0.0

◆ IsMouseButtonPressedImpl()

virtual bool Karma::Input::IsMouseButtonPressedImpl ( int button)
protectedpure virtual

Declaration of IsMouseButtonPressed function to be implemeted.

Parameters
buttonThe integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro.
Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ IsMouseButtonReleased()

static bool Karma::Input::IsMouseButtonReleased ( int button)
inlinestatic

Polling function for the inquiry of mouse button release.

Parameters
buttonThe integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro
Note
GLFW API is used
Since
Karma 1.0.0

◆ IsMouseButtonReleasedImpl()

virtual bool Karma::Input::IsMouseButtonReleasedImpl ( int button)
protectedpure virtual

Declaration of IsMouseButtonReleased function to be implemented.

Parameters
buttonThe integer corresponding to mouse button. For instance GLFW_MOUSE_BUTTON_1 macro.
Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ SetConnectedJoySticks()

void Karma::Input::SetConnectedJoySticks ( )
staticprotected

Create a list of connected joysticks (gamepads)

Since
Karma 1.0.0

◆ SetEventCallback()

virtual void Karma::Input::SetEventCallback ( const EventCallbackFn & callback,
Window * window )
pure virtual

Set the event callback for the Input.

Parameters
callbackThe 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.
windowThe handle of GLFW window
Since
Karma 1.0.0

Implemented in Karma::LinuxInput, Karma::MacInput, and Karma::WindowsInput.

◆ SetGamepadMapping()

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 joystick functions provide unlabeled axes, buttons, and hats, with no indication of where they are located on the device.
Their order may also vary between platforms even with the same device.
To solve this problem the SDL community crowdsourced the SDL_GameControllerDB project, a database of mappings from many
different devices to an Xbox-like gamepad.

The code is like so

std::string testString = KarmaUtilities::ReadFileToSpitString("../Resources/Misc/GameControllerDB.txt");
const char* mappings = testString.c_str();
glfwUpdateGamepadMappings(mappings);
static std::string ReadFileToSpitString(const std::string &filePath)
Generates a sting of text contained within a file.
Definition KarmaUtilities.cpp:5
Since
Karma 1.0.0

The documentation for this class was generated from the following files: