Files
fulpstation/lua/timer.lua
A miscellaneous Fern 9bd86e85b5 June/July TGU: Loadout menu, flatpackers and... whatever else! (#1230)
* Initial Commit

* Not quite all was staged, apparently.

* Multiline no longer necessary

* For my convenience...

* Forgot an important little tidbit in routes.tsx

* This updated, apparently.

* And now hell breaks loose

* First batch

* Second Batch

* Third batch (Unit Tests)

* Improvised shotgun ammo is gone; Vibebots are refactored

* UpdatePath sweeps in our fulp_modules/_maps folder

* I can't bring myself to do it.

* Map stuff

* Didn't mean to leave this uncommented

* I carpet-bombed them with Find-Replace. Let's see what linters think

* I sure do hope this is comprehensive and doesn't break other things

* This may take a while

* Next Round

* Hopefully the last batch before getting on with actual fixes

* Telescreens

* :/

* Stragglers

* Helio Emergency Shuttle; NearStation adjustments.

* Only one more commit for greenchecks... Shuttle code be dammed.

* Pff, the file was missing

* Same treatment as the other map files.

* Missed a comma :P

* BZ chambers for Xenobiology

* Odd. Most of these got done earlier. Not sure why this one wasn't.

* Mapping sweep. I didn't adjust C_tags in Theia. Another time.

* The balloon alerts overlap

* I hate TGU I hate TGU

* I meant to say "I hate TG" on the last one. Freudian slip.

* Fix Fix

* Nanite research cost rebalance

* TGU-Update: Step 0

* Yeah I figured it'd do this.

* I accidentally undid this

* Failed to catch this one

* I don't trust hundredths not to break or be broken somewhere.

* Little air alarm tweaks

* Ports #1228

* Stuff I missed

* Silly

* TGU so nice we're going to make it thrice

* Yarn

* Should be all? Fixes cult stun too.

* Thermomachine layers

* Free square spellcheck to rerun tests and see if it's consistent

* All credit goes to QLA for reminding me to actually do this

* Update to e40becd742

* github folder
2024-08-06 20:17:51 -04:00

111 lines
2.4 KiB
Lua

local state = require("state")
local Timer = {}
local SSlua = dm.global_vars.SSlua
__Timer_timers = __Timer_timers or {}
__Timer_callbacks = __Timer_callbacks or {}
function __add_internal_timer(func, time, loop)
local timer = {
loop = loop,
executeTime = time + dm.world.time,
}
__Timer_callbacks[tostring(func)] = function()
timer.executing = false
if loop and timer.terminate ~= true then
timer.executeTime = dm.world.time + time
else
__stop_internal_timer(tostring(func))
end
func()
end
__Timer_timers[tostring(func)] = timer
return tostring(func)
end
function __stop_internal_timer(func)
local timer = __Timer_timers[func]
if timer then
if not timer.executing then
__Timer_timers[func] = nil
__Timer_callbacks[func] = nil
else
timer.terminate = true
end
end
end
__Timer_timer_processing = __Timer_timer_processing or false
state.state.timer_enabled = 1
__Timer_timer_process = function(seconds_per_tick)
if __Timer_timer_processing then
return 0
end
__Timer_timer_processing = true
for func, timeData in __Timer_timers do
if timeData.executing == true then
continue
end
if _exec.time / (dm.world.tick_lag * 100) > 0.85 then
sleep()
end
if dm.world.time >= timeData.executeTime then
list.add(state.state.functions_to_execute, func)
timeData.executing = true
end
end
__Timer_timer_processing = false
return 1
end
function Timer.wait(time)
local yieldIndex = _exec.next_yield_index
__add_internal_timer(function()
SSlua:queue_resume(state.state, yieldIndex)
end, time * 10, false)
coroutine.yield()
end
function Timer.set_timeout(time, func)
Timer.start_loop(time, 1, func)
end
function Timer.start_loop(time, amount, func)
if not amount or amount == 0 then
return
end
if amount == -1 then
return __add_internal_timer(func, time * 10, true)
end
if amount == 1 then
return __add_internal_timer(func, time * 10, false)
end
-- Lua counts from 1 so let's keep consistent with that
local doneAmount = 1
local funcId
local newFunc = function()
func(doneAmount)
doneAmount += 1
if doneAmount > amount then
Timer.end_loop(funcId)
end
end
funcId = __add_internal_timer(newFunc, time * 10, true)
return funcId
end
function Timer.end_loop(id)
__stop_internal_timer(id)
end
function Timer.stop_all_loops()
for id, data in __Timer_timers do
if data.loop then
Timer.end_loop(id)
end
end
end
return Timer