Small cleanup: move up some lsnes_instance stuff

This commit is contained in:
Ilari Liusvaara 2016-04-16 10:51:02 +03:00
parent 40ac5d56e3
commit 7903ba1fda
5 changed files with 24 additions and 23 deletions

View file

@ -19,8 +19,10 @@ namespace keyboard { class key; }
#define LUA_TIMED_HOOK_IDLE 0
#define LUA_TIMED_HOOK_TIMER 1
void init_lua() throw();
void quit_lua() throw();
class emulator_instance;
void init_lua(emulator_instance& inst) throw();
void quit_lua(emulator_instance& inst) throw();
struct lua_state
{

View file

@ -195,14 +195,14 @@ dumper_information UI_get_dumpers(emulator_instance& inst)
void UI_start_dump(emulator_instance& inst, dumper_factory_base& factory, const std::string& mode,
const std::string& prefix)
{
lsnes_instance.iqueue->run([&inst, &factory, mode, prefix]() {
inst.iqueue->run([&inst, &factory, mode, prefix]() {
inst.mdumper->start(factory, mode, prefix);
});
}
void UI_end_dump(emulator_instance& inst, dumper_factory_base& factory)
{
lsnes_instance.iqueue->run([&inst, &factory]() {
inst.iqueue->run([&inst, &factory]() {
auto in = inst.mdumper->get_instance(&factory);
delete in;
});
@ -220,7 +220,7 @@ void UI_do_keypress(emulator_instance& inst, const keyboard::modifier_set& mods,
bool UI_has_movie(emulator_instance& inst)
{
bool ret = false;
lsnes_instance.iqueue->run([&inst, &ret]() {
inst.iqueue->run([&inst, &ret]() {
ret = !!*inst.mlogic && !inst.rom->isnull();
});
return ret;
@ -228,7 +228,7 @@ bool UI_has_movie(emulator_instance& inst)
void UI_save_movie(emulator_instance& inst, std::ostringstream& stream)
{
lsnes_instance.iqueue->run([&inst, &stream]() {
inst.iqueue->run([&inst, &stream]() {
auto prj = inst.project->get();
if(prj) {
inst.mlogic->get_mfile().gamename = prj->gamename;
@ -243,7 +243,7 @@ std::pair<std::string, std::string> UI_lookup_platform_and_game(emulator_instanc
{
std::string plat;
std::string game;
lsnes_instance.iqueue->run([&inst, &plat, &game]() {
inst.iqueue->run([&inst, &plat, &game]() {
auto prj = inst.project->get();
if(prj)
game = prj->gamename;
@ -257,7 +257,7 @@ std::pair<std::string, std::string> UI_lookup_platform_and_game(emulator_instanc
std::string UI_get_project_otherpath(emulator_instance& inst)
{
std::string path;
lsnes_instance.iqueue->run([&inst, &path]() {
inst.iqueue->run([&inst, &path]() {
path = inst.project->otherpath();
});
return path;
@ -266,7 +266,7 @@ std::string UI_get_project_otherpath(emulator_instance& inst)
std::string UI_get_project_moviepath(emulator_instance& inst)
{
std::string path;
lsnes_instance.iqueue->run([&inst, &path]() {
inst.iqueue->run([&inst, &path]() {
path = inst.project->moviepath();
});
return path;
@ -275,7 +275,7 @@ std::string UI_get_project_moviepath(emulator_instance& inst)
bool UI_in_project_context(emulator_instance& inst)
{
bool pc;
lsnes_instance.iqueue->run([&inst, &pc]() {
inst.iqueue->run([&inst, &pc]() {
pc = (inst.project->get() != NULL);
});
return pc;

View file

@ -404,9 +404,8 @@ void lua_state::callback_keyhook(const std::string& key, keyboard::key& p) throw
run_callback(*on_keyhook, lua::state::string_tag(key), lua::state::fnptr_tag(push_keygroup_parameters2, &p));
}
void init_lua() throw()
void init_lua(emulator_instance& core) throw()
{
auto& core = lsnes_instance;
core.lua->set_oom_handler(OOM_panic);
core.lua->set_soft_oom_handler(soft_oom);
try {
@ -431,9 +430,9 @@ void init_lua() throw()
copy_system_tables(*core.lua);
}
void quit_lua() throw()
void quit_lua(emulator_instance& core) throw()
{
lsnes_instance.lua->deinit();
core.lua->deinit();
}

View file

@ -598,7 +598,7 @@ bool lsnes_app::OnInit()
save_configuration();
return false;
}
init_lua();
init_lua(lsnes_instance);
lsnes_instance.mdumper->set_output(&messages.getstream());
msg_window = new wxwin_messages(lsnes_instance);
@ -626,7 +626,7 @@ bool lsnes_app::OnInit()
std::cerr << "Can't load ROM: " << e.what() << std::endl;
show_message_ok(NULL, "Error loading ROM", std::string("Error loading ROM:\n\n") +
e.what(), wxICON_EXCLAMATION);
quit_lua(); //Don't crash.
quit_lua(lsnes_instance); //Don't crash.
return false;
}
@ -639,7 +639,7 @@ bool lsnes_app::OnInit()
std::cerr << "Can't load state: " << e.what() << std::endl;
show_message_ok(NULL, "Error loading movie", std::string("Error loading movie:\n\n") +
e.what(), wxICON_EXCLAMATION);
quit_lua(); //Don't crash.
quit_lua(lsnes_instance); //Don't crash.
return false;
}
else {
@ -665,7 +665,7 @@ int lsnes_app::OnExit()
if(x)
x->Destroy();
save_configuration();
quit_lua();
quit_lua(lsnes_instance);
lsnes_instance.mlogic->release_memory();
platform::quit();
lsnes_instance.buttons->cleanup();

View file

@ -336,7 +336,7 @@ int main(int argc, char** argv)
set_random_seed();
platform::init();
init_lua();
init_lua(lsnes_instance);
lsnes_instance.mdumper->set_output(&messages.getstream());
set_hasher_callback(hash_callback);
@ -387,7 +387,7 @@ int main(int argc, char** argv)
movfn = do_download_movie(movfn);
} catch(std::exception& e) {
messages << "FATAL: Can't download movie: " << e.what() << std::endl;
quit_lua();
quit_lua(lsnes_instance);
fatal_error();
exit(1);
}
@ -404,7 +404,7 @@ int main(int argc, char** argv)
OOM_panic();
} catch(std::exception& e) {
messages << "FATAL: Can't load ROM: " << e.what() << std::endl;
quit_lua();
quit_lua(lsnes_instance);
fatal_error();
exit(1);
}
@ -430,11 +430,11 @@ int main(int argc, char** argv)
OOM_panic();
} catch(std::exception& e) {
messages << "FATAL: " << e.what() << std::endl;
quit_lua();
quit_lua(lsnes_instance);
fatal_error();
return 1;
}
quit_lua();
quit_lua(lsnes_instance);
lsnes_instance.mlogic->release_memory();
lsnes_instance.buttons->cleanup();
return 0;