From: Ingo Ruhnke Date: Wed, 6 Aug 2014 19:07:48 +0000 (+0200) Subject: Keycode values changed between SDL1 and SDL2, so reset controls to default if old... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6ff2ba5014199fea40820924c94c4939b90c7230;p=supertux.git Keycode values changed between SDL1 and SDL2, so reset controls to default if old SDL1 values are found --- diff --git a/src/control/keyboard_manager.cpp b/src/control/keyboard_manager.cpp index 929e10617..15f498e14 100644 --- a/src/control/keyboard_manager.cpp +++ b/src/control/keyboard_manager.cpp @@ -258,27 +258,36 @@ KeyboardManager::reversemap_key(Controller::Control c) void KeyboardManager::read(const lisp::Lisp* keymap_lisp) { - keymap.clear(); - keymap_lisp->get("jump-with-up", jump_with_up_kbd); - lisp::ListIterator iter(keymap_lisp); - while(iter.next()) { - if (iter.item() == "map") { - int key = -1; - std::string control; - const lisp::Lisp* map = iter.lisp(); - map->get("key", key); - map->get("control", control); + // keycode values changed between SDL1 and SDL2, so we skip old SDL1 + // based values and use the defaults instead on the first read of + // the config file + bool config_is_sdl2 = false; + keymap_lisp->get("sdl2", config_is_sdl2); + if (config_is_sdl2) + { + keymap.clear(); + keymap_lisp->get("jump-with-up", jump_with_up_kbd); + lisp::ListIterator iter(keymap_lisp); + while(iter.next()) { + if (iter.item() == "map") { + int key = -1; + std::string control; + const lisp::Lisp* map = iter.lisp(); + map->get("key", key); - int i = 0; - for(i = 0; Controller::controlNames[i] != 0; ++i) { - if (control == Controller::controlNames[i]) - break; - } - if (Controller::controlNames[i] == 0) { - log_info << "Invalid control '" << control << "' in keymap" << std::endl; - continue; + map->get("control", control); + + int i = 0; + for(i = 0; Controller::controlNames[i] != 0; ++i) { + if (control == Controller::controlNames[i]) + break; + } + if (Controller::controlNames[i] == 0) { + log_info << "Invalid control '" << control << "' in keymap" << std::endl; + continue; + } + keymap[static_cast(key)] = static_cast(i); } - keymap[static_cast(key)] = static_cast(i); } } } @@ -286,6 +295,7 @@ KeyboardManager::read(const lisp::Lisp* keymap_lisp) void KeyboardManager::write(Writer& writer) { + writer.write("sdl2", true); writer.write("jump-with-up", jump_with_up_kbd); for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) { writer.start_list("map");