keyboard ennit
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#include "Aeon/Input/Input.hpp"
|
#include "Aeon/Input/Input.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "Aeon/Core/Events.hpp"
|
#include "Aeon/Core/Events.hpp"
|
||||||
|
|
||||||
@@ -15,6 +17,10 @@ Input::Input()
|
|||||||
mDisplayEventDispatcher.RegisterAsSource( "ENGINE_DISPLAY_CORE" );
|
mDisplayEventDispatcher.RegisterAsSource( "ENGINE_DISPLAY_CORE" );
|
||||||
mMouseEventDispatcher.RegisterAsSource( "ENGINE_INPUT_MOUSE" );
|
mMouseEventDispatcher.RegisterAsSource( "ENGINE_INPUT_MOUSE" );
|
||||||
mKeyboardEventDispatcher.RegisterAsSource( "ENGINE_INPUT_KEYBOARD" );
|
mKeyboardEventDispatcher.RegisterAsSource( "ENGINE_INPUT_KEYBOARD" );
|
||||||
|
|
||||||
|
mKbdState = static_cast<const uint8_t*>(SDL_GetKeyboardState( &numScancodes ));
|
||||||
|
mOldKbdState = static_cast<uint8_t*>(malloc( numScancodes / sizeof( uint8_t ) ));
|
||||||
|
memcpy( mOldKbdState, mKbdState, 242 / sizeof( uint8_t ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::~Input()
|
Input::~Input()
|
||||||
@@ -22,10 +28,13 @@ Input::~Input()
|
|||||||
mDisplayEventDispatcher.DeRegisterAsSource( "ENGINE_DISPLAY_CORE" );
|
mDisplayEventDispatcher.DeRegisterAsSource( "ENGINE_DISPLAY_CORE" );
|
||||||
mMouseEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_MOUSE" );
|
mMouseEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_MOUSE" );
|
||||||
mKeyboardEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_KEYBOARD" );
|
mKeyboardEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_KEYBOARD" );
|
||||||
|
|
||||||
|
free( mOldKbdState );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::PollInput()
|
void Input::PollInput()
|
||||||
{
|
{
|
||||||
|
SDL_PumpEvents();
|
||||||
while ( SDL_PollEvent( &mEvent ) )
|
while ( SDL_PollEvent( &mEvent ) )
|
||||||
{
|
{
|
||||||
switch ( mEvent.type )
|
switch ( mEvent.type )
|
||||||
@@ -54,9 +63,22 @@ void Input::PollInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Uint8* state = (Uint8*)SDL_GetKeyboardState( NULL );
|
// just in case
|
||||||
//std::cout << state << std::endl;
|
mKbdState = static_cast<const uint8_t*>(SDL_GetKeyboardState( &numScancodes ));
|
||||||
//std::cout << std::endl;
|
|
||||||
|
// keyboard processing
|
||||||
|
|
||||||
|
// first we want to check if any key has changed
|
||||||
|
// if a key has changed, then we want to check if any keys are pressed
|
||||||
|
// if a key is pressed we want to check the keys and dispatch events
|
||||||
|
// according to the scancode
|
||||||
|
// keydown and keyup will be done seperately
|
||||||
|
if ( !std::equal( mKbdState, mKbdState + numScancodes, mOldKbdState ) )
|
||||||
|
{
|
||||||
|
std::cout << "keyboard ennit" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy( mOldKbdState, mKbdState, numScancodes / sizeof( uint8_t ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::mPollDisplay()
|
void Input::mPollDisplay()
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public:
|
|||||||
~Input();
|
~Input();
|
||||||
|
|
||||||
void PollInput();
|
void PollInput();
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
void mPollDisplay();
|
void mPollDisplay();
|
||||||
void mPollMouse();
|
void mPollMouse();
|
||||||
void mPollScroll();
|
void mPollScroll();
|
||||||
@@ -24,8 +24,10 @@ private:
|
|||||||
void mPollKeyboard();
|
void mPollKeyboard();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SDL_Event mEvent;
|
SDL_Event mEvent;
|
||||||
|
int numScancodes = 242;
|
||||||
|
const uint8_t* mKbdState;
|
||||||
|
uint8_t* mOldKbdState;
|
||||||
|
|
||||||
Aeon::Core::EventDispatcher mDisplayEventDispatcher;
|
Aeon::Core::EventDispatcher mDisplayEventDispatcher;
|
||||||
Aeon::Core::EventDispatcher mKeyboardEventDispatcher;
|
Aeon::Core::EventDispatcher mKeyboardEventDispatcher;
|
||||||
|
|||||||
Reference in New Issue
Block a user