mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 09:42:29 +00:00
## About The Pull Request
As the title says.
`init_order` is no more, subsystems ordering now depends on their
declared dependencies.
Subsystems can now declare which other subsystems need to init before
them using a list and the subsystem's typepath
I.e.
```dm
dependencies = list(
/datum/controller/subsystem/atoms,
/datum/controller/subsystem/mapping
)
```
The reverse can also be done, if a subsystem must initialize after your
own:
```dm
dependents = list(
/datum/controller/subsystem/atoms
)
```
Cyclical dependencies are not allowed and will throw an error on
initialization if one is found.
There's also a debug tool to visualize the dependency graph, although
it's a bit basic:

Subsystem load ordering can still be controlled using `init_stage`, some
subsystems use this in cases where they must initialize first or last
regardless of dependencies. An error will be thrown if a subsystem has
an `init_stage` before one of their dependencies.
## Why It's Good For The Game
Makes dealing with subsystem dependencies easier, and reduces the chance
of making a dependency error when needing to shift around subsystem
inits.
## Changelog
🆑
refactor: Refactored subsystem initialization
/🆑
74 lines
2.5 KiB
Plaintext
74 lines
2.5 KiB
Plaintext
SUBSYSTEM_DEF(vis_overlays)
|
|
name = "Vis contents overlays"
|
|
wait = 1 MINUTES
|
|
flags = SS_NO_INIT
|
|
priority = FIRE_PRIORITY_VIS
|
|
|
|
var/list/vis_overlay_cache = list()
|
|
var/list/currentrun
|
|
|
|
/datum/controller/subsystem/vis_overlays/fire(resumed = FALSE)
|
|
if(!resumed)
|
|
currentrun = vis_overlay_cache.Copy()
|
|
var/list/current_run = currentrun
|
|
|
|
while(current_run.len)
|
|
var/key = current_run[current_run.len]
|
|
var/obj/effect/overlay/vis/overlay = current_run[key]
|
|
current_run.len--
|
|
if(!overlay.unused && !length(overlay.vis_locs))
|
|
overlay.unused = world.time
|
|
else if(overlay.unused && overlay.unused + overlay.cache_expiration < world.time)
|
|
vis_overlay_cache -= key
|
|
qdel(overlay)
|
|
if(MC_TICK_CHECK)
|
|
return
|
|
|
|
//the "thing" var can be anything with vis_contents which includes images - in the future someone should totally allow vis overlays to be passed in as an arg instead of all this bullshit
|
|
/datum/controller/subsystem/vis_overlays/proc/add_vis_overlay(atom/movable/thing, icon, iconstate, layer, plane, dir, alpha = 255, add_appearance_flags = NONE, unique = FALSE)
|
|
var/obj/effect/overlay/vis/overlay
|
|
if(!unique)
|
|
. = "[icon]|[iconstate]|[layer]|[plane]|[dir]|[alpha]|[add_appearance_flags]"
|
|
overlay = vis_overlay_cache[.]
|
|
if(!overlay)
|
|
overlay = _create_new_vis_overlay(icon, iconstate, layer, plane, dir, alpha, add_appearance_flags)
|
|
vis_overlay_cache[.] = overlay
|
|
else
|
|
overlay.unused = 0
|
|
else
|
|
overlay = _create_new_vis_overlay(icon, iconstate, layer, plane, dir, alpha, add_appearance_flags)
|
|
overlay.cache_expiration = -1
|
|
var/cache_id = "[text_ref(overlay)]@{[world.time]}"
|
|
vis_overlay_cache[cache_id] = overlay
|
|
. = overlay
|
|
thing.vis_contents += overlay
|
|
|
|
if(!isatom(thing)) // Automatic rotation is not supported on non atoms
|
|
return overlay
|
|
|
|
if(!thing.managed_vis_overlays)
|
|
thing.managed_vis_overlays = list(overlay)
|
|
else
|
|
thing.managed_vis_overlays += overlay
|
|
return overlay
|
|
|
|
/datum/controller/subsystem/vis_overlays/proc/_create_new_vis_overlay(icon, iconstate, layer, plane, dir, alpha, add_appearance_flags)
|
|
var/obj/effect/overlay/vis/overlay = new
|
|
overlay.icon = icon
|
|
overlay.icon_state = iconstate
|
|
overlay.layer = layer
|
|
overlay.plane = plane
|
|
overlay.dir = dir
|
|
overlay.alpha = alpha
|
|
overlay.appearance_flags |= add_appearance_flags
|
|
return overlay
|
|
|
|
|
|
/datum/controller/subsystem/vis_overlays/proc/remove_vis_overlay(atom/movable/thing, list/overlays)
|
|
thing.vis_contents -= overlays
|
|
if(!isatom(thing))
|
|
return
|
|
thing.managed_vis_overlays -= overlays
|
|
if(!length(thing.managed_vis_overlays))
|
|
thing.managed_vis_overlays = null
|