sdl: convert keyboard mapping from keycodes to scancode on first load
This commit is contained in:
parent
967f4570ed
commit
894a0540b9
|
@ -142,6 +142,7 @@ void InputMapping::load(FILE* fp)
|
||||||
int dz = mf.get_int("emulator", "dead_zone", 10);
|
int dz = mf.get_int("emulator", "dead_zone", 10);
|
||||||
dz = std::min(dz, 100);
|
dz = std::min(dz, 100);
|
||||||
dz = std::max(dz, 0);
|
dz = std::max(dz, 0);
|
||||||
|
version = mf.get_int("emulator", "version", 1);
|
||||||
|
|
||||||
this->dead_zone = (float)dz / 100.f;
|
this->dead_zone = (float)dz / 100.f;
|
||||||
|
|
||||||
|
@ -236,6 +237,7 @@ bool InputMapping::save(const char *name)
|
||||||
|
|
||||||
mf.set("emulator", "mapping_name", this->name);
|
mf.set("emulator", "mapping_name", this->name);
|
||||||
mf.set_int("emulator", "dead_zone", (int)std::round(this->dead_zone * 100.f));
|
mf.set_int("emulator", "dead_zone", (int)std::round(this->dead_zone * 100.f));
|
||||||
|
mf.set_int("emulator", "version", version);
|
||||||
|
|
||||||
for (int port = 0; port < 4; port++)
|
for (int port = 0; port < 4; port++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
float dead_zone = 0.1f;
|
float dead_zone = 0.1f;
|
||||||
|
int version = 2;
|
||||||
|
|
||||||
DreamcastKey get_button_id(u32 port, u32 code)
|
DreamcastKey get_button_id(u32 port, u32 code)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,35 @@ class SDLKeyboardDevice : public KeyboardDeviceTemplate<SDL_Scancode>
|
||||||
public:
|
public:
|
||||||
SDLKeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port, "SDL") {
|
SDLKeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port, "SDL") {
|
||||||
_unique_id = "sdl_keyboard";
|
_unique_id = "sdl_keyboard";
|
||||||
loadMapping();
|
if (find_mapping())
|
||||||
|
{
|
||||||
|
if (input_mapper->version == 1)
|
||||||
|
{
|
||||||
|
// Convert keycodes to scancode
|
||||||
|
SDL_Scancode scancodes[4][26] {};
|
||||||
|
for (int i = 0; i < 26; i++)
|
||||||
|
{
|
||||||
|
DreamcastKey key = (DreamcastKey)(1 << i);
|
||||||
|
for (int port = 0; port < 4; port++)
|
||||||
|
{
|
||||||
|
SDL_Keycode keycode = (SDL_Keycode)input_mapper->get_button_code(port, key);
|
||||||
|
if ((int)keycode != -1)
|
||||||
|
scancodes[port][i] = SDL_GetScancodeFromKey(keycode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 26; i++)
|
||||||
|
{
|
||||||
|
DreamcastKey key = (DreamcastKey)(1 << i);
|
||||||
|
for (int port = 0; port < 4; port++)
|
||||||
|
if (scancodes[port][i] != 0)
|
||||||
|
input_mapper->set_button(port, key, (u32)scancodes[port][i]);
|
||||||
|
}
|
||||||
|
input_mapper->version = 2;
|
||||||
|
save_mapping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
input_mapper = getDefaultMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *get_button_name(u32 code) override
|
const char *get_button_name(u32 code) override
|
||||||
|
|
Loading…
Reference in New Issue