Cleanup controller and keymapper stuff on exit

This commit is contained in:
Ilari Liusvaara 2013-08-07 22:06:38 +03:00
parent 11b83ef0ff
commit 3b1383232e
6 changed files with 30 additions and 0 deletions

View file

@ -10,6 +10,7 @@ void reread_active_buttons();
void reinitialize_buttonmap();
void load_macros(controller_state& ctrlstate);
void load_project_macros(controller_state& ctrlstate, project_info& pinfo);
void cleanup_all_keys();
extern controller_state controls;
extern std::map<std::string, std::string> button_keys;

View file

@ -34,5 +34,9 @@ void lsnes_gamepads_init();
* Deinitialize gamepads (need to be called after deinitializing joysticks).
*/
void lsnes_gamepads_deinit();
/**
* Cleanup the keymapper stuff.
*/
void cleanup_keymapper();
#endif

View file

@ -64,11 +64,18 @@ namespace
std::map<std::string, inverse_bind*> macro_binds2;
std::map<std::string, controller_bind> all_buttons;
std::map<std::string, active_bind> active_buttons;
std::map<std::string, controller_key*> added_keys;
//Promote stored key to active key.
void promote_key(controller_key& k)
{
std::string name = k.get_command();
if(added_keys.count(name)) {
//Already exists.
delete &k;
return;
}
added_keys[name] = &k;
if(!button_keys.count(name))
return;
k.append(button_keys[name]);
@ -597,5 +604,11 @@ void load_project_macros(controller_state& ctrlstate, project_info& pinfo)
load_macros(ctrlstate);
}
void cleanup_all_keys()
{
for(auto i : added_keys)
delete i.second;
}
controller_state controls;
std::map<std::string, std::string> button_keys;

View file

@ -83,6 +83,13 @@ void lsnes_gamepads_deinit()
cfg << lsnes_gamepads.save().serialize() << std::endl;
}
void cleanup_keymapper()
{
for(auto i : buttons) delete i.second;
for(auto i : axes) delete i.second;
for(auto i : hats) delete i.second;
}
namespace
{
function_ptr_command<> show_joysticks(lsnes_cmd, "show-joysticks", "Show joystick info",

View file

@ -7,6 +7,7 @@
#include "core/dispatch.hpp"
#include "core/framerate.hpp"
#include "core/joystickapi.hpp"
#include "core/keymapper.hpp"
#include "core/loadlib.hpp"
#include "lua/lua.hpp"
#include "core/mainloop.hpp"
@ -510,6 +511,8 @@ int lsnes_app::OnExit()
joystick_driver_signal();
joystick_thread_handle->join();
platform::quit();
cleanup_all_keys();
cleanup_keymapper();
return 0;
}

View file

@ -1,6 +1,7 @@
#include "lsnes.hpp"
#include "core/advdumper.hpp"
#include "core/controller.hpp"
#include "core/command.hpp"
#include "core/dispatch.hpp"
#include "core/mainloop.hpp"
@ -335,5 +336,6 @@ int main(int argc, char** argv)
information_dispatch::do_dump_end();
rrdata::close();
quit_lua();
cleanup_all_keys();
return 0;
}