Will not draw unchanged rows

This commit is contained in:
LDDestroier 2019-09-29 23:23:58 -04:00 committed by GitHub
parent aa16749037
commit d575a3b660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 23 deletions

View File

@ -104,7 +104,10 @@ local cwrite = function(text, y, terminal)
end
-- start up lddterm (I'm starting to think I should've used window API)
local lddterm = {}
local lddterm = {
FULL_IMAGE = false,
OLD_IMAGE = false,
}
lddterm.alwaysRender = false -- renders after any and all screen-changing functions.
lddterm.useColors = true -- normal computers do not allow color, but this variable doesn't do anything yet
lddterm.baseTerm = term.current() -- will draw to this terminal
@ -263,23 +266,26 @@ local fixCursorPos = function()
end
-- renders the screen with optional transformation function
lddterm.render = function(transformation, drawFunction)
lddterm.render = function(transformation, drawFunction, forceDraw)
-- determine new screen size and change lddterm screen to fit
old_scr_x, old_scr_y = scr_x, scr_y
determineScreenSize()
if old_scr_x ~= scr_x or old_scr_y ~= scr_y then
lddterm.baseTerm.clear()
end
local image = lddterm.screenshot()
lddterm.OLD_IMAGE = lddterm.FULL_IMAGE or {{},{},{}}
lddterm.FULL_IMAGE = lddterm.screenshot()
if type(transformation) == "function" then
image = transformation(image)
lddterm.FULL_IMAGE = transformation(lddterm.FULL_IMAGE)
end
if drawFunction then
drawFunction(image, lddterm.baseTerm)
drawFunction(lddterm.FULL_IMAGE, lddterm.baseTerm)
else
for y = 1, #image[1] do
for y = 1, #lddterm.FULL_IMAGE[1] do
if forceDraw or (lddterm.FULL_IMAGE[1][y] ~= lddterm.OLD_IMAGE[1][y]) or (lddterm.FULL_IMAGE[2][y] ~= lddterm.OLD_IMAGE[2][y]) or (lddterm.FULL_IMAGE[3][y] ~= lddterm.OLD_IMAGE[3][y]) then
lddterm.baseTerm.setCursorPos(1 + lddterm.adjustX, y + lddterm.adjustY)
lddterm.baseTerm.blit(image[1][y], image[2][y], image[3][y])
lddterm.baseTerm.blit(lddterm.FULL_IMAGE[1][y], lddterm.FULL_IMAGE[2][y], lddterm.FULL_IMAGE[3][y])
end
end
end
if doDrawWorkspaceIndicator then
@ -493,7 +499,7 @@ lddterm.newWindow = function(width, height, x, y, meta)
window.x = math.floor(x or window.x)
window.y = math.floor(y or window.y)
if lddterm.alwaysRender then
lddterm.render(lddterm.transformation, lddterm.drawFunction)
lddterm.render(lddterm.transformation, lddterm.drawFunction, true)
end
end
window.handle.setPaletteColor = function(slot, r, g, b)
@ -1125,6 +1131,7 @@ local main = function()
-- if true, timer events won't be accepted by instances (unless it's an extraEvent)
local banTimerEvent, evt
local doRedraw = false -- redraw screen after resuming every instance
local doForceRedraw = false -- redraw screen without checking for changes in screen
local doTick = true -- check for key inputs and whatnot
local checkIfExtraEvents = function()
@ -1145,6 +1152,7 @@ local main = function()
while isRunning do
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
doRedraw = false
doForceRedraw = false
doTick = true
evt = {os.pullEventRaw()}
@ -1160,6 +1168,7 @@ local main = function()
doDrawWorkspaceIndicator = false
banTimerEvent = true
doRedraw = true
doForceRedraw = true
else
if evt[2] == tID then
doRedraw = true
@ -1374,7 +1383,7 @@ local main = function()
end
if doRedraw then
lddterm.render()
lddterm.render(nil, nil, doForceRedraw)
end
lddterm.selectedWindow = instances[focus[2]][focus[1]].window.layer