|
@@ -6,11 +6,30 @@ namespace oxygine
|
|
|
{
|
|
{
|
|
|
namespace key
|
|
namespace key
|
|
|
{
|
|
{
|
|
|
|
|
+ int _counter = 0;
|
|
|
|
|
+
|
|
|
const int KEYS = 256;
|
|
const int KEYS = 256;
|
|
|
unsigned char _keys[KEYS];
|
|
unsigned char _keys[KEYS];
|
|
|
|
|
|
|
|
|
|
+ void init()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!_counter)
|
|
|
|
|
+ memset(_keys, 0, sizeof(_keys));
|
|
|
|
|
+
|
|
|
|
|
+ _counter++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void release()
|
|
|
|
|
+ {
|
|
|
|
|
+ _counter--;
|
|
|
|
|
+ OX_ASSERT(_counter >= 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void update()
|
|
void update()
|
|
|
{
|
|
{
|
|
|
|
|
+ if (!_counter)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
int num = 0;
|
|
int num = 0;
|
|
|
const Uint8* data = SDL_GetKeyboardState(&num);
|
|
const Uint8* data = SDL_GetKeyboardState(&num);
|
|
|
num = std::min(num, KEYS);
|
|
num = std::min(num, KEYS);
|
|
@@ -20,12 +39,14 @@ namespace oxygine
|
|
|
|
|
|
|
|
bool wasPressed(keycode k)
|
|
bool wasPressed(keycode k)
|
|
|
{
|
|
{
|
|
|
|
|
+ OX_ASSERT(_counter);
|
|
|
const Uint8* data = SDL_GetKeyboardState(0);
|
|
const Uint8* data = SDL_GetKeyboardState(0);
|
|
|
return data[k] && !_keys[k];
|
|
return data[k] && !_keys[k];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool wasReleased(keycode key)
|
|
bool wasReleased(keycode key)
|
|
|
{
|
|
{
|
|
|
|
|
+ OX_ASSERT(_counter);
|
|
|
const Uint8* data = SDL_GetKeyboardState(0);
|
|
const Uint8* data = SDL_GetKeyboardState(0);
|
|
|
return !data[key] && _keys[key];
|
|
return !data[key] && _keys[key];
|
|
|
}
|
|
}
|