|
|
@@ -7,17 +7,19 @@
|
|
|
// ----------------------------------------------------------------
|
|
|
|
|
|
#include "InputSystem.h"
|
|
|
+#include <SDL/SDL.h>
|
|
|
+#include <cstring>
|
|
|
|
|
|
-bool KeyboardState::GetKeyValue(SDL_Scancode code) const
|
|
|
+bool KeyboardState::GetKeyValue(int keyCode) const
|
|
|
{
|
|
|
- return mCurrState[code] == 1;
|
|
|
+ return mCurrState[keyCode] == 1;
|
|
|
}
|
|
|
|
|
|
-ButtonState KeyboardState::GetKeyState(SDL_Scancode code) const
|
|
|
+ButtonState KeyboardState::GetKeyState(int keyCode) const
|
|
|
{
|
|
|
- if (mCurrState[code] == 0)
|
|
|
+ if (mCurrState[keyCode] == 0)
|
|
|
{
|
|
|
- if (mPrevState[code] == 0)
|
|
|
+ if (mPrevState[keyCode] == 0)
|
|
|
{
|
|
|
return ENone;
|
|
|
}
|
|
|
@@ -28,7 +30,7 @@ ButtonState KeyboardState::GetKeyState(SDL_Scancode code) const
|
|
|
}
|
|
|
else // must be 1
|
|
|
{
|
|
|
- if (mPrevState[code] == 0)
|
|
|
+ if (mPrevState[keyCode] == 0)
|
|
|
{
|
|
|
return EPressed;
|
|
|
}
|
|
|
@@ -39,12 +41,14 @@ ButtonState KeyboardState::GetKeyState(SDL_Scancode code) const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-InputSystem::InputSystem()
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
bool InputSystem::Initialize()
|
|
|
{
|
|
|
+ // Assign current state pointer
|
|
|
+ mState.Keyboard.mCurrState = SDL_GetKeyboardState(NULL);
|
|
|
+ // Clear previous state memory
|
|
|
+ memset(mState.Keyboard.mPrevState, 0,
|
|
|
+ SDL_NUM_SCANCODES);
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -54,6 +58,11 @@ void InputSystem::Shutdown()
|
|
|
|
|
|
void InputSystem::PrepareForUpdate()
|
|
|
{
|
|
|
+ // Copy current state to previous
|
|
|
+ // Keyboard
|
|
|
+ memcpy(mState.Keyboard.mPrevState,
|
|
|
+ mState.Keyboard.mCurrState,
|
|
|
+ SDL_NUM_SCANCODES);
|
|
|
}
|
|
|
|
|
|
void InputSystem::Update()
|