VR-Engage  2.2
Loading...
Searching...
No Matches
sdlGameControllerDevice.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
6//! \file
7//! \brief Input device implementation for joystick and gamepad controllers
8
9#pragma once
10
11#include "vreInput/export.h"
13#include "vreInput/inputData.h"
14
15#include <vector>
16#include <map>
17
18namespace makVre
19{
20//! \brief Input device implementation for joystick and gamepad controllers
21//!
22//! This class provides support for joystick and gamepad devices, handling
23//! axis movement, button presses, and hat switch inputs. It can manage
24//! multiple controllers simultaneously, differentiating them by index.
26{
27public:
28 //! \brief Default constructor
29 //!
30 //! Initializes the joystick input device
32
33 //! \brief Virtual destructor
34 //!
35 //! Cleans up resources owned by the joystick input device
36 virtual ~DtSDLGameControllerDevice() override;
37
38 //! \brief Initialize the joystick input device
39 //!
40 //! Sets up the joystick device with the input manager and initializes
41 //! controller tracking structures.
42 //!
43 //! \param mgr Reference to the input manager that owns this device
44 //! \return True if initialization succeeded, false otherwise
45 virtual bool init(DtVreInputManager& mgr) override;
46
47 //! \brief Shut down the joystick input device
48 //!
49 //! Releases resources and disconnects from any connected controllers
50 virtual void shutdown() override;
51
52 //! \brief Report the current state of all controller inputs
53 //!
54 //! Sends input events for the current state of all connected controllers' axes,
55 //! buttons, and hat switches to initialize the input system with current values
56 virtual void reportCurrentState() override;
57
58 //! \brief Update method called each frame
59 //!
60 //! Polls connected controllers for input changes and updates internal state
61 //!
62 //! \param dt Delta time in seconds since the last frame
63 virtual void tick(double dt) override;
64
65 //! \brief Add a controller to be tracked by this device
66 //!
67 //! Registers a new controller with the specified index and initializes
68 //! data structures to track its state
69 //!
70 //! \param index The index of the controller to add
71 virtual void addController(int index);
72
73 //! \brief Remove a controller from being tracked
74 //!
75 //! Unregisters a controller and removes its tracking data
76 //!
77 //! \param id The ID of the controller to remove
78 virtual void removeController(int id);
79
80 //! \brief Process input from a controller
81 //!
82 //! Processes input data from a controller and forwards it to the input manager
83 //!
84 //! \param controller The index of the controller generating the input
85 //! \param type The type of input (axis, button, hat, etc.)
86 //! \param id The specific input ID (button number, axis index, etc.)
87 //! \param value The input value
88 //! \param flags Optional flags specific to the input type
89 virtual void processInput(int controller, DtInputType type, int id, float value, int flags = 0);
90
91 //! \brief Process axis input from a controller
92 //!
93 //! Specialized handling for axis inputs, with additional processing
94 //! for state tracking and dead zones
95 //!
96 //! \param controller The index of the controller generating the input
97 //! \param id The axis index
98 //! \param value The axis value
99 virtual void processAxisInput(int controller, int id, int value);
100
101 virtual const std::map<int, DtInputData>& getControllerData() const { return myControllerData; };
102
103protected:
104 //! \brief Pointer to the input manager that owns this device
106
107 //! \brief List of indices for currently connected controllers
108 std::vector<int> myControllers;
109
110 //! \brief Map of controller indices to their corresponding input data
111 std::map<int, DtInputData> myControllerData;
112
113 //! \brief Map tracking current position of each hat switch for each controller
114 //!
115 //! First key is controller index, second key is hat ID, value is position
116 std::map<int, std::map<int, float>> myHatPosition;
117};
118
119} // namespace makVre
DtInputDevice()
Default constructor.
Definition inputDevice.h:28
DtVreInputManager * myManager
Pointer to the input manager that owns this device.
Definition sdlGameControllerDevice.h:105
virtual ~DtSDLGameControllerDevice() override
Virtual destructor.
virtual void addController(int index)
Add a controller to be tracked by this device.
virtual void processInput(int controller, DtInputType type, int id, float value, int flags=0)
Process input from a controller.
virtual bool init(DtVreInputManager &mgr) override
Initialize the joystick input device.
virtual void shutdown() override
Shut down the joystick input device.
std::map< int, DtInputData > myControllerData
Map of controller indices to their corresponding input data.
Definition sdlGameControllerDevice.h:111
virtual void reportCurrentState() override
Report the current state of all controller inputs.
std::vector< int > myControllers
List of indices for currently connected controllers.
Definition sdlGameControllerDevice.h:108
virtual void processAxisInput(int controller, int id, int value)
Process axis input from a controller.
virtual void tick(double dt) override
Update method called each frame.
DtSDLGameControllerDevice()
Default constructor.
virtual void removeController(int id)
Remove a controller from being tracked.
virtual const std::map< int, DtInputData > & getControllerData() const
Definition sdlGameControllerDevice.h:101
std::map< int, std::map< int, float > > myHatPosition
Map tracking current position of each hat switch for each controller.
Definition sdlGameControllerDevice.h:116
Central manager for input device handling, action mapping, and input processing.
Definition vreInputManager.h:81
Defines DLL export/import macros for the vreInput library.
#define VREINPUT_DLL
DLL export/import macro for the vreInput library.
Definition export.h:25
Defines data structures and enumerations for input device data.
Abstract base class for input device implementations.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
enum DtInputType { DtInputTypeAxis=0, DtInputTypeButton, DtInputTypeDoubleClick, DtInputTypeHat, DtInputTypeTrackBall, DtInputTypeMotion, DtInputTypeScroll, DtInputTypeKey, DtInputTypeInvalid } DtInputType
Enumeration of input event types.
Definition inputData.h:30