mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-10 08:54:15 +00:00
* Micro-optimize icon smoothing subsystem, cutting down more than 50% of its init time (about .8s drop on local, more on prod) (#69741)
With atoms now being 50% of the init time instead of ~80%, I've decided to poke around other subsystems.
Unfortunately they're not straight forward at all and extremely boring. bitmask_smooth() in particular is just a big proc that is called ~60k times, so I made some adjustments to its macro to reduce ops.
I removed code that looped over two entire Z-levels to find things to smooth, added by e2dd404, at a time before the initialize system. This doesn't have huge gains since it just defers to the queue anyway, but it still shaved off 0.1-0.2s on local.
I removed update_appearance(~UPDATE_SMOOTHING) from something since the person who added it doesn't remember why and it doesn't appear to do anything. Lemon thinks it's something to do with emissives, but I tested with neon carpet and it seemed to work fine.
* Micro-optimize icon smoothing subsystem, cutting down more than 50% of its init time (about .8s drop on local, more on prod)
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
72 lines
2.0 KiB
Plaintext
72 lines
2.0 KiB
Plaintext
SUBSYSTEM_DEF(icon_smooth)
|
|
name = "Icon Smoothing"
|
|
init_order = INIT_ORDER_ICON_SMOOTHING
|
|
wait = 1
|
|
priority = FIRE_PRIOTITY_SMOOTHING
|
|
flags = SS_TICKER
|
|
|
|
///Blueprints assemble an image of what pipes/manifolds/wires look like on initialization, and thus should be taken after everything's been smoothed
|
|
var/list/blueprint_queue = list()
|
|
var/list/smooth_queue = list()
|
|
var/list/deferred = list()
|
|
|
|
/datum/controller/subsystem/icon_smooth/fire()
|
|
var/list/smooth_queue_cache = smooth_queue
|
|
while(length(smooth_queue_cache))
|
|
var/atom/smoothing_atom = smooth_queue_cache[length(smooth_queue_cache)]
|
|
smooth_queue_cache.len--
|
|
if(QDELETED(smoothing_atom) || !(smoothing_atom.smoothing_flags & SMOOTH_QUEUED))
|
|
continue
|
|
if(smoothing_atom.flags_1 & INITIALIZED_1)
|
|
smoothing_atom.smooth_icon()
|
|
else
|
|
deferred += smoothing_atom
|
|
if (MC_TICK_CHECK)
|
|
return
|
|
|
|
if (!length(smooth_queue_cache))
|
|
if (deferred.len)
|
|
smooth_queue = deferred
|
|
deferred = smooth_queue_cache
|
|
else
|
|
can_fire = FALSE
|
|
|
|
/datum/controller/subsystem/icon_smooth/Initialize()
|
|
var/list/queue = smooth_queue
|
|
smooth_queue = list()
|
|
|
|
while(length(queue))
|
|
var/atom/smoothing_atom = queue[length(queue)]
|
|
queue.len--
|
|
if(QDELETED(smoothing_atom) || !(smoothing_atom.smoothing_flags & SMOOTH_QUEUED) || !smoothing_atom.z)
|
|
continue
|
|
smoothing_atom.smooth_icon()
|
|
CHECK_TICK
|
|
|
|
queue = blueprint_queue
|
|
blueprint_queue = null
|
|
|
|
for(var/atom/movable/movable_item as anything in queue)
|
|
if(!isturf(movable_item.loc))
|
|
continue
|
|
var/turf/item_loc = movable_item.loc
|
|
item_loc.add_blueprints(movable_item)
|
|
|
|
return SS_INIT_SUCCESS
|
|
|
|
|
|
/datum/controller/subsystem/icon_smooth/proc/add_to_queue(atom/thing)
|
|
if(thing.smoothing_flags & SMOOTH_QUEUED)
|
|
return
|
|
thing.smoothing_flags |= SMOOTH_QUEUED
|
|
smooth_queue += thing
|
|
if(!can_fire)
|
|
can_fire = TRUE
|
|
|
|
/datum/controller/subsystem/icon_smooth/proc/remove_from_queues(atom/thing)
|
|
thing.smoothing_flags &= ~SMOOTH_QUEUED
|
|
smooth_queue -= thing
|
|
if(blueprint_queue)
|
|
blueprint_queue -= thing
|
|
deferred -= thing
|