1
0
mirror of https://github.com/LDDestroier/CC/ synced 2025-07-04 19:12:56 +00:00

Fixed timer events with os.queueEvent

Timers that go on 0.05 delays are now also their proper speed.
This commit is contained in:
LDDestroier 2019-06-20 18:12:03 -04:00 committed by GitHub
parent 332f92cadf
commit 21f310af7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -728,22 +728,39 @@ end
-- prevents wiseassed-ness -- prevents wiseassed-ness
config.workspaceMoveSpeed = math.min(math.max(config.workspaceMoveSpeed, 0.001), 1) config.workspaceMoveSpeed = math.min(math.max(config.workspaceMoveSpeed, 0.001), 1)
local scrollWindows = function(tickDownTimers) local tickDownInstanceTimers = function(x, y)
timersToDelete = {}
for id, duration in pairs(instances[y][x].timer) do
if duration <= 0.05 then
instances[y][x].extraEvents[#instances[y][x].extraEvents + 1] = {"timer", id}
timersToDelete[#timersToDelete + 1] = id
else
instances[y][x].timer[id] = duration - 0.05
end
end
for i = 1, #timersToDelete do
instances[y][x].timer[timersToDelete[i]] = nil
end
end
local scrollWindows = function(doScrollWindows, tickDownTimers)
local changed = false local changed = false
local timersToDelete = {} local timersToDelete = {}
if realScroll[1] < scroll[1] then if doScrollWindows then
realScroll[1] = math.min(realScroll[1] + config.workspaceMoveSpeed, scroll[1]) if realScroll[1] < scroll[1] then
changed = true realScroll[1] = math.min(realScroll[1] + config.workspaceMoveSpeed, scroll[1])
elseif realScroll[1] > scroll[1] then changed = true
realScroll[1] = math.max(realScroll[1] - config.workspaceMoveSpeed, scroll[1]) elseif realScroll[1] > scroll[1] then
changed = true realScroll[1] = math.max(realScroll[1] - config.workspaceMoveSpeed, scroll[1])
end changed = true
if realScroll[2] < scroll[2] then end
realScroll[2] = math.min(realScroll[2] + config.workspaceMoveSpeed, scroll[2]) if realScroll[2] < scroll[2] then
changed = true realScroll[2] = math.min(realScroll[2] + config.workspaceMoveSpeed, scroll[2])
elseif realScroll[2] > scroll[2] then changed = true
realScroll[2] = math.max(realScroll[2] - config.workspaceMoveSpeed, scroll[2]) elseif realScroll[2] > scroll[2] then
changed = true realScroll[2] = math.max(realScroll[2] - config.workspaceMoveSpeed, scroll[2])
changed = true
end
end end
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize() gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
for y = gridMinY, gridHeight do for y = gridMinY, gridHeight do
@ -753,20 +770,8 @@ local scrollWindows = function(tickDownTimers)
instances[y][x].window.x = math.floor(1 + (instances[y][x].x + realScroll[1] - 1) * scr_x) instances[y][x].window.x = math.floor(1 + (instances[y][x].x + realScroll[1] - 1) * scr_x)
instances[y][x].window.y = math.floor(1 + (instances[y][x].y + realScroll[2] - 1) * scr_y) instances[y][x].window.y = math.floor(1 + (instances[y][x].y + realScroll[2] - 1) * scr_y)
if not instances[y][x].paused then
if tickDownTimers and (not instances[y][x].paused) then tickDownInstanceTimers(x, y)
timersToDelete = {}
for id, duration in pairs(instances[y][x].timer) do
if duration <= 0 then
instances[y][x].extraEvents[#instances[y][x].extraEvents + 1] = {"timer", id}
timersToDelete[#timersToDelete + 1] = id
else
instances[y][x].timer[id] = duration - 0.05
end
end
for i = 1, #timersToDelete do
instances[y][x].timer[timersToDelete[i]] = nil
end
end end
end end
@ -786,7 +791,7 @@ end
local addWorkspace = function(xmod, ymod) local addWorkspace = function(xmod, ymod)
config.WSmap[focus[2] + ymod] = config.WSmap[focus[2] + ymod] or {} config.WSmap[focus[2] + ymod] = config.WSmap[focus[2] + ymod] or {}
if not config.WSmap[focus[2] + ymod][focus[1] + xmod] then if not config.WSmap[focus[2] + ymod][focus[1] + xmod] then
config.WSmap[focus[2] + ymod][focus[1] + xmod] = instances[focus[2] + ymod][focus[1] + xmod].program config.WSmap[focus[2] + ymod][focus[1] + xmod] = true
newInstance(focus[1] + xmod, focus[2] + ymod, config.defaultProgram, false) newInstance(focus[1] + xmod, focus[2] + ymod, config.defaultProgram, false)
saveConfig() saveConfig()
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize() gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
@ -903,7 +908,7 @@ local main = function()
end end
end end
scrollWindows() scrollWindows(true, false)
term.clear() term.clear()
if config.timesRan <= 0 then if config.timesRan <= 0 then
@ -938,6 +943,9 @@ local main = function()
-- timer for instance timers and window scrolling -- timer for instance timers and window scrolling
tID = os.startTimer(0.05) tID = os.startTimer(0.05)
-- if true, timer events won't be accepted by instances (unless it's an extraEvent)
local banTimerEvent
while isRunning do while isRunning do
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize() gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
local evt = {os.pullEventRaw()} local evt = {os.pullEventRaw()}
@ -950,9 +958,16 @@ local main = function()
if evt[2] == wID then if evt[2] == wID then
enteringCommand = true enteringCommand = true
doDrawWorkspaceIndicator = false doDrawWorkspaceIndicator = false
elseif evt[2] == tID then banTimerEvent = true
scrollWindows(true) else
tID = os.startTimer(0.05) if evt[2] == tID then
banTimerEvent = true
tID = os.startTimer(0.05)
scrollWindows(true, true)
else
banTimerEvent = false
scrollWindows(false, true)
end
end end
end end
@ -1091,7 +1106,6 @@ local main = function()
if instances[y] then if instances[y] then
for x = gridMinX, gridWidth do for x = gridMinX, gridWidth do
if instances[y][x] then if instances[y][x] then
if #instances[y][x].extraEvents ~= 0 then if #instances[y][x].extraEvents ~= 0 then
for i = 1, #instances[y][x].extraEvents do for i = 1, #instances[y][x].extraEvents do
if checkIfCanRun(instances[y][x].extraEvents[i], x, y) then if checkIfCanRun(instances[y][x].extraEvents[i], x, y) then
@ -1106,7 +1120,7 @@ local main = function()
instances[y][x].extraEvents = {} instances[y][x].extraEvents = {}
end end
if justStarted or (checkIfCanRun(evt, x, y) and evt[1] ~= "timer") then if justStarted or (checkIfCanRun(evt, x, y) and not (banTimerEvent and evt[1] == "timer")) then
previousTerm = term.redirect(instances[y][x].window.handle) previousTerm = term.redirect(instances[y][x].window.handle)
setInstanceSpecificFunctions(x, y) setInstanceSpecificFunctions(x, y)
cSuccess, instances[y][x].eventFilter = coroutine.resume(instances[y][x].co, table.unpack(evt)) cSuccess, instances[y][x].eventFilter = coroutine.resume(instances[y][x].co, table.unpack(evt))