Brunot
Loading...
Searching...
No Matches
Controllers Class Reference

Class that detects whenever controllers are plugged in and broadcasts whenever any of them do an input. More...

#include <Controllers.h>

Collaboration diagram for Controllers:
[legend]

Public Member Functions

 Controllers ()
auto update (float dt) -> void
auto showMenu () -> void
auto getHeldButtonsMap () -> std::unordered_map< int, std::string > &
 Returns the map of all buttons that have ControllerHoldButton behavior and their corresponding event.
auto getTapButtonsMap () -> std::unordered_map< int, std::string > &
 Returns the map of all buttons that have ControllerButton behavior and their corresponding event.
auto getSticksMap () -> std::unordered_map< int, std::pair< std::string, std::string > >
 Returns the map of all the sticks and their corresponding events.
auto getEnabled () const -> bool
 Returns if controller input is currently enabled or not.
auto setEnabled (bool newState) -> void
 Sets whether input from controllers are accepted or not.
auto removeControllerID (int id) -> void
 Removes a controller ID from the updating list, meaning its inputs will no longer be received.
auto connectController (int controllerID) -> void
 Helper function that handles all the necessary protocols whenever a new controller is detected.

Static Public Member Functions

static auto getControllerNameFromID (int id) -> std::string
 Public function that gets the name for a controller based on its ID. Primarily used for debugging.
static auto controllerCallback (int joystickID, int event) -> void
 Callback used by GLFW whenever a controller is connected/disconnected.

Private Member Functions

auto getButtonStatesOfController (int controllerID) -> std::array< std::unique_ptr< ControllerButton >, 15 > &
auto getStickStatesOfController (int controllerID) -> std::array< ControllerStick, 6 > &

Private Attributes

bool enabled
 Bool used to see if we should be receiving input from controllers.
std::vector< int > connectedControllers
 Tracks every single controller that is currently plugged in.
std::unordered_map< int, std::string > holdButtonMap
 Map that takes GLFW gamepad buttons and maps them to input event names. Should only store buttons that have behavior when held down.
std::unordered_map< int, std::string > tapButtonMap
 Map that takes GLFW gamepad buttons and maps them to input event names. Should only store buttons that only have behavior when tapped.
std::unordered_map< int, std::pair< std::string, std::string > > stickMap
 Map that takes GLFW gamepad sticks and maps them to the two events per stick (sticks go from -1 to 1, so they need two events).
std::array< controllerInputTracker, 16 > lastFrameControllerState
 An array that tracks the previous frame state of the buttons and joysticks for controllers.
int maxConnectedControllers = 4
 Tracker used to see if we need to create another controllerInputTracker (so we're not allocating a lot of unique_ptr's that're never going to be used).

Detailed Description

Class that detects whenever controllers are plugged in and broadcasts whenever any of them do an input.

@Controllers.h

Constructor & Destructor Documentation

◆ Controllers()

Controllers::Controllers ( )

Navigation

Gameplay

Utility

Here is the call graph for this function:

Member Function Documentation

◆ connectController()

auto Controllers::connectController ( int controllerID) ->void

Helper function that handles all the necessary protocols whenever a new controller is detected.

Here is the caller graph for this function:

◆ controllerCallback()

auto Controllers::controllerCallback ( int joystickID,
int event )->void
static

Callback used by GLFW whenever a controller is connected/disconnected.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getButtonStatesOfController()

auto Controllers::getButtonStatesOfController ( int controllerID) ->std::array< std::unique_ptr< ControllerButton >, 15 > &
private
Here is the caller graph for this function:

◆ getControllerNameFromID()

auto Controllers::getControllerNameFromID ( int id) ->std::string
static

Public function that gets the name for a controller based on its ID. Primarily used for debugging.

Here is the caller graph for this function:

◆ getEnabled()

auto Controllers::getEnabled ( ) const->bool

Returns if controller input is currently enabled or not.

◆ getHeldButtonsMap()

auto Controllers::getHeldButtonsMap ( ) ->std::unordered_map< int, std::string > &

Returns the map of all buttons that have ControllerHoldButton behavior and their corresponding event.

◆ getSticksMap()

auto Controllers::getSticksMap ( ) ->std::unordered_map< int, std::pair< std::string, std::string > >

Returns the map of all the sticks and their corresponding events.

◆ getStickStatesOfController()

auto Controllers::getStickStatesOfController ( int controllerID) ->std::array< ControllerStick, 6 > &
private
Here is the caller graph for this function:

◆ getTapButtonsMap()

auto Controllers::getTapButtonsMap ( ) ->std::unordered_map< int, std::string > &

Returns the map of all buttons that have ControllerButton behavior and their corresponding event.

◆ removeControllerID()

auto Controllers::removeControllerID ( int id) ->void

Removes a controller ID from the updating list, meaning its inputs will no longer be received.

The ID will be re-added if the controller is unplugged, then plugged back in.

Parameters
idThe ID you want to remove

◆ setEnabled()

auto Controllers::setEnabled ( bool newState) ->void

Sets whether input from controllers are accepted or not.

◆ showMenu()

auto Controllers::showMenu ( ) ->void

◆ update()

auto Controllers::update ( float dt) ->void
Here is the call graph for this function:

Member Data Documentation

◆ connectedControllers

std::vector<int> Controllers::connectedControllers
private

Tracks every single controller that is currently plugged in.

◆ enabled

bool Controllers::enabled
private

Bool used to see if we should be receiving input from controllers.

◆ holdButtonMap

std::unordered_map<int, std::string> Controllers::holdButtonMap
private

Map that takes GLFW gamepad buttons and maps them to input event names. Should only store buttons that have behavior when held down.

◆ lastFrameControllerState

std::array<controllerInputTracker, 16> Controllers::lastFrameControllerState
private

An array that tracks the previous frame state of the buttons and joysticks for controllers.

◆ maxConnectedControllers

int Controllers::maxConnectedControllers = 4
private

Tracker used to see if we need to create another controllerInputTracker (so we're not allocating a lot of unique_ptr's that're never going to be used).

◆ stickMap

std::unordered_map<int, std::pair<std::string, std::string> > Controllers::stickMap
private

Map that takes GLFW gamepad sticks and maps them to the two events per stick (sticks go from -1 to 1, so they need two events).

◆ tapButtonMap

std::unordered_map<int, std::string> Controllers::tapButtonMap
private

Map that takes GLFW gamepad buttons and maps them to input event names. Should only store buttons that only have behavior when tapped.


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