Only update emulator status from within update_movie_state()
This commit is contained in:
parent
b0503ad245
commit
b367334238
5 changed files with 74 additions and 22 deletions
|
@ -167,9 +167,17 @@ struct lsnes_memorywatch_set
|
|||
* Parameter rq: The render queue to use.
|
||||
*/
|
||||
void watch(struct framebuffer::queue& rq);
|
||||
/**
|
||||
* Get memory watch vars that go to window.
|
||||
*/
|
||||
const std::map<std::string, std::u32string>& get_window_vars() { return window_vars; }
|
||||
private:
|
||||
void rebuild(std::map<std::string, lsnes_memorywatch_item>& nitems);
|
||||
std::map<std::string, lsnes_memorywatch_item> items;
|
||||
std::map<std::string, std::u32string> window_vars;
|
||||
std::map<std::string, bool> used_memorywatches;
|
||||
void erase_unused_watches();
|
||||
void memorywatch_output(const std::string& name, const std::string& value);
|
||||
memorywatch_set watch_set;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef _lua__hpp__included__
|
||||
#define _lua__hpp__included__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "core/controllerframe.hpp"
|
||||
#include "library/movie.hpp"
|
||||
#include "library/framebuffer.hpp"
|
||||
|
@ -35,10 +37,12 @@ void lua_callback_do_latch(std::list<std::string>& args);
|
|||
void lua_run_startup_scripts();
|
||||
void lua_add_startup_script(const std::string& file);
|
||||
|
||||
|
||||
#define LUA_TIMED_HOOK_IDLE 0
|
||||
#define LUA_TIMED_HOOK_TIMER 1
|
||||
|
||||
uint64_t lua_timed_hook(int timer) throw();
|
||||
const std::map<std::string, std::u32string>& get_lua_watch_vars();
|
||||
|
||||
extern bool lua_requests_repaint;
|
||||
extern bool lua_requests_subframe_paint;
|
||||
|
|
|
@ -426,6 +426,29 @@ void update_movie_state()
|
|||
}
|
||||
_status.set((stringfmt() << "P" << (i + 1)).str(), _buffer);
|
||||
}
|
||||
//Lua variables.
|
||||
{
|
||||
static std::map<std::string, std::u32string> old_luavars;
|
||||
auto& lvars = get_lua_watch_vars();
|
||||
for(auto i : old_luavars)
|
||||
if(!lvars.count(i.first))
|
||||
_status.erase("L[" + i.first + "]");
|
||||
for(auto i : lvars)
|
||||
_status.set("L[" + i.first + "]", i.second);
|
||||
old_luavars = lvars;
|
||||
}
|
||||
//Memory watches.
|
||||
{
|
||||
static std::map<std::string, std::u32string> old_memvars;
|
||||
auto& mvars = lsnes_memorywatch.get_window_vars();
|
||||
for(auto i : old_memvars)
|
||||
if(!mvars.count(i.first))
|
||||
_status.erase("M[" + i.first + "]");
|
||||
for(auto i : mvars)
|
||||
_status.set("M[" + i.first + "]", i.second);
|
||||
old_memvars = mvars;
|
||||
}
|
||||
|
||||
notify_status_update();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
namespace
|
||||
{
|
||||
std::map<std::string, std::pair<framebuffer::font2*, size_t>> fonts_in_use;
|
||||
std::map<std::string, std::u32string> memorywatch_vars;
|
||||
|
||||
framebuffer::font2& get_builtin_font2()
|
||||
{
|
||||
|
@ -72,24 +73,6 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
std::map<std::string, bool> used_memorywatches;
|
||||
void memorywatch_output_fn(const std::string& name, const std::string& value)
|
||||
{
|
||||
auto& status = platform::get_emustatus();
|
||||
used_memorywatches[name] = true;
|
||||
status.set("M[" + name + "]", value);
|
||||
}
|
||||
|
||||
void erase_unused_watches()
|
||||
{
|
||||
auto& status = platform::get_emustatus();
|
||||
for(auto& i : used_memorywatches) {
|
||||
if(!i.second)
|
||||
status.erase("M[" + i.first + "]");
|
||||
i.second = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string json_string_default(const JSON::node& node, const std::string& pointer, const std::string& dflt)
|
||||
{
|
||||
return (node.type_of(pointer) == JSON::string) ? node[pointer].as_string8() : dflt;
|
||||
|
@ -109,6 +92,8 @@ namespace
|
|||
{
|
||||
return (node.type_of(pointer) == JSON::boolean) ? node[pointer].as_bool() : dflt;
|
||||
}
|
||||
|
||||
void dummy_target_fn(const std::string& n, const std::string& v) {}
|
||||
}
|
||||
|
||||
lsnes_memorywatch_printer::lsnes_memorywatch_printer()
|
||||
|
@ -193,7 +178,7 @@ gcroot_pointer<memorywatch_item_printer> lsnes_memorywatch_printer::get_printer_
|
|||
} catch(std::exception& e) {
|
||||
(stringfmt() << "Error while parsing conditional: " << e.what()).throwex();
|
||||
}
|
||||
l->set_output(memorywatch_output_fn);
|
||||
l->set_output(dummy_target_fn);
|
||||
break;
|
||||
case PC_ONSCREEN:
|
||||
ptr = gcroot_pointer<memorywatch_item_printer>(new memorywatch_output_fb);
|
||||
|
@ -530,6 +515,14 @@ void lsnes_memorywatch_set::rebuild(std::map<std::string, lsnes_memorywatch_item
|
|||
memread_oper = NULL;
|
||||
}
|
||||
rt_printer = i.second.printer.get_printer_obj(vars_fn);
|
||||
|
||||
//Set final callback for list objects (since it wasn't known on creation).
|
||||
auto list_obj = dynamic_cast<memorywatch_output_list*>(rt_printer.as_pointer());
|
||||
if(list_obj)
|
||||
list_obj->set_output([this](const std::string& n, const std::string& v) {
|
||||
this->memorywatch_output(n, v);
|
||||
});
|
||||
|
||||
memorywatch_item it(*expression_value());
|
||||
*vars_fn(i.first) = *rt_expr;
|
||||
it.expr = vars_fn(i.first);
|
||||
|
@ -546,4 +539,19 @@ void lsnes_memorywatch_set::rebuild(std::map<std::string, lsnes_memorywatch_item
|
|||
garbage_collectable::do_gc();
|
||||
}
|
||||
|
||||
void lsnes_memorywatch_set::memorywatch_output(const std::string& name, const std::string& value)
|
||||
{
|
||||
used_memorywatches[name] = true;
|
||||
window_vars[name] = utf8::to32(value);
|
||||
}
|
||||
|
||||
void lsnes_memorywatch_set::erase_unused_watches()
|
||||
{
|
||||
for(auto& i : used_memorywatches) {
|
||||
if(!i.second)
|
||||
window_vars.erase(i.first);
|
||||
i.second = false;
|
||||
}
|
||||
}
|
||||
|
||||
lsnes_memorywatch_set lsnes_memorywatch;
|
||||
|
|
|
@ -2,8 +2,12 @@
|
|||
#include "core/window.hpp"
|
||||
#include "library/minmax.hpp"
|
||||
|
||||
void update_movie_state();
|
||||
|
||||
namespace
|
||||
{
|
||||
std::map<std::string, std::u32string> lua_watch_vars;
|
||||
|
||||
template<uint32_t lua_render_context::*gap, bool delta>
|
||||
int lua_gui_set_gap(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
|
@ -70,11 +74,11 @@ namespace
|
|||
|
||||
P(name, value);
|
||||
|
||||
auto& w = platform::get_emustatus();
|
||||
if(value == "")
|
||||
w.erase("L[" + name + "]");
|
||||
lua_watch_vars.erase(name);
|
||||
else
|
||||
w.set("L[" + name + "]", value);
|
||||
lua_watch_vars[name] = utf8::to32(value);
|
||||
update_movie_state();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -130,3 +134,8 @@ namespace
|
|||
{"set_video_scale", set_video_scale},
|
||||
});
|
||||
}
|
||||
|
||||
const std::map<std::string, std::u32string>& get_lua_watch_vars()
|
||||
{
|
||||
return lua_watch_vars;
|
||||
}
|
Loading…
Add table
Reference in a new issue