Icon smoothing subsystem update (#17383)

* sfasdf

* sfsaf

* sadfas

* sdfasdf
This commit is contained in:
Fluffy
2023-09-27 10:23:15 +00:00
committed by GitHub
parent 5623822d0d
commit 870f97c1c7
34 changed files with 370 additions and 175 deletions
+71 -14
View File
@@ -1,3 +1,20 @@
/**
* Adds an atom to the smoothing queue
*
* Used only internally to save on proc calls, eg. for `add_to_queue_neighbors`
*
* * thing - An `/atom` to add to the queue
*/
#define SSICONSMOOTH_ADD_TO_QUEUE(thing) \
if(thing.smoothing_flags & SMOOTH_QUEUED){ \
return; \
}\
thing.smoothing_flags |= SMOOTH_QUEUED; \
smooth_queue += thing; \
if(!can_fire){ \
can_fire = TRUE; \
}
var/datum/controller/subsystem/icon_smooth/SSicon_smooth
/datum/controller/subsystem/icon_smooth
@@ -24,17 +41,27 @@ var/datum/controller/subsystem/icon_smooth/SSicon_smooth
return ..()
/datum/controller/subsystem/icon_smooth/fire()
if(SSatoms.initializing_something())
return
if (explosion_in_progress)
return
while(smooth_queue.len)
var/atom/A = smooth_queue[smooth_queue.len]
smooth_queue.len--
smooth_icon(A)
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
smooth_icon(smoothing_atom)
if (MC_TICK_CHECK)
return
if (!smooth_queue.len)
suspend()
if (!length(smooth_queue_cache))
can_fire = FALSE
/datum/controller/subsystem/icon_smooth/ExplosionStart()
explosion_in_progress = TRUE
@@ -48,16 +75,46 @@ var/datum/controller/subsystem/icon_smooth/SSicon_smooth
if (config.fastboot)
LOG_DEBUG("icon_smoothing: Skipping prebake, fastboot enabled.")
..()
return
return ..()
var/queue = smooth_queue
var/list/queue = smooth_queue
smooth_queue = list()
for(var/V in queue)
var/atom/A = V
if(!A)
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
smooth_icon(A)
smooth_icon(smoothing_atom)
CHECK_TICK
..()
. = ..()
/datum/controller/subsystem/icon_smooth/proc/add_to_queue(atom/thing)
SHOULD_NOT_SLEEP(TRUE)
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/add_to_queue_neighbors(atom/thing)
SHOULD_NOT_SLEEP(TRUE)
for(var/atom/neighbor as anything in orange(1,thing))
if(neighbor.smoothing_flags)
SSICONSMOOTH_ADD_TO_QUEUE(neighbor)
/datum/controller/subsystem/icon_smooth/proc/remove_from_queues(atom/thing)
SHOULD_NOT_SLEEP(TRUE)
thing.smoothing_flags &= ~SMOOTH_QUEUED
smooth_queue -= thing
#undef SSICONSMOOTH_ADD_TO_QUEUE
@@ -1,3 +1,5 @@
#define SUBSYSTEM_INIT_SOURCE "subsystem init"
var/datum/controller/subsystem/atoms/SSatoms
#define BAD_INIT_QDEL_BEFORE 1
@@ -10,6 +12,11 @@ var/datum/controller/subsystem/atoms/SSatoms
init_order = SS_INIT_ATOMS
flags = SS_NO_FIRE
/// A stack of list(source, desired initialized state)
/// We read the source of init changes from the last entry, and assert that all changes will come with a reset
var/list/initialized_state = list()
var/base_initialized
var/initialized = INITIALIZATION_INSSATOMS
var/old_initialized
@@ -27,13 +34,14 @@ var/datum/controller/subsystem/atoms/SSatoms
/datum/controller/subsystem/atoms/Initialize(timeofday)
initialized = INITIALIZATION_INNEW_MAPLOAD
InitializeAtoms()
initialized = INITIALIZATION_INNEW_REGULAR
return ..()
/datum/controller/subsystem/atoms/proc/InitializeAtoms(list/atoms)
if(initialized == INITIALIZATION_INSSATOMS)
return
initialized = INITIALIZATION_INNEW_MAPLOAD
set_tracked_initalized(INITIALIZATION_INNEW_MAPLOAD, SUBSYSTEM_INIT_SOURCE)
LAZYINITLIST(late_loaders)
LAZYINITLIST(late_qdel)
@@ -58,7 +66,7 @@ var/datum/controller/subsystem/atoms/SSatoms
admin_notice(SPAN_DANGER("Initialized [count] atoms."), R_DEBUG)
log_subsystem("atoms", "Initialized [count] atoms.")
initialized = INITIALIZATION_INNEW_REGULAR
clear_tracked_initalize(SUBSYSTEM_INIT_SOURCE)
if(late_loaders.len)
for(var/I in 1 to late_loaders.len)
@@ -127,12 +135,17 @@ var/datum/controller/subsystem/atoms/SSatoms
/datum/controller/subsystem/atoms/proc/ForceInitializeContents(atom/A)
var/list/mload_args = list(TRUE)
var/loaded = 0
set_tracked_initalized(INITIALIZATION_INNEW_MAPLOAD, SUBSYSTEM_INIT_SOURCE+"- ForceInitializeContents: [text_ref(A)]")
for (var/thing in A)
var/atom/movable/AM = thing
if (!AM.initialized)
InitAtom(AM, mload_args)
++loaded
clear_tracked_initalize(SUBSYSTEM_INIT_SOURCE+"- ForceInitializeContents: [text_ref(A)]")
LOG_DEBUG("atoms: force-loaded [loaded] out of [A.contents.len] atoms in [A].")
/datum/controller/subsystem/atoms/proc/InitLog()
@@ -158,11 +171,39 @@ var/datum/controller/subsystem/atoms/SSatoms
initialized = SSatoms.initialized
if(initialized == INITIALIZATION_INNEW_MAPLOAD)
InitializeAtoms()
old_initialized = SSatoms.old_initialized
initialized_state = SSatoms.initialized_state
BadInitializeCalls = SSatoms.BadInitializeCalls
/datum/controller/subsystem/atoms/proc/map_loader_begin()
old_initialized = initialized
initialized = INITIALIZATION_INSSATOMS
/datum/controller/subsystem/atoms/proc/map_loader_begin(source)
set_tracked_initalized(INITIALIZATION_INSSATOMS, source)
/datum/controller/subsystem/atoms/proc/map_loader_stop()
initialized = old_initialized
/datum/controller/subsystem/atoms/proc/map_loader_stop(source)
clear_tracked_initalize(source)
/// Use this to set initialized to prevent error states where the old initialized is overriden, and we end up losing all context
/// Accepts a state and a source, the most recent state is used, sources exist to prevent overriding old values accidentially
/datum/controller/subsystem/atoms/proc/set_tracked_initalized(state, source)
if(!length(initialized_state))
base_initialized = initialized
initialized_state += list(list(source, state))
initialized = state
/datum/controller/subsystem/atoms/proc/clear_tracked_initalize(source)
if(!length(initialized_state))
return
for(var/i in length(initialized_state) to 1 step -1)
if(initialized_state[i][1] == source)
initialized_state.Cut(i, i+1)
break
if(!length(initialized_state))
initialized = base_initialized
base_initialized = INITIALIZATION_INNEW_REGULAR
return
initialized = initialized_state[length(initialized_state)][2]
/// Returns TRUE if anything is currently being initialized
/datum/controller/subsystem/atoms/proc/initializing_something()
return length(initialized_state) > 1
#undef SUBSYSTEM_INIT_SOURCE