1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-06-01 10:53:05 -07:00

defer printing to reduce lag

This commit is contained in:
Connor Olding 2015-05-14 01:14:52 -07:00
parent 9b6c63df2d
commit f1602b1ab2
2 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -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