GlistEngine
Loading...
Searching...
No Matches
gInputManager.h
Go to the documentation of this file.
1/*
2 * gInputManager.h
3 *
4 * Created on: Feb 9, 2026
5 * Author: Metehan Gezer
6 */
7
8#ifndef ENGINE_CORE_GINPUTMANAGER_H_
9#define ENGINE_CORE_GINPUTMANAGER_H_
10
11#include "gEventHook.h"
12#include "gWindowEvents.h"
13#include "gInputPlayer.h"
14#include <map>
15#include <vector>
16#include <string>
17
42class gInputManager : public gEventHook {
43public:
44 static const int MAXGAMEPADS = 16;
45 static const int MAXGAMEPADBUTTONS = 15;
46 static const int MAXGAMEPADAXES = 6;
47
49
52
53 // Player management
54
59 gInputPlayer* getPlayer(int playerIndex);
60
64 int getPlayerCount() const;
65
66 // Raw device state
67
68 bool isKeyPressed(int keyCode) const;
69 bool isKeyJustPressed(int keyCode) const;
70 void getMouseDelta(float& dx, float& dy) const;
71
72 bool isGamepadConnected(int gamepadId) const;
73 bool isGamepadButtonPressed(int gamepadId, int buttonId) const;
74 bool isGamepadButtonJustPressed(int gamepadId, int buttonId) const;
75 float getGamepadAxisValue(int gamepadId, int axisId) const;
76
81 void update();
82
83private:
84 void onEvent(gEvent& event) override;
85 bool onKeyPressed(gKeyPressedEvent& event);
86 bool onKeyReleased(gKeyReleasedEvent& event);
87 bool onMouseMoved(gMouseMovedEvent& event);
88 bool onJoystickConnect(gJoystickConnectEvent& event);
89 bool onJoystickDisconnect(gJoystickDisconnectEvent& event);
90
91 void pollGamepads();
92
93 // Keyboard + mouse state
94 bool keys[512];
95 bool keysjustpressed[512];
96 float mousedeltax;
97 float mousedeltay;
98
99 // Gamepad state
100 struct GamepadState {
101 bool connected;
102 bool buttons[MAXGAMEPADBUTTONS];
103 bool previousbuttons[MAXGAMEPADBUTTONS];
104 bool buttonsjustpressed[MAXGAMEPADBUTTONS];
105 float axes[MAXGAMEPADAXES];
106 };
107 GamepadState gamepadstate[MAXGAMEPADS];
108
109 // Players
110 std::vector<gInputPlayer*> players;
111};
112
114
115#endif /* ENGINE_CORE_GINPUTMANAGER_H_ */
Definition gEventHook.h:14
Definition gEvent.h:32
Definition gInputManager.h:42
bool isGamepadButtonJustPressed(int gamepadId, int buttonId) const
void getMouseDelta(float &dx, float &dy) const
static const int MAXGAMEPADAXES
Definition gInputManager.h:46
bool isKeyPressed(int keyCode) const
static const int MAXGAMEPADS
Definition gInputManager.h:44
float getGamepadAxisValue(int gamepadId, int axisId) const
static const int MAXGAMEPADBUTTONS
Definition gInputManager.h:45
bool isGamepadConnected(int gamepadId) const
gInputPlayer::AxisBinding AxisBinding
Definition gInputManager.h:48
gInputPlayer * getPlayer(int playerIndex)
bool isKeyJustPressed(int keyCode) const
int getPlayerCount() const
bool isGamepadButtonPressed(int gamepadId, int buttonId) const
Definition gInputPlayer.h:42
Definition gWindowEvents.h:196
Definition gWindowEvents.h:211
Definition gWindowEvents.h:46
Definition gWindowEvents.h:59
Definition gWindowEvents.h:68
gInputManager * inputmanager
Definition gInputPlayer.h:44