Commit Graph

9 Commits

Author SHA1 Message Date
Watermelon914
fe3c2edddd 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>
2024-03-22 10:59:16 +13:00
Watermelon914
ec41393b31 Expands the SS13.lua module by adding loop helpers and functions to get the script runner. (#79081)
## About The Pull Request
`SS13.get_runner_client()` and `SS13.get_runner_ckey` will return the
client and the ckey respectively of the user who ran the lua script. Can
be unreliable after the first sleep or yield.
The SS13 module can now be made local as the tables that need to be
accessed globally have been moved to their own global variables.
Added `SS13.start_loop(time, amount, func)`, `SS13.end_loop(id)`,
`SS13.stop_all_loops()` that allow lua scripts to more easily make
loops. Removed the `timer` parameter from these functions, which
specified the timer subsystem to use.
Documentation on all new added functions have been added in the
lua/README.md

## Why It's Good For The Game
Getting the client who ran the script and the ckey that ran the script
is useful for self contained scripts that are looking for an entrypoint
(e.g. location to spawn some item/mob/structure). `dm.usr` is a special
variable used for other purposes and can be unreliable when used this
way even if there haven't been any sleeps or yields yet, so having a
dedicated variable and function to handle it makes things easier.

Being able to make the SS13 module local allows for more self-contained
scripts. Although this isn't super helpful because `require` will still
load the same object for all lua scripts loaded on the same state.

Basic looping helpers allow for lua scripts to more easily create loops
without needing to recursively do a `set_timeout` or to do a
`while(true) do SS13.wait(1) end` loop.

## Changelog
🆑
admin: Added SS13.get_runner_ckey() and SS13.get_runner_client() which
stores the ckey and returns the client of the user who ran the lua
script. Can be unreliable if accessed after sleeping.
admin: Added timer loop helpers to the SS13.lua module, check the docs
admin: The SS13.lua module can now be made local without causing any
errors.
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
2023-10-20 13:55:58 -04:00
Watermelon914
c4763f2621 Fixes some lua problems, specifically with qdeling callbacks and adds lua utility functions (#77468)
## About The Pull Request
See title. Callbacks were getting deleted in SS13.lua which is
non-ideal. They should be automatically collected by the garbage
collector.
Also adds some utility lua functions like SS13.is_valid,
SS13.stop_tracking, SS13.new_untracked, SS13.type and SS13.qdel

## Why It's Good For The Game
Fixes some harddel issues, as well as callbacks clogging up the garbage
subsystem.

## Changelog
🆑
admin: Added new lua functions: SS13.is_valid, SS13.stop_tracking,
SS13.new_untracked, SS13.type and SS13.qdel
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
2023-08-10 06:45:31 -04:00
Watermelon914
9d61c652e3 Fixed lua-created atoms from hard deleting (#77391)
## About The Pull Request
Lua created atoms hard delete because they get added to a references
list without ever being cleared. This fixes that by registering a
qdeleting signal on them and removing them from the list on delete.

## Why It's Good For The Game
Harddel fixes

## Changelog
🆑
fix: Fixed a hard delete that would occur with lua-created atoms.
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
2023-08-07 14:28:12 -04:00
Watermelon914
b12f02c897 Fixes SS13.register_signal on parent_qdeleting signal in lua causing an error (#76282)
## About The Pull Request
Potato renamed comp_lookup to _listen_lookup, which wasn't updated in
the lua script. This PR changes the SS13 lua script to properly access
the correct variable

## Why It's Good For The Game
Bugfix

## Changelog

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
2023-06-25 17:10:57 -04:00
Y0SH1M4S73R
6bb24ac773 Fixes hard-dels related to lua signal handlers (#69555)
When I changed the syntax of SS13.lua to account for the ability to properly index tables with datums, it turns out that the callbacks created for signal handlers and timeouts had circular references, resulting in hard-deletes.

My first solution was to make it so signal handler and timeout callbacks use weakrefs, which get resolved in lua_state/call_function, but it turns out that, when calling the signal cleanup function, a qdeleted-but-not-yet-garbage-collected datum's weakref resolves to null because datum.gc_collected is set to GC_CURRENTLY_BEING_QDELETED before COMSIG_PARENT_QDELETING gets sent.

To resolve this issue, Potato and Oranges both recommended that I make a snowflake variant of resolve which ignores whether the datum a weakref points to is qdeleted - only that it is null or it's weakref isn't the very weakref resolve was called on. This proc was given a lengthy autodoc comment describing when it should or shouldn't be used, to ensure it is only used in cases similar to the one I needed to create it for (needing to resolve a weakref to a datum in a COMSIG_PARENT_QDELETING handler registered on that very datum).
2022-09-01 10:30:59 +01:00
Y0SH1M4S73R
57b10fcb64 Bumps auxlua to 1.2.1 (+ several other ui fixes and qol tweaks) (#69271)
* preparations for self-referential list conversion

* additional changes for the auxlua 1.1.1 update

* fixed a type in `SS13.await`

* bumps auxlua to 1.2.0

* bumps auxlua to 1.2.1
2022-08-23 23:21:39 -07:00
Y0SH1M4S73R
a6b4c3db8a [GBP no update] Mitigates lua-related harddels and fixes lua signal handlers for COMSIG_PARENT_QDELETING (#68677) 2022-07-24 00:56:17 -07:00
Y0SH1M4S73R
4e6e1f090e [Ready for Review] Admin lua scripting (#65635)
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-07-19 15:45:23 -07:00