diff --git a/include/lua/internal.hpp b/include/lua/internal.hpp index eb520e1a..815c5e1f 100644 --- a/include/lua/internal.hpp +++ b/include/lua/internal.hpp @@ -6,6 +6,7 @@ #include #include #include "library/luabase.hpp" +#include "library/lua-framebuffer.hpp" extern lua_state lsnes_lua_state; extern lua_function_group lua_func_bit; @@ -21,4 +22,7 @@ extern bool lua_booted_flag; extern uint64_t lua_idle_hook_time; extern uint64_t lua_timer_hook_time; +extern void* synchronous_paint_ctx; +void lua_renderq_run(lua_render_context* ctx, void* synchronous_paint_ctx); + #endif diff --git a/lua.lyx b/lua.lyx index 3e7e39ea..1c62cf05 100644 --- a/lua.lyx +++ b/lua.lyx @@ -1452,6 +1452,18 @@ Syntax: none gui.repaint() Request on_repaint() to happen as soon as possible. \end_layout +\begin_layout Subsection +gui.synchronous_repaint: Paint screen now +\end_layout + +\begin_layout Itemize +Syntax: none gui.synchronous_repaint(RENDERQUEUE queue) +\end_layout + +\begin_layout Standard +Paints specified render queue on screen right there and then. +\end_layout + \begin_layout Subsection gui.subframe_update: Enable/Disable subframe updates \end_layout diff --git a/lua.pdf b/lua.pdf index 8b9c6f7c..47773ab0 100644 Binary files a/lua.pdf and b/lua.pdf differ diff --git a/src/lua/gui-rqueue.cpp b/src/lua/gui-rqueue.cpp index e19c13cf..fae9e778 100644 --- a/src/lua/gui-rqueue.cpp +++ b/src/lua/gui-rqueue.cpp @@ -1,3 +1,4 @@ +#include "core/framebuffer.hpp" #include "lua/internal.hpp" #include "library/framebuffer.hpp" @@ -50,6 +51,20 @@ namespace return 0; }); + function_ptr_luafun gui_srepaint(lua_func_misc, "gui.synchronous_repaint", [](lua_state& L, + const std::string& fname) -> int { + if(lua_class::is(L, 1)) { + lua_class::get(L, 1, fname.c_str()); + auto q = lua_class::pin(L, 1, fname.c_str()); + synchronous_paint_ctx = q->object(); + redraw_framebuffer(); + } else { + L.pushstring("Expected RENDERCTX as argument 1 for gui.renderq_run."); + L.error(); + } + return 0; + }); + function_ptr_luafun gui_rq_clear(lua_func_misc, "gui.renderq_clear", [](lua_state& L, const std::string& fname) -> int { if(lua_class::is(L, 1)) { @@ -102,3 +117,18 @@ namespace } DECLARE_LUACLASS(render_queue_obj, "RENDERCTX"); + +void lua_renderq_run(lua_render_context* ctx, void* _sctx) +{ + render_queue_obj* sctx = (render_queue_obj*)_sctx; + lua_render_context* ptr = sctx->get(); + if(ptr->top_gap != std::numeric_limits::max()) + ctx->top_gap = ptr->top_gap; + if(ptr->right_gap != std::numeric_limits::max()) + ctx->right_gap = ptr->right_gap; + if(ptr->bottom_gap != std::numeric_limits::max()) + ctx->bottom_gap = ptr->bottom_gap; + if(ptr->left_gap != std::numeric_limits::max()) + ctx->left_gap = ptr->left_gap; + ctx->queue->copy_from(*ptr->queue); +} diff --git a/src/lua/lua.cpp b/src/lua/lua.cpp index 11296ad4..23d72ac3 100644 --- a/src/lua/lua.cpp +++ b/src/lua/lua.cpp @@ -21,6 +21,7 @@ uint64_t lua_timer_hook_time = 0x7EFFFFFFFFFFFFFFULL; bool* lua_veto_flag = NULL; bool* lua_kill_frame = NULL; extern const char* lua_sysrc_script; +void* synchronous_paint_ctx; lua_state lsnes_lua_state; lua_function_group lua_func_bit; @@ -235,6 +236,13 @@ namespace do_eval_lua(L, lua_sysrc_script); } + void run_synchronous_paint(struct lua_render_context* ctx) + { + if(!synchronous_paint_ctx) + return; + lua_renderq_run(ctx, synchronous_paint_ctx); + } + #define DEFINE_CB(X) lua_state::lua_callback_list on_##X (lsnes_lua_state, #X , "on_" #X ) DEFINE_CB(paint); @@ -267,6 +275,7 @@ namespace void lua_callback_do_paint(struct lua_render_context* ctx, bool non_synthetic) throw() { + run_synchronous_paint(ctx); run_callback(on_paint, lua_state::store_tag(lua_render_ctx, ctx), lua_state::boolean_tag(non_synthetic)); }