[MIRROR] Moves lua off of the timer subsystem and onto its own internal scheduler. (#26980)

* Moves lua off of the timer subsystem and onto its own internal scheduler. (#82131)

## About The Pull Request
Lua uses the timer subsystem, which can end up holding the entire timer
subsystem if lua is creating a lot of timers.
The solution to this is to use an internal scheduler instead so that the
load gets placed onto the lua subsystem.

## Why It's Good For The Game
Performance improvement when using lua scripts.

## Changelog
🆑
refactor: Auxlua no longer uses the timer subsystem to get stuff done,
lua scripts shouldn't slow down timers anymore.
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>

* Moves lua off of the timer subsystem and onto its own internal scheduler.

---------

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>
This commit is contained in:
SkyratBot
2024-04-03 01:04:17 +02:00
committed by GitHub
parent 391abe6c91
commit 3ff553cb62
5 changed files with 328 additions and 246 deletions
+13
View File
@@ -24,6 +24,12 @@ GLOBAL_PROTECT(lua_usr)
/// Ckey of the last user who ran a script on this lua state.
var/ckey_last_runner = ""
/// Whether the timer.lua script has been included into this lua context state.
var/timer_enabled = FALSE
/// Callbacks that need to be ran on next tick
var/list/functions_to_execute = list()
/datum/lua_state/vv_edit_var(var_name, var_value)
. = ..()
if(var_name == NAMEOF(src, internal_id))
@@ -89,6 +95,13 @@ GLOBAL_PROTECT(lua_usr)
return result
/datum/lua_state/process(seconds_per_tick)
if(timer_enabled)
call_function("__Timer_timer_process", seconds_per_tick)
for(var/function as anything in functions_to_execute)
call_function(list("__Timer_callbacks", function))
functions_to_execute.Cut()
/datum/lua_state/proc/call_function(function, ...)
var/call_args = length(args) > 1 ? args.Copy(2) : list()
if(islist(function))