small scrolling optimization to textgpu

This commit is contained in:
ocawesome101 2021-05-28 20:57:45 -04:00
parent b4fefd4c0f
commit ecdc855ee0

View File

@ -50,7 +50,7 @@ local function rgb(i)
end
local unsub, fullRefresh
local function set(x, y, text, f, b, safe)
local function set(x, y, text, f, b, safe, noref)
if x > w or x < 1 or y > h or y < 1 or not tbuffer[y] then
if safe then
return
@ -72,9 +72,11 @@ local function set(x, y, text, f, b, safe)
fbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
f .. fbuffer[y]:sub(x + len)
else
local F = mapping[f]
local r, g, _b = rgb(F)
write("\27[38;2;", r, ";", g, ";", _b, "m")
if not noref then
local F = mapping[f]
local r, g, _b = rgb(F)
write("\27[38;2;", r, ";", g, ";", _b, "m")
end
fbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
string.rep(string.char(f - 1), len) .. fbuffer[y]:sub(x + len)
end
@ -82,14 +84,18 @@ local function set(x, y, text, f, b, safe)
bbuffer[y] = bbuffer[y]:sub(1, x - 1) ..
b .. bbuffer[y]:sub(x + len)
else
local B = mapping[b]
local r, g, _b = rgb(B)
write("\27[48;2;", r, ";", g, ";", _b, "m")
if not noref then
local B = mapping[b]
local r, g, _b = rgb(B)
write("\27[48;2;", r, ";", g, ";", _b, "m")
end
bbuffer[y] = bbuffer[y]:sub(1, x - 1) ..
string.rep(string.char(b - 1), len) .. bbuffer[y]:sub(x + len)
end
write("\27[", y, ";", x, "H", text)
flush()
if not noref then
write("\27[", y, ";", x, "H", text)
flush()
end
end
fullRefresh = function()
@ -282,7 +288,7 @@ function textgpu.start()
for i=start, stop, step do
local str, fstr, bstr = get(x, i, W, true)
if str and fstr and bstr then
set(x + xd, i + yd, str, fstr, bstr, true)
set(x + xd, i + yd, str, fstr, bstr, true, true)
end
end
fullRefresh()