mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +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_EJECT,
|
||||||
KEY_SLEEP,
|
KEY_SLEEP,
|
||||||
|
|
||||||
KEY_MAX_ENUM = 512
|
KEY_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Keyboard() {}
|
virtual ~Keyboard() {}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
* 3. This notice may not be removed or altered from any source distribution.
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "common/config.h"
|
|
||||||
|
|
||||||
#include "Keyboard.h"
|
#include "Keyboard.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -55,8 +53,8 @@ bool Keyboard::isDown(Key *keylist) const
|
|||||||
|
|
||||||
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
||||||
{
|
{
|
||||||
auto it = keys.find(key);
|
SDL_Scancode scancode = SDL_GetScancodeFromKey(keymap[key]);
|
||||||
if (it != keys.end() && keystate[SDL_GetScancodeFromKey(it->second)])
|
if (keystate[scancode])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +74,10 @@ bool Keyboard::hasTextInput() const
|
|||||||
return SDL_IsTextInputActive();
|
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;
|
k[Keyboard::KEY_UNKNOWN] = SDLK_UNKNOWN;
|
||||||
|
|
||||||
@@ -287,7 +286,7 @@ std::map<Keyboard::Key, SDL_Keycode> Keyboard::createKeyMap()
|
|||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<Keyboard::Key, SDL_Keycode> Keyboard::keys = Keyboard::createKeyMap();
|
const SDL_Keycode *Keyboard::keymap = Keyboard::createKeyMap();
|
||||||
|
|
||||||
} // sdl
|
} // sdl
|
||||||
} // keyboard
|
} // keyboard
|
||||||
|
|||||||
@@ -26,10 +26,7 @@
|
|||||||
#include "common/EnumMap.h"
|
#include "common/EnumMap.h"
|
||||||
|
|
||||||
// SDL
|
// SDL
|
||||||
#include <SDL.h>
|
#include <SDL_keyboard.h>
|
||||||
|
|
||||||
// STL
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -60,8 +57,8 @@ private:
|
|||||||
// The real implementation is in love::event::sdl::Event::Convert.
|
// The real implementation is in love::event::sdl::Event::Convert.
|
||||||
bool key_repeat;
|
bool key_repeat;
|
||||||
|
|
||||||
static std::map<Key, SDL_Keycode> createKeyMap();
|
static const SDL_Keycode *createKeyMap();
|
||||||
static std::map<Key, SDL_Keycode> keys;
|
static const SDL_Keycode *keymap;
|
||||||
|
|
||||||
}; // Keyboard
|
}; // Keyboard
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user