mirror of
https://github.com/LDDestroier/CC/
synced 2025-07-04 02:53:05 +00:00
Tied rendering to timer rather than events, fixes
This commit is contained in:
parent
3150c0ea47
commit
416579ae69
127
workspace.lua
127
workspace.lua
@ -356,43 +356,11 @@ lddterm.newWindow = function(width, height, x, y, meta)
|
|||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
window.handle.scrollX = function(amount)
|
window.handle.write = function(text)
|
||||||
if amount > 0 then
|
|
||||||
for i = 1, amount do
|
|
||||||
for c = 1, 3 do
|
|
||||||
for y = 1, window.height do
|
|
||||||
table.remove(window.buffer[c][y], 1)
|
|
||||||
window.buffer[c][y][window.width] = (
|
|
||||||
c == 1 and window.clearChar or
|
|
||||||
c == 2 and window.colors[1] or
|
|
||||||
c == 3 and window.colors[2]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif amount < 0 then
|
|
||||||
for i = 1, -amount do
|
|
||||||
for c = 1, 3 do
|
|
||||||
for y = 1, window.height do
|
|
||||||
window.buffer[c][y][window.width] = nil
|
|
||||||
table.insert(window.buffer[c][y], 1, (
|
|
||||||
c == 1 and window.clearChar or
|
|
||||||
c == 2 and window.colors[1] or
|
|
||||||
c == 3 and window.colors[2]
|
|
||||||
))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if lddterm.alwaysRender then
|
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
window.handle.write = function(text, x, y, ignoreAlwaysRender)
|
|
||||||
assert(text ~= nil, "expected string 'text'")
|
assert(text ~= nil, "expected string 'text'")
|
||||||
text = tostring(text)
|
text = tostring(text)
|
||||||
local cx = math.floor(tonumber(x) or window.cursor[1])
|
local cx = math.floor(window.cursor[1])
|
||||||
local cy = math.floor(tonumber(y) or window.cursor[2])
|
local cy = math.floor(window.cursor[2])
|
||||||
text = text:sub(math.max(0, -cx - 1))
|
text = text:sub(math.max(0, -cx - 1))
|
||||||
for i = 1, #text do
|
for i = 1, #text do
|
||||||
if cx >= 1 and cx <= window.width and cy >= 1 and cy <= window.height then
|
if cx >= 1 and cx <= window.width and cy >= 1 and cy <= window.height then
|
||||||
@ -403,27 +371,7 @@ lddterm.newWindow = function(width, height, x, y, meta)
|
|||||||
cx = math.min(cx + 1, window.width + 1)
|
cx = math.min(cx + 1, window.width + 1)
|
||||||
end
|
end
|
||||||
window.cursor = {cx, cy}
|
window.cursor = {cx, cy}
|
||||||
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
if lddterm.alwaysRender then
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
window.handle.writeWrap = function(text, x, y, ignoreAlwaysRender)
|
|
||||||
local words = explode(" ", text, nil, true)
|
|
||||||
local cx, cy = x or window.cursor[1], y or window.cursor[2]
|
|
||||||
for i = 1, #words do
|
|
||||||
if cx + #words[i] > window.width + 1 then
|
|
||||||
cx = 1
|
|
||||||
if cy >= window.height then
|
|
||||||
window.handle.scroll(1)
|
|
||||||
cy = window.height
|
|
||||||
else
|
|
||||||
cy = cy + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
window.handle.write(words[i], cx, cy, true)
|
|
||||||
cx = cx + #words[i]
|
|
||||||
end
|
|
||||||
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -450,25 +398,13 @@ lddterm.newWindow = function(width, height, x, y, meta)
|
|||||||
cx = cx + 1
|
cx = cx + 1
|
||||||
end
|
end
|
||||||
window.cursor = {cx, cy}
|
window.cursor = {cx, cy}
|
||||||
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
window.handle.print = function(text)
|
|
||||||
text = text and tostring(text)
|
|
||||||
window.handle.write(text, x, y, true)
|
|
||||||
window.cursor[1] = 1
|
|
||||||
if window.cursor[2] >= window.height then
|
|
||||||
window.handle.scroll(1)
|
|
||||||
else
|
|
||||||
window.cursor[2] = window.cursor[2] + 1
|
|
||||||
if lddterm.alwaysRender then
|
if lddterm.alwaysRender then
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
window.handle.clear = function(char)
|
||||||
window.handle.clear = function(char, ignoreAlwaysRender)
|
|
||||||
local cx = 1
|
local cx = 1
|
||||||
|
char = type(char) == "string" and char or " "
|
||||||
for y = 1, window.height do
|
for y = 1, window.height do
|
||||||
for x = 1, window.width do
|
for x = 1, window.width do
|
||||||
if char then
|
if char then
|
||||||
@ -479,12 +415,13 @@ lddterm.newWindow = function(width, height, x, y, meta)
|
|||||||
window.buffer[3][y][x] = window.colors[2]
|
window.buffer[3][y][x] = window.colors[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
if lddterm.alwaysRender then
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
window.handle.clearLine = function(cy, char, ignoreAlwaysRender)
|
window.handle.clearLine = function(cy, char)
|
||||||
cy = math.floor(cy or window.cursor[2])
|
cy = math.floor(cy or window.cursor[2])
|
||||||
|
char = type(char) == "string" and char or " "
|
||||||
local cx = 1
|
local cx = 1
|
||||||
for x = 1, window.width do
|
for x = 1, window.width do
|
||||||
if char then
|
if char then
|
||||||
@ -494,19 +431,7 @@ lddterm.newWindow = function(width, height, x, y, meta)
|
|||||||
window.buffer[2][cy or window.cursor[2]][x] = window.colors[1]
|
window.buffer[2][cy or window.cursor[2]][x] = window.colors[1]
|
||||||
window.buffer[3][cy or window.cursor[2]][x] = window.colors[2]
|
window.buffer[3][cy or window.cursor[2]][x] = window.colors[2]
|
||||||
end
|
end
|
||||||
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
if lddterm.alwaysRender then
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
window.handle.clearColumn = function(cx, char, ignoreAlwaysRender)
|
|
||||||
cx = math.floor(cx)
|
|
||||||
char = char and char:sub(1,1)
|
|
||||||
for y = 1, window.height do
|
|
||||||
window.buffer[1][y][cx or window.cursor[1]] = char and char or window.clearChar
|
|
||||||
window.buffer[2][y][cx or window.cursor[1]] = window.colors[1]
|
|
||||||
window.buffer[3][y][cx or window.cursor[1]] = window.colors[2]
|
|
||||||
end
|
|
||||||
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
||||||
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -695,6 +620,12 @@ local newInstance = function(x, y, program, initialStart)
|
|||||||
elseif type(instance.program) == "function" then
|
elseif type(instance.program) == "function" then
|
||||||
pcall(function() load(instance.program, nil, nil, instance.env) end)
|
pcall(function() load(instance.program, nil, nil, instance.env) end)
|
||||||
end
|
end
|
||||||
|
instance.extraEvents = {}
|
||||||
|
instance.timer = {}
|
||||||
|
instance.clockMod = 0
|
||||||
|
instance.lastClock = 0
|
||||||
|
instance.timeMod = 0
|
||||||
|
instance.lastTime = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local drawInactiveScreen = function()
|
local drawInactiveScreen = function()
|
||||||
@ -747,7 +678,7 @@ local newInstance = function(x, y, program, initialStart)
|
|||||||
|
|
||||||
drawInactiveScreen()
|
drawInactiveScreen()
|
||||||
|
|
||||||
coroutine.yield()
|
--coroutine.yield()
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
evt = {os.pullEventRaw()}
|
evt = {os.pullEventRaw()}
|
||||||
@ -839,15 +770,16 @@ local scrollWindows = function(doScrollWindows, tickDownTimers)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local swapInstances = function(xmod, ymod)
|
local swapInstances = function(xmod, ymod)
|
||||||
instances[focus[2]][focus[1]], instances[focus[2] + ymod][focus[1] + xmod] = instances[focus[2] + ymod][focus[1] + xmod], instances[focus[2]][focus[1]]
|
|
||||||
instances[focus[2]][focus[1]].x, instances[focus[2] + ymod][focus[1] + xmod].x = instances[focus[2] + ymod][focus[1] + xmod].x, instances[focus[2]][focus[1]].x
|
|
||||||
instances[focus[2]][focus[1]].y, instances[focus[2] + ymod][focus[1] + xmod].y = instances[focus[2] + ymod][focus[1] + xmod].y, instances[focus[2]][focus[1]].y
|
|
||||||
if not instances[focus[2]][focus[1]].active then
|
if not instances[focus[2]][focus[1]].active then
|
||||||
table.insert(instances[focus[2]][focus[1]].extraEvents, {"workspace_swap"})
|
table.insert(instances[focus[2]][focus[1]].extraEvents, {"workspace_swap"})
|
||||||
end
|
end
|
||||||
if not instances[focus[2] + ymod][focus[1] + xmod].active then
|
if not instances[focus[2] + ymod][focus[1] + xmod].active then
|
||||||
table.insert(instances[focus[2] + ymod][focus[1] + xmod].extraEvents, {"workspace_swap"})
|
table.insert(instances[focus[2] + ymod][focus[1] + xmod].extraEvents, {"workspace_swap"})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
instances[focus[2]][focus[1]], instances[focus[2] + ymod][focus[1] + xmod] = instances[focus[2] + ymod][focus[1] + xmod], instances[focus[2]][focus[1]]
|
||||||
|
instances[focus[2]][focus[1]].x, instances[focus[2] + ymod][focus[1] + xmod].x = instances[focus[2] + ymod][focus[1] + xmod].x, instances[focus[2]][focus[1]].x
|
||||||
|
instances[focus[2]][focus[1]].y, instances[focus[2] + ymod][focus[1] + xmod].y = instances[focus[2] + ymod][focus[1] + xmod].y, instances[focus[2]][focus[1]].y
|
||||||
end
|
end
|
||||||
|
|
||||||
local addWorkspace = function(xmod, ymod)
|
local addWorkspace = function(xmod, ymod)
|
||||||
@ -948,9 +880,12 @@ local checkIfCanRun = function(evt, x, y)
|
|||||||
instances[y][x].active or (
|
instances[y][x].active or (
|
||||||
x == focus[1] and
|
x == focus[1] and
|
||||||
y == focus[2]
|
y == focus[2]
|
||||||
) or
|
) or (
|
||||||
evt[1] == "terminate" or
|
x == focus[1] and
|
||||||
evt[1] == "workspace_swap"
|
y == focus[2]
|
||||||
|
) and (
|
||||||
|
evt[1] == "terminate"
|
||||||
|
) or evt[1] == "workspace_swap"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1055,9 +990,11 @@ 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
|
||||||
|
|
||||||
while isRunning do
|
while isRunning do
|
||||||
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
||||||
|
doRedraw = false
|
||||||
|
|
||||||
evt = {os.pullEventRaw()}
|
evt = {os.pullEventRaw()}
|
||||||
|
|
||||||
@ -1073,6 +1010,7 @@ local main = function()
|
|||||||
banTimerEvent = true
|
banTimerEvent = true
|
||||||
else
|
else
|
||||||
if evt[2] == tID then
|
if evt[2] == tID then
|
||||||
|
doRedraw = true
|
||||||
banTimerEvent = true
|
banTimerEvent = true
|
||||||
tID = os.startTimer(0.05)
|
tID = os.startTimer(0.05)
|
||||||
scrollWindows(true, true)
|
scrollWindows(true, true)
|
||||||
@ -1296,8 +1234,11 @@ local main = function()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
lddterm.selectedWindow = instances[focus[2]][focus[1]].window.layer
|
if doRedraw then
|
||||||
lddterm.render()
|
lddterm.render()
|
||||||
|
end
|
||||||
|
|
||||||
|
lddterm.selectedWindow = instances[focus[2]][focus[1]].window.layer
|
||||||
justStarted = false
|
justStarted = false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user