Karma Engine
Loading...
Searching...
No Matches
Input.h
1#pragma once
2
3#include "krpch.h"
4
5#include "Karma/Log.h"
6#include "Karma/Events/Event.h"
7#include "Karma/Window.h"
8#include "Karma/KarmaUtilities.h"
9
10/*
11 Input system need complete revamp in the sense to provide enough context for input maping
12 and being able to work with specialized controller devices with minimal latency.
13*/
14
15
16namespace Karma
17{
18 enum class InputRegisteringAPI
19 {
20 None = 0,
21 GlfwInput
22 };
23
24 struct InputData
25 {
26 };
27
28 class KARMA_API GameAction
29 {
30 public:
31 GameAction();
32
33 // Getters
34 const std::string& GetGAName() const { return m_ActionName; }
35 const std::shared_ptr<void>& GetClassAction() const { return m_ClassAction; }
36 private:
37 // The class/object pointer, imparting the action
38 std::shared_ptr<void> m_ClassAction;
39 std::string m_ActionName;
40 };
41
42 class KARMA_API Button
43 {
44 public:
45 Button();
46
47 // Getters
48 const int& GetButtonID() const { return m_ButtonID; }
49 private:
50 int m_ButtonID;
51
52 };
53
54 class KARMA_API ControllerDevice
55 {
56 public:
57 ControllerDevice(int cID, const std::string& dName);
58
59 void AddInputMapping();
60
61 // Getters
62 const int& GetControllerID() const { return m_ControllerID; }
63 const std::string& GetDeviceName() const { return m_DeviceName; }
64
65 private:
66 std::unordered_map<std::shared_ptr<Button>, std::shared_ptr<GameAction>> m_InputMapping;
67 int m_ControllerID;
68 std::string m_DeviceName;
69 bool m_IsGamePad;
70 };
71
72 class KARMA_API Input
73 {
74 public:
75 Input(InputData& inputDatRef);
76 ~Input();
77
78 inline static bool IsKeyPressed(int keycode)
79 {
80 return s_Instance->IsKeyPressedImpl(keycode);
81 }
82
83 inline static bool IsMouseButtonPressed(int button)
84 {
85 return s_Instance->IsMouseButtonPressedImpl(button);
86 }
87
88 inline static bool IsMouseButtonReleased(int button)
89 {
90 return s_Instance->IsMouseButtonReleasedImpl(button);
91 }
92
93 inline static bool IsControllerButtonPressed(int button, int cID)
94 {
95 return s_Instance->IsControllerButtonPressedImpl(button, cID);
96 }
97
98 inline static float ControllerAxisPivotVal(int axis, int cID)
99 {
100 return s_Instance->ControllerAxisPivotValImpl(axis, cID);
101 }
102
103 inline static std::pair<float, float>GetMousePosition()
104 {
105 return s_Instance->GetMousePositionImpl();
106 }
107
108 inline static float GetMouseX()
109 {
110 return s_Instance->GetMouseXImpl();
111 }
112
113 inline static float GetMouseY()
114 {
115 return s_Instance->GetMouseYImpl();
116 }
117
118 inline static InputRegisteringAPI GetAPI() { return s_InputAPI; }
119
120 inline static void DeInit()
121 {
122 KR_CORE_INFO("Shutting down input system");
123 }
124
125 static void Init();
126
127 static std::shared_ptr<Input> GetInputInstance() { return s_Instance; }
128
129 using EventCallbackFn = std::function<void(Event&)>;
130 virtual void SetEventCallback(const EventCallbackFn& callback, Window* window) = 0;
131
132 void SetGamepadMapping();
133
134 // Debug purposes
135 static void DisplayControllerDevices();
136
137 protected:
138 virtual bool IsKeyPressedImpl(int keycode) = 0;
139 virtual bool IsMouseButtonPressedImpl(int button) = 0;
140 virtual bool IsMouseButtonReleasedImpl(int button) = 0;
141 virtual bool IsControllerButtonPressedImpl(int button, int cID) = 0;
142 virtual float ControllerAxisPivotValImpl(int axis, int cID) = 0;
143
144 virtual std::pair<float, float> GetMousePositionImpl() = 0;
145 virtual float GetMouseXImpl() = 0;
146 virtual float GetMouseYImpl() = 0;
147
148 // GLFW specific
149 static void SetConnectedJoySticks();
150
151 // Getters
152 const std::list<std::shared_ptr<ControllerDevice>>& GetControllerDevices() const { return m_ControllerDevices; }
153
154 void AddControllerDevice(std::shared_ptr<ControllerDevice> device);
155
156 private:
157 static InputRegisteringAPI s_InputAPI;
158 static std::shared_ptr<Input> s_Instance;
159
160 protected:
161 static std::list<std::shared_ptr<ControllerDevice>> m_ControllerDevices;
162 };
163}
Definition Input.h:43
Definition Input.h:55
Definition Event.h:35
Definition Input.h:29
Definition Input.h:73
Definition Window.h:27
@ None
Definition KarmaTypes.h:33
Definition Input.h:25