mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Updated the love key to SDL keycode mapping to be a static array instead of a std::map.
This commit is contained in:
@@ -241,7 +241,7 @@ public:
|
||||
KEY_EJECT,
|
||||
KEY_SLEEP,
|
||||
|
||||
KEY_MAX_ENUM = 512
|
||||
KEY_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Keyboard() {}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "common/config.h"
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
namespace love
|
||||
@@ -55,8 +53,8 @@ bool Keyboard::isDown(Key *keylist) const
|
||||
|
||||
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
||||
{
|
||||
auto it = keys.find(key);
|
||||
if (it != keys.end() && keystate[SDL_GetScancodeFromKey(it->second)])
|
||||
SDL_Scancode scancode = SDL_GetScancodeFromKey(keymap[key]);
|
||||
if (keystate[scancode])
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,9 +74,10 @@ bool Keyboard::hasTextInput() const
|
||||
return SDL_IsTextInputActive();
|
||||
}
|
||||
|
||||
std::map<Keyboard::Key, SDL_Keycode> Keyboard::createKeyMap()
|
||||
const SDL_Keycode *Keyboard::createKeyMap()
|
||||
{
|
||||
std::map<Keyboard::Key, SDL_Keycode> k;
|
||||
// Array must be static so its lifetime continues once the function returns.
|
||||
static SDL_Keycode k[Keyboard::KEY_MAX_ENUM] = {SDLK_UNKNOWN};
|
||||
|
||||
k[Keyboard::KEY_UNKNOWN] = SDLK_UNKNOWN;
|
||||
|
||||
@@ -287,7 +286,7 @@ std::map<Keyboard::Key, SDL_Keycode> Keyboard::createKeyMap()
|
||||
return k;
|
||||
}
|
||||
|
||||
std::map<Keyboard::Key, SDL_Keycode> Keyboard::keys = Keyboard::createKeyMap();
|
||||
const SDL_Keycode *Keyboard::keymap = Keyboard::createKeyMap();
|
||||
|
||||
} // sdl
|
||||
} // keyboard
|
||||
|
||||
@@ -26,10 +26,7 @@
|
||||
#include "common/EnumMap.h"
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
// STL
|
||||
#include <map>
|
||||
#include <SDL_keyboard.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -60,8 +57,8 @@ private:
|
||||
// The real implementation is in love::event::sdl::Event::Convert.
|
||||
bool key_repeat;
|
||||
|
||||
static std::map<Key, SDL_Keycode> createKeyMap();
|
||||
static std::map<Key, SDL_Keycode> keys;
|
||||
static const SDL_Keycode *createKeyMap();
|
||||
static const SDL_Keycode *keymap;
|
||||
|
||||
}; // Keyboard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user