mirror of
https://github.com/LDDestroier/CC/
synced 2025-03-06 11:38:10 +00:00
Will not draw unchanged rows
This commit is contained in:
parent
aa16749037
commit
d575a3b660
@ -104,7 +104,10 @@ local cwrite = function(text, y, terminal)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- start up lddterm (I'm starting to think I should've used window API)
|
-- 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.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.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
|
lddterm.baseTerm = term.current() -- will draw to this terminal
|
||||||
@ -263,23 +266,26 @@ local fixCursorPos = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- renders the screen with optional transformation function
|
-- 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
|
-- determine new screen size and change lddterm screen to fit
|
||||||
old_scr_x, old_scr_y = scr_x, scr_y
|
old_scr_x, old_scr_y = scr_x, scr_y
|
||||||
determineScreenSize()
|
determineScreenSize()
|
||||||
if old_scr_x ~= scr_x or old_scr_y ~= scr_y then
|
if old_scr_x ~= scr_x or old_scr_y ~= scr_y then
|
||||||
lddterm.baseTerm.clear()
|
lddterm.baseTerm.clear()
|
||||||
end
|
end
|
||||||
local image = lddterm.screenshot()
|
lddterm.OLD_IMAGE = lddterm.FULL_IMAGE or {{},{},{}}
|
||||||
|
lddterm.FULL_IMAGE = lddterm.screenshot()
|
||||||
if type(transformation) == "function" then
|
if type(transformation) == "function" then
|
||||||
image = transformation(image)
|
lddterm.FULL_IMAGE = transformation(lddterm.FULL_IMAGE)
|
||||||
end
|
end
|
||||||
if drawFunction then
|
if drawFunction then
|
||||||
drawFunction(image, lddterm.baseTerm)
|
drawFunction(lddterm.FULL_IMAGE, lddterm.baseTerm)
|
||||||
else
|
else
|
||||||
for y = 1, #image[1] do
|
for y = 1, #lddterm.FULL_IMAGE[1] do
|
||||||
lddterm.baseTerm.setCursorPos(1 + lddterm.adjustX, y + lddterm.adjustY)
|
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.blit(image[1][y], image[2][y], image[3][y])
|
lddterm.baseTerm.setCursorPos(1 + lddterm.adjustX, y + lddterm.adjustY)
|
||||||
|
lddterm.baseTerm.blit(lddterm.FULL_IMAGE[1][y], lddterm.FULL_IMAGE[2][y], lddterm.FULL_IMAGE[3][y])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if doDrawWorkspaceIndicator then
|
if doDrawWorkspaceIndicator then
|
||||||
@ -493,7 +499,7 @@ lddterm.newWindow = function(width, height, x, y, meta)
|
|||||||
window.x = math.floor(x or window.x)
|
window.x = math.floor(x or window.x)
|
||||||
window.y = math.floor(y or window.y)
|
window.y = math.floor(y or window.y)
|
||||||
if lddterm.alwaysRender then
|
if lddterm.alwaysRender then
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
lddterm.render(lddterm.transformation, lddterm.drawFunction, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
window.handle.setPaletteColor = function(slot, r, g, b)
|
window.handle.setPaletteColor = function(slot, r, g, b)
|
||||||
@ -671,7 +677,7 @@ local newInstance = function(x, y, program, initialStart)
|
|||||||
instance.timeMod = 0
|
instance.timeMod = 0
|
||||||
instance.lastTime = 0
|
instance.lastTime = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local cx, cy
|
local cx, cy
|
||||||
|
|
||||||
local drawInactiveScreen = function()
|
local drawInactiveScreen = function()
|
||||||
@ -725,12 +731,12 @@ local newInstance = function(x, y, program, initialStart)
|
|||||||
drawInactiveScreen()
|
drawInactiveScreen()
|
||||||
|
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
|
|
||||||
for i = 0, 15 do
|
for i = 0, 15 do
|
||||||
window.palette[2^i] = {term.nativePaletteColor(2^i)}
|
window.palette[2^i] = {term.nativePaletteColor(2^i)}
|
||||||
end
|
end
|
||||||
correctPalette(window.x, window.y)
|
correctPalette(window.x, window.y)
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
evt = {os.pullEventRaw()}
|
evt = {os.pullEventRaw()}
|
||||||
if evt[1] == "workspace_swap" then
|
if evt[1] == "workspace_swap" then
|
||||||
@ -959,10 +965,10 @@ local checkIfCanRun = function(evt, x, y)
|
|||||||
elseif not instances[y][x] then
|
elseif not instances[y][x] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local instance = instances[y][x]
|
local instance = instances[y][x]
|
||||||
local focused = (focus[1] == x and focus[2] == y)
|
local focused = (focus[1] == x and focus[2] == y)
|
||||||
|
|
||||||
if evt then
|
if evt then
|
||||||
if justStarted then
|
if justStarted then
|
||||||
return true
|
return true
|
||||||
@ -970,7 +976,7 @@ local checkIfCanRun = function(evt, x, y)
|
|||||||
if instance.paused then
|
if instance.paused then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
|
|
||||||
if evt[1] == "workspace_swap" then
|
if evt[1] == "workspace_swap" then
|
||||||
return true
|
return true
|
||||||
elseif evt[1] == "terminate" and focused then
|
elseif evt[1] == "terminate" and focused then
|
||||||
@ -988,7 +994,7 @@ local checkIfCanRun = function(evt, x, y)
|
|||||||
return focused
|
return focused
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -1052,14 +1058,14 @@ local resumeInstance = function(evt, x, y)
|
|||||||
end
|
end
|
||||||
table.remove(instances[y][x].extraEvents, 1)
|
table.remove(instances[y][x].extraEvents, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if checkIfCanRun(instances[y][x].extraEvents[1], x, y) then
|
if checkIfCanRun(instances[y][x].extraEvents[1], x, y) then
|
||||||
oldFuncReplace.os.queueEvent("resume_instance", x, y, instances[y][x].extraEvents[1])
|
oldFuncReplace.os.queueEvent("resume_instance", x, y, instances[y][x].extraEvents[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
term.redirect(previousTerm)
|
term.redirect(previousTerm)
|
||||||
|
|
||||||
os.startTimer = oldFuncReplace.os.startTimer
|
os.startTimer = oldFuncReplace.os.startTimer
|
||||||
os.cancelTimer = oldFuncReplace.os.cancelTimer
|
os.cancelTimer = oldFuncReplace.os.cancelTimer
|
||||||
if config.doPauseClockAndTime then
|
if config.doPauseClockAndTime then
|
||||||
@ -1124,8 +1130,9 @@ local main = function()
|
|||||||
|
|
||||||
-- if true, timer events won't be accepted by instances (unless it's an extraEvent)
|
-- if true, timer events won't be accepted by instances (unless it's an extraEvent)
|
||||||
local banTimerEvent, evt
|
local banTimerEvent, evt
|
||||||
local doRedraw = false -- redraw screen after resuming every instance
|
local doRedraw = false -- redraw screen after resuming every instance
|
||||||
local doTick = true -- check for key inputs and whatnot
|
local doForceRedraw = false -- redraw screen without checking for changes in screen
|
||||||
|
local doTick = true -- check for key inputs and whatnot
|
||||||
|
|
||||||
local checkIfExtraEvents = function()
|
local checkIfExtraEvents = function()
|
||||||
for y = gridMinY, gridHeight do
|
for y = gridMinY, gridHeight do
|
||||||
@ -1145,6 +1152,7 @@ local main = function()
|
|||||||
while isRunning do
|
while isRunning do
|
||||||
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
||||||
doRedraw = false
|
doRedraw = false
|
||||||
|
doForceRedraw = false
|
||||||
doTick = true
|
doTick = true
|
||||||
|
|
||||||
evt = {os.pullEventRaw()}
|
evt = {os.pullEventRaw()}
|
||||||
@ -1160,6 +1168,7 @@ local main = function()
|
|||||||
doDrawWorkspaceIndicator = false
|
doDrawWorkspaceIndicator = false
|
||||||
banTimerEvent = true
|
banTimerEvent = true
|
||||||
doRedraw = true
|
doRedraw = true
|
||||||
|
doForceRedraw = true
|
||||||
else
|
else
|
||||||
if evt[2] == tID then
|
if evt[2] == tID then
|
||||||
doRedraw = true
|
doRedraw = true
|
||||||
@ -1172,9 +1181,9 @@ local main = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif evt[1] == "resume_instance" then
|
elseif evt[1] == "resume_instance" then
|
||||||
|
|
||||||
resumeInstance(evt[4], evt[2], evt[3])
|
resumeInstance(evt[4], evt[2], evt[3])
|
||||||
|
|
||||||
doTick = false
|
doTick = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1374,7 +1383,7 @@ local main = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if doRedraw then
|
if doRedraw then
|
||||||
lddterm.render()
|
lddterm.render(nil, nil, doForceRedraw)
|
||||||
end
|
end
|
||||||
|
|
||||||
lddterm.selectedWindow = instances[focus[2]][focus[1]].window.layer
|
lddterm.selectedWindow = instances[focus[2]][focus[1]].window.layer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user