From 19cacf248d86c63eabf6f9ffe7f5fb08ceca49cb Mon Sep 17 00:00:00 2001 From: Benjamin Kyd Date: Thu, 19 May 2022 22:37:21 +0100 Subject: [PATCH] fixed a lot of issues with keyboard polling --- Aeon/Aeon.cpp | 4 +--- Aeon/Core/Events.hpp | 6 +++--- Aeon/Input/Input.cpp | 30 ++++++++++++++++-------------- Aeon/Input/Input.hpp | 1 + Game/ExampleGame.cpp | 9 ++++----- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Aeon/Aeon.cpp b/Aeon/Aeon.cpp index 62da020..e2fc6d1 100644 --- a/Aeon/Aeon.cpp +++ b/Aeon/Aeon.cpp @@ -24,7 +24,7 @@ void App::Run() { while ( !mSIGTERM ) { - // Should do this ONLY on update + // Should do this ONLY on update (but needs to be on main thread) mInput.PollInput(); // tick through game layers @@ -69,8 +69,6 @@ const Display& App::GetDisplay() void App::PushLayer( GameLayer* layer ) { - - mGameLayers.push_back( layer ); } diff --git a/Aeon/Core/Events.hpp b/Aeon/Core/Events.hpp index a222172..fbb5187 100644 --- a/Aeon/Core/Events.hpp +++ b/Aeon/Core/Events.hpp @@ -52,9 +52,9 @@ namespace Aeon::Core { * MOUSE_SCROLL - y+- * MOUSE_MOVE - move to x, y relative dx, dy * ENGINE_INPUT_KEYBOARD -* KEYBOARD_KEYDOWN - keycode -* KEYBOARD_KEYUP - keycode -* KEYBOARD_KEYPRESS - keycode for continual pressing +* KEYBOARD_KEYDOWN - keycode, keymod +* KEYBOARD_KEYUP - keycode, keymod +* KEYBOARD_KEYPRESS - keycode for continual pressing, keymod */ diff --git a/Aeon/Input/Input.cpp b/Aeon/Input/Input.cpp index d0725a9..af08238 100644 --- a/Aeon/Input/Input.cpp +++ b/Aeon/Input/Input.cpp @@ -232,24 +232,26 @@ void Input::mPollKeyboard() uint16_t mods = mEvent.key.keysym.mod; e.keyMods = mods; + mModKeyState = mods; + mKeyboardEventDispatcher.Dispatch( e ); } void Input::mPollScanKeyboard() { - // this is naive, can be optimised with double buffering - // for ( int i = 0; i < mNumScancodes; i++ ) - // { - // bool isKeyPressed = (bool)mKbdState[i]; - // if ( isKeyPressed ) - // { - // EKeyCode whatKeyPressed = KeyCodeFromScanCode( (SDL_Scancode)i ); + //this is naive, can be optimised with double buffering + for ( int i = 0; i < mNumScancodes; i++ ) + { + bool isKeyPressed = (bool)mKbdState[i]; + if ( isKeyPressed ) + { + EKeyCode whatKeyPressed = KeyCodeFromScanCode( (SDL_Scancode)i ); - // Aeon::Core::GenericEvent e; - // e.keyCode = whatKeyPressed; - // e.Type = "KEYBOARD_KEYPRESS"; - - // mKeyboardEventDispatcher.Dispatch( e ); - // } - // } + Aeon::Core::GenericEvent e; + e.keyCode = whatKeyPressed; + e.keyMods = mModKeyState; + e.Type = "KEYBOARD_KEYPRESS"; + mKeyboardEventDispatcher.Dispatch( e ); + } + } } diff --git a/Aeon/Input/Input.hpp b/Aeon/Input/Input.hpp index 8ffd96b..35f24ca 100644 --- a/Aeon/Input/Input.hpp +++ b/Aeon/Input/Input.hpp @@ -31,6 +31,7 @@ private: int mNumScancodes = 242; const uint8_t* mKbdState; + uint16_t mModKeyState = 0x0; Aeon::Core::EventDispatcher mDisplayEventDispatcher; Aeon::Core::EventDispatcher mKeyboardEventDispatcher; diff --git a/Game/ExampleGame.cpp b/Game/ExampleGame.cpp index c64ebaf..f51222e 100644 --- a/Game/ExampleGame.cpp +++ b/Game/ExampleGame.cpp @@ -1,6 +1,3 @@ -// simple raycast shooter -// shotgun fun fun yanno - #include #include @@ -37,6 +34,10 @@ public: { std::cout << "FROM LEVEL " << e.Type << " " << (char)e.keyCode << std::endl; + if ( e.keyMods & Aeon::Input::EModCode::SHIFT ) { + std::cout << "Shift" << std::endl; + } + return false; } @@ -49,8 +50,6 @@ public: class ExampleGame : public Aeon::Core::App { public: - - // take command line args better (parse them first!) ExampleGame() : App( { "Example" }, { "Game with AEON!" } ) {