fixed a lot of issues with keyboard polling

This commit is contained in:
Benjamin Kyd
2022-05-19 22:37:21 +01:00
parent 7e635a031c
commit 19cacf248d
5 changed files with 25 additions and 25 deletions

View File

@@ -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 );
}

View File

@@ -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
*/

View File

@@ -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 );
}
}
}

View File

@@ -31,6 +31,7 @@ private:
int mNumScancodes = 242;
const uint8_t* mKbdState;
uint16_t mModKeyState = 0x0;
Aeon::Core::EventDispatcher mDisplayEventDispatcher;
Aeon::Core::EventDispatcher mKeyboardEventDispatcher;

View File

@@ -1,6 +1,3 @@
// simple raycast shooter
// shotgun fun fun yanno
#include <iostream>
#include <Aeon/Aeon.hpp>
@@ -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!" } )
{