Lua: gui.synchronous_repaint()

This commit is contained in:
Ilari Liusvaara 2013-08-21 04:14:53 +03:00
parent e2b08d9c83
commit 7026453768
5 changed files with 55 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include "library/luabase.hpp" #include "library/luabase.hpp"
#include "library/lua-framebuffer.hpp"
extern lua_state lsnes_lua_state; extern lua_state lsnes_lua_state;
extern lua_function_group lua_func_bit; 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_idle_hook_time;
extern uint64_t lua_timer_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 #endif

12
lua.lyx
View file

@ -1452,6 +1452,18 @@ Syntax: none gui.repaint()
Request on_repaint() to happen as soon as possible. Request on_repaint() to happen as soon as possible.
\end_layout \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 \begin_layout Subsection
gui.subframe_update: Enable/Disable subframe updates gui.subframe_update: Enable/Disable subframe updates
\end_layout \end_layout

BIN
lua.pdf

Binary file not shown.

View file

@ -1,3 +1,4 @@
#include "core/framebuffer.hpp"
#include "lua/internal.hpp" #include "lua/internal.hpp"
#include "library/framebuffer.hpp" #include "library/framebuffer.hpp"
@ -50,6 +51,20 @@ namespace
return 0; return 0;
}); });
function_ptr_luafun gui_srepaint(lua_func_misc, "gui.synchronous_repaint", [](lua_state& L,
const std::string& fname) -> int {
if(lua_class<render_queue_obj>::is(L, 1)) {
lua_class<render_queue_obj>::get(L, 1, fname.c_str());
auto q = lua_class<render_queue_obj>::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, function_ptr_luafun gui_rq_clear(lua_func_misc, "gui.renderq_clear", [](lua_state& L,
const std::string& fname) -> int { const std::string& fname) -> int {
if(lua_class<render_queue_obj>::is(L, 1)) { if(lua_class<render_queue_obj>::is(L, 1)) {
@ -102,3 +117,18 @@ namespace
} }
DECLARE_LUACLASS(render_queue_obj, "RENDERCTX"); 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<uint32_t>::max())
ctx->top_gap = ptr->top_gap;
if(ptr->right_gap != std::numeric_limits<uint32_t>::max())
ctx->right_gap = ptr->right_gap;
if(ptr->bottom_gap != std::numeric_limits<uint32_t>::max())
ctx->bottom_gap = ptr->bottom_gap;
if(ptr->left_gap != std::numeric_limits<uint32_t>::max())
ctx->left_gap = ptr->left_gap;
ctx->queue->copy_from(*ptr->queue);
}

View file

@ -21,6 +21,7 @@ uint64_t lua_timer_hook_time = 0x7EFFFFFFFFFFFFFFULL;
bool* lua_veto_flag = NULL; bool* lua_veto_flag = NULL;
bool* lua_kill_frame = NULL; bool* lua_kill_frame = NULL;
extern const char* lua_sysrc_script; extern const char* lua_sysrc_script;
void* synchronous_paint_ctx;
lua_state lsnes_lua_state; lua_state lsnes_lua_state;
lua_function_group lua_func_bit; lua_function_group lua_func_bit;
@ -235,6 +236,13 @@ namespace
do_eval_lua(L, lua_sysrc_script); 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 DEFINE_CB(X) lua_state::lua_callback_list on_##X (lsnes_lua_state, #X , "on_" #X )
DEFINE_CB(paint); DEFINE_CB(paint);
@ -267,6 +275,7 @@ namespace
void lua_callback_do_paint(struct lua_render_context* ctx, bool non_synthetic) throw() 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)); run_callback(on_paint, lua_state::store_tag(lua_render_ctx, ctx), lua_state::boolean_tag(non_synthetic));
} }