From f1602b1ab2b1235b10aa15240dc04860541542b6 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 14 May 2015 01:14:52 -0700 Subject: [PATCH] defer printing to reduce lag --- Lua/event flag monitor.lua | 3 ++- Lua/messages.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Lua/event flag monitor.lua b/Lua/event flag monitor.lua index 66ca066..5fc8ec7 100644 --- a/Lua/event flag monitor.lua +++ b/Lua/event flag monitor.lua @@ -46,7 +46,7 @@ function FlagMonitor:mark(i, x, x1) str = str..' (NEW!)' end if not ignore[str] then - printf('%s @%i', str, now) + dprintf('%s @%i', str, now) message(str, 180) end end @@ -124,6 +124,7 @@ elseif oot then igi:save() it_:save() ei_:save() + print_deferred() draw_messages() emu.frameadvance() end diff --git a/Lua/messages.lua b/Lua/messages.lua index 0fde663..476b8b2 100644 --- a/Lua/messages.lua +++ b/Lua/messages.lua @@ -46,3 +46,34 @@ function draw_messages() messages = okay __messages_then = now end + +__dprinted = {} + +function dprint(...) -- defer print + -- helps with lag from printing directly to Bizhawk's console + table.insert(__dprinted, {...}) +end + +function dprintf(fmt, ...) + table.insert(__dprinted, fmt:format(...)) +end + +function print_deferred() + local buff = '' + for i, t in ipairs(__dprinted) do + if type(t) == 'string' then + buff = buff..t..'\n' + elseif type(t) == 'table' then + local s = '' + for j, v in ipairs(t) do + s = s..tostring(v) + if j ~= #t then s = s..'\t' end + end + buff = buff..s..'\n' + end + end + if #buff > 0 then + print(buff:sub(1, #buff - 1)) + end + __dprinted = {} +end