11#include " Input/UserInput.hpp"
2+ #include " Core.h"
3+ #include " Debug/Logger.hpp"
24#include " Input/InputEvents.h"
35#include " Input/ControllerObject.hpp"
46
@@ -10,7 +12,7 @@ using namespace Core;
1012// ---------------------------------------------------------------------------------------------------------------------
1113void UserInput::StartCapturing ()
1214{
13- if (!m_bIsCapturing && m_pWindowDesc )
15+ if (!m_bIsCapturing && this -> GetWindowDesc () )
1416 m_bIsCapturing = true ;
1517}
1618
@@ -36,9 +38,9 @@ void UserInput::Update()
3638 }
3739 }
3840
39- while (!m_pWindowDesc ->InputStruct .empty ()) {
40- AbInputStruct& is = m_pWindowDesc ->InputStruct .front ();
41- m_pWindowDesc ->InputStruct .pop ();
41+ while (!this -> GetWindowDesc () ->InputStruct .empty ()) {
42+ AbInputStruct& is = this -> GetWindowDesc () ->InputStruct .front ();
43+ this -> GetWindowDesc () ->InputStruct .pop ();
4244
4345 switch (is.Event ) {
4446 case EAbInputEvents::AbKeyPress: {
@@ -85,7 +87,7 @@ void UserInput::Update()
8587 }
8688
8789 // Consume the input event
88- m_pWindowDesc ->LastEvent &= ~EAbWindowEvents::Input;
90+ this -> GetWindowDesc () ->LastEvent &= ~EAbWindowEvents::Input;
8991 }
9092}
9193
@@ -99,57 +101,61 @@ void UserInput::Bind(void* pThis, ControllerObject* pCo, AbAction action, AbMous
99101
100102 if (bind.Type & EAbBindType::Keyboard)
101103 {
102- if (bind.keyboard .KeyCode <= AB_INVALID_KEY || bind.keyboard .KeyCode >= AB_KEY_COUNT ) {
104+ if (bind.Keyboard .KeyCode <= AB_INVALID_KEY || bind.Keyboard .KeyCode >= AB_KEY_COUNT ) {
103105 AB_LOG (Debug::Error, L" Key code is an invalid code (code outside of boundries for keys)." );
104106 AB_LOG (Debug::Error, L" Can't bind the action for the keyboard." );
105107 AB_LOG (Debug::Error, L" Action wasn't bound." );
106108 return ;
107109 }
108110
109- if (bind.keyboard .KeyState & EAbOnKeyState ::Press) {
111+ if (bind.Keyboard .KeyState & EAbOnState ::Press) {
110112 m_KeyPressMap.BindAction (bind, pThis, action, nullptr );
111113 }
112- else if (bind.keyboard .KeyState & EAbOnKeyState ::Release) {
114+ else if (bind.Keyboard .KeyState & EAbOnState ::Release) {
113115 m_KeyReleaseMap.BindAction (bind, pThis, action, nullptr );
114116 }
115- else if (bind.keyboard .KeyState & EAbOnKeyState ::Continuous) {
117+ else if (bind.Keyboard .KeyState & EAbOnState ::Continuous) {
116118 m_KeyContinuous.BindAction (bind, pThis, action, nullptr );
117119 }
118-
119- m_BindsHandles[pThis].push_back (bind);
120120 }
121121 else if (bind.Type & EAbBindType::Mouse) {
122122 m_MouseMap.BindAction (bind, pThis, nullptr , mouseAction);
123123 }
124+
125+ m_BindsHandles[pCo].push_back ({ bind, pThis });
126+ AB_LOG (Core::Debug::Info, L" New bind for %p, type %d" , pCo, bind.Type );
124127}
125128
126129// ---------------------------------------------------------------------------------------------------------------------
127- void UserInput::Unbind (void * pThis )
130+ void UserInput::Unbind (ControllerObject* pCo )
128131{
129- const auto & handle = m_BindsHandles.find (pThis );
132+ const auto & handle = m_BindsHandles.find (pCo );
130133
131134 if (handle == m_BindsHandles.end ()) {
132- AB_LOG (Debug::Warning, L" Cannot unbind this bind from this UserInput, because UserInput doesn't handles it." );
135+ AB_LOG (Debug::Warning, L" Cannot unbind this bind from this UserInput, because UserInput doesn't handles it. "
136+ " %p" , pCo);
133137 return ;
134138 }
139+ AB_LOG (Core::Debug::Info, L" Unbind for %p" , pCo);
135140
136- for (const auto & inputBind : handle->second ) {
141+ for (const auto & bindHandle : handle->second ) {
142+ auto & inputBind = bindHandle.Ib ;
137143
138144 if (inputBind.Type & EAbBindType::Keyboard)
139145 {
140- if (inputBind.keyboard .KeyState & EAbOnKeyState ::Press) {
141- m_KeyPressMap.UnbindAction (inputBind, pThis);
146+ if (inputBind.Keyboard .KeyState & EAbOnState ::Press) {
147+ m_KeyPressMap.UnbindAction (inputBind, bindHandle. pThis );
142148 }
143- else if (inputBind.keyboard .KeyState & EAbOnKeyState ::Release) {
144- m_KeyReleaseMap.UnbindAction (inputBind, pThis);
149+ else if (inputBind.Keyboard .KeyState & EAbOnState ::Release) {
150+ m_KeyReleaseMap.UnbindAction (inputBind, bindHandle. pThis );
145151 }
146- else if (inputBind.keyboard .KeyState & EAbOnKeyState ::Continuous) {
147- m_KeyContinuous.UnbindAction (inputBind, pThis);
152+ else if (inputBind.Keyboard .KeyState & EAbOnState ::Continuous) {
153+ m_KeyContinuous.UnbindAction (inputBind, bindHandle. pThis );
148154 }
149155 }
150156 else if (inputBind.Type & EAbBindType::Mouse)
151157 {
152- m_MouseMap.UnbindAction (inputBind, pThis);
158+ m_MouseMap.UnbindAction (inputBind, bindHandle. pThis );
153159 }
154160 }
155161
0 commit comments