Cleans up/renames as private some internal var definitions, removes some fucked uses of internal list vars (#75769)

## About The Pull Request

[Improves the documentation of DCS lists, removes old list of callback
docs that no longer
apply](https://github.com/tgstation/tgstation/commit/c3821d9f5ffaeaa4772f927c819da0c1de0ca27c)

[Adds a second signal register to decal rotating, adds a trait to
objects under a tile. STOP DIRECTLY READING HIDDEN LISTS I SWEAR TO
GOD](https://github.com/tgstation/tgstation/commit/6b3f97a76a6f7d24ab952739a1561633922994e1)

[Removes direct reads of the timer list, they were redundant
mostly](https://github.com/tgstation/tgstation/commit/14fcd9f8a6d1b2d42ec6df3493ebc76fe7c12032)

[Please stop directly reading/modifying the traits list to ensure your
dna rot follows the
brain](https://github.com/tgstation/tgstation/commit/ec0e5237ec2b7c3b7806cb993670acc8ce388bdc)

[Marks internal datum lists as well internal with
_](https://github.com/tgstation/tgstation/pull/75769/commits/57c6577ff61629b8ea792ee37ec4f2490a8e2865)

[57c6577](https://github.com/tgstation/tgstation/pull/75769/commits/57c6577ff61629b8ea792ee37ec4f2490a8e2865)

Does the same to _clear_signal_refs() in hopes of keeping people from
touching it

## Why It's Good For The Game

They pissed me off.

Users should not be touching these lists, especially in ways that make
assumptions about their structure and are thus prone to breaking if that
ever changes.
Most of these are close to zero cost changes, using a wrapper to solve
the problem, or just yeeting it

Two aren't, Decals with a direction have gained a second signal register
on init, and things that sit underfloor (cables/pipes) now get a trait
when inserted there.

This should have a minimal impact on memory/init time, bugging
@Mothblocks about it just in case
This commit is contained in:
LemonInTheDark
2023-06-05 22:25:09 -06:00
committed by GitHub
parent 83cd4cac3b
commit daf55e611c
22 changed files with 135 additions and 118 deletions
+22 -22
View File
@@ -90,9 +90,9 @@
/datum/component/proc/_JoinParent()
var/datum/P = parent
//lazy init the parent's dc list
var/list/dc = P.datum_components
var/list/dc = P._datum_components
if(!dc)
P.datum_components = dc = list()
P._datum_components = dc = list()
//set up the typecache
var/our_type = type
@@ -127,7 +127,7 @@
*/
/datum/component/proc/_RemoveFromParent()
var/datum/parent = src.parent
var/list/parents_components = parent.datum_components
var/list/parents_components = parent._datum_components
for(var/I in _GetInverseTypeList())
var/list/components_of_type = parents_components[I]
@@ -143,7 +143,7 @@
parents_components -= I
if(!parents_components.len)
parent.datum_components = null
parent._datum_components = null
UnregisterFromParent()
@@ -220,9 +220,9 @@
RegisterSignals(target, signal_type, proctype, override)
return
var/list/procs = (signal_procs ||= list())
var/list/procs = (_signal_procs ||= list())
var/list/target_procs = (procs[target] ||= list())
var/list/lookup = (target.comp_lookup ||= list())
var/list/lookup = (target._comp_lookup ||= list())
if(!override && target_procs[signal_type])
var/override_message = "[signal_type] overridden. Use override = TRUE to suppress this warning.\nTarget: [target] ([target.type]) Proc: [proctype]"
@@ -258,13 +258,13 @@
* * sig_typeor_types Signal string key or list of signal keys to stop listening to specifically
*/
/datum/proc/UnregisterSignal(datum/target, sig_type_or_types)
var/list/lookup = target.comp_lookup
if(!signal_procs || !signal_procs[target] || !lookup)
var/list/lookup = target._comp_lookup
if(!_signal_procs || !_signal_procs[target] || !lookup)
return
if(!islist(sig_type_or_types))
sig_type_or_types = list(sig_type_or_types)
for(var/sig in sig_type_or_types)
if(!signal_procs[target][sig])
if(!_signal_procs[target][sig])
if(!istext(sig))
stack_trace("We're unregistering with something that isn't a valid signal \[[sig]\], you fucked up")
continue
@@ -272,25 +272,25 @@
if(2)
lookup[sig] = (lookup[sig]-src)[1]
if(1)
stack_trace("[target] ([target.type]) somehow has single length list inside comp_lookup")
stack_trace("[target] ([target.type]) somehow has single length list inside _comp_lookup")
if(src in lookup[sig])
lookup -= sig
if(!length(lookup))
target.comp_lookup = null
target._comp_lookup = null
break
if(0)
if(lookup[sig] != src)
continue
lookup -= sig
if(!length(lookup))
target.comp_lookup = null
target._comp_lookup = null
break
else
lookup[sig] -= src
signal_procs[target] -= sig_type_or_types
if(!signal_procs[target].len)
signal_procs -= target
_signal_procs[target] -= sig_type_or_types
if(!_signal_procs[target].len)
_signal_procs -= target
/**
* Called on a component when a component of the same type was added to the same parent
@@ -354,17 +354,17 @@
* Use the [SEND_SIGNAL] define instead
*/
/datum/proc/_SendSignal(sigtype, list/arguments)
var/target = comp_lookup[sigtype]
var/target = _comp_lookup[sigtype]
if(!length(target))
var/datum/listening_datum = target
return NONE | call(listening_datum, listening_datum.signal_procs[src][sigtype])(arglist(arguments))
return NONE | call(listening_datum, listening_datum._signal_procs[src][sigtype])(arglist(arguments))
. = NONE
// This exists so that even if one of the signal receivers unregisters the signal,
// all the objects that are receiving the signal get the signal this final time.
// AKA: No you can't cancel the signal reception of another object by doing an unregister in the same signal.
var/list/queued_calls = list()
for(var/datum/listening_datum as anything in target)
queued_calls[listening_datum] = listening_datum.signal_procs[src][sigtype]
queued_calls[listening_datum] = listening_datum._signal_procs[src][sigtype]
for(var/datum/listening_datum as anything in queued_calls)
. |= call(listening_datum, queued_calls[listening_datum])(arglist(arguments))
@@ -381,7 +381,7 @@
RETURN_TYPE(c_type)
if(initial(c_type.dupe_mode) == COMPONENT_DUPE_ALLOWED || initial(c_type.dupe_mode) == COMPONENT_DUPE_SELECTIVE)
stack_trace("GetComponent was called to get a component of which multiple copies could be on an object. This can easily break and should be changed. Type: \[[c_type]\]")
var/list/dc = datum_components
var/list/dc = _datum_components
if(!dc)
return null
. = dc[c_type]
@@ -401,7 +401,7 @@
RETURN_TYPE(c_type)
if(initial(c_type.dupe_mode) == COMPONENT_DUPE_ALLOWED || initial(c_type.dupe_mode) == COMPONENT_DUPE_SELECTIVE)
stack_trace("GetComponent was called to get a component of which multiple copies could be on an object. This can easily break and should be changed. Type: \[[c_type]\]")
var/list/dc = datum_components
var/list/dc = _datum_components
if(!dc)
return null
var/datum/component/C = dc[c_type]
@@ -419,7 +419,7 @@
* * c_type The component type path
*/
/datum/proc/GetComponents(c_type)
var/list/components = datum_components?[c_type]
var/list/components = _datum_components?[c_type]
if(!components)
return list()
return islist(components) ? components : list(components)
@@ -590,7 +590,7 @@
* * /datum/target the target to move the components to
*/
/datum/proc/TransferComponents(datum/target)
var/list/dc = datum_components
var/list/dc = _datum_components
if(!dc)
return
var/comps = dc[/datum/component]
+12 -8
View File
@@ -89,10 +89,18 @@
remove_timer()
return ..()
/// Returns the time remaining in decomp, either from our potential timer or our own value, whichever is more useful
/datum/component/decomposition/proc/get_time()
if(!timerid)
return time_remaining
return timeleft(timerid)
/datum/component/decomposition/proc/remove_timer()
if(active_timers) // Makes sure there's an active timer to delete.
time_remaining = timeleft(timerid)
deltimer(timerid)
if(!timerid)
return
time_remaining = timeleft(timerid)
deltimer(timerid)
timerid = null
/datum/component/decomposition/proc/dropped()
SIGNAL_HANDLER
@@ -118,11 +126,7 @@
/datum/component/decomposition/proc/examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
var/time_d = 0
if(active_timers) // Is the timer currently applied to this?
time_d = timeleft(timerid)
else
time_d = time_remaining
var/time_d = get_time()
switch(time_d / original_time)
if(0.5 to 0.75) // 25% rotten
examine_list += span_notice("[parent] looks kinda stale.")
@@ -63,6 +63,7 @@
/datum/component/plumbing/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_MOVABLE_MOVED, COMSIG_PARENT_QDELETING, COMSIG_OBJ_DEFAULT_UNFASTEN_WRENCH, COMSIG_OBJ_HIDE, \
COMSIG_ATOM_UPDATE_OVERLAYS, COMSIG_ATOM_DIR_CHANGE, COMSIG_MOVABLE_CHANGE_DUCT_LAYER, COMSIG_COMPONENT_ADDED))
REMOVE_TRAIT(parent, TRAIT_UNDERFLOOR, REF(src))
/datum/component/plumbing/Destroy()
ducts = null
@@ -316,6 +317,11 @@
var/should_hide = !underfloor_accessibility
if(should_hide)
ADD_TRAIT(parent_obj, TRAIT_UNDERFLOOR, REF(src))
else
REMOVE_TRAIT(parent_obj, TRAIT_UNDERFLOOR, REF(src))
if(parent_movable.anchored || !should_hide)
tile_covered = should_hide
parent_obj.update_appearance()
+18 -18
View File
@@ -18,24 +18,24 @@
var/gc_destroyed
/// Active timers with this datum as the target
var/list/active_timers
var/list/_active_timers
/// Status traits attached to this datum. associative list of the form: list(trait name (string) = list(source1, source2, source3,...))
var/list/status_traits
var/list/_status_traits
/**
* Components attached to this datum
*
* Lazy associated list in the structure of `type:component/list of components`
* Lazy associated list in the structure of `type -> component/list of components`
*/
var/list/datum_components
var/list/_datum_components
/**
* Any datum registered to receive signals from this datum is in this list
*
* Lazy associated list in the structure of `signal:registree/list of registrees`
* Lazy associated list in the structure of `signal -> registree/list of registrees`
*/
var/list/comp_lookup
/// Lazy associated list in the structure of `signals:proctype` that are run when the datum receives that signal
var/list/list/datum/callback/signal_procs
var/list/_comp_lookup
/// Lazy associated list in the structure of `target -> list(signal -> proctype)` that are run when the datum receives that signal
var/list/list/_signal_procs
/// Datum level flags
var/datum_flags = NONE
@@ -107,9 +107,9 @@
datum_flags &= ~DF_USE_TAG //In case something tries to REF us
weak_reference = null //ensure prompt GCing of weakref.
if(active_timers)
var/list/timers = active_timers
active_timers = null
if(_active_timers)
var/list/timers = _active_timers
_active_timers = null
for(var/datum/timedevent/timer as anything in timers)
if (timer.spent && !(timer.flags & TIMER_DELETE_ME))
continue
@@ -122,7 +122,7 @@
#endif
//BEGIN: ECS SHIT
var/list/dc = datum_components
var/list/dc = _datum_components
if(dc)
var/all_components = dc[/datum/component]
if(length(all_components))
@@ -133,15 +133,15 @@
qdel(C, FALSE, TRUE)
dc.Cut()
clear_signal_refs()
_clear_signal_refs()
//END: ECS SHIT
return QDEL_HINT_QUEUE
///Only override this if you know what you're doing. You do not know what you're doing
///This is a threat
/datum/proc/clear_signal_refs()
var/list/lookup = comp_lookup
/datum/proc/_clear_signal_refs()
var/list/lookup = _comp_lookup
if(lookup)
for(var/sig in lookup)
var/list/comps = lookup[sig]
@@ -151,10 +151,10 @@
else
var/datum/component/comp = comps
comp.UnregisterSignal(src, sig)
comp_lookup = lookup = null
_comp_lookup = lookup = null
for(var/target in signal_procs)
UnregisterSignal(target, signal_procs[target])
for(var/target in _signal_procs)
UnregisterSignal(target, _signal_procs[target])
#ifdef DATUMVAR_DEBUGGING_MODE
/datum/proc/save_vars()
+15 -16
View File
@@ -20,23 +20,17 @@
if(old_dir == new_dir)
return
var/list/resulting_decals_params = list() // param lists
var/list/old_decals = list() //instances
if(!source.comp_lookup || !source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS])
//should probably also unregister itself
var/list/datum/element/decal/old_decals = list() //instances
SEND_SIGNAL(source, COMSIG_ATOM_DECALS_ROTATING, old_decals)
if(!length(old_decals))
UnregisterSignal(source, COMSIG_ATOM_DIR_CHANGE)
return
if(length(source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS]))
for(var/datum/element/decal/decal in source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS])
old_decals += decal
resulting_decals_params += list(decal.get_rotated_parameters(old_dir,new_dir))
else
var/datum/element/decal/decal = source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS]
if(!istype(decal))
return
old_decals += decal
resulting_decals_params += list(decal.get_rotated_parameters(old_dir,new_dir))
var/list/resulting_decals_params = list() // param lists
for(var/datum/element/decal/rotating as anything in old_decals)
resulting_decals_params += list(rotating.get_rotated_parameters(old_dir,new_dir))
//Instead we could generate ids and only remove duplicates to save on churn on four-corners symmetry ?
for(var/datum/element/decal/decal in old_decals)
@@ -80,7 +74,7 @@
base_icon_state = _icon_state
smoothing = _smoothing
RegisterSignal(target,COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(apply_overlay), TRUE)
RegisterSignal(target, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(apply_overlay), TRUE)
if(target.flags_1 & INITIALIZED_1)
target.update_appearance(UPDATE_OVERLAYS) //could use some queuing here now maybe.
else
@@ -88,7 +82,8 @@
if(isitem(target))
INVOKE_ASYNC(target, TYPE_PROC_REF(/obj/item/, update_slot_icon), TRUE)
if(_dir)
SSdcs.RegisterSignal(target,COMSIG_ATOM_DIR_CHANGE, TYPE_PROC_REF(/datum/controller/subsystem/processing/dcs, rotate_decals), TRUE)
RegisterSignal(target, COMSIG_ATOM_DECALS_ROTATING, PROC_REF(shuttle_rotate), TRUE)
SSdcs.RegisterSignal(target, COMSIG_ATOM_DIR_CHANGE, TYPE_PROC_REF(/datum/controller/subsystem/processing/dcs, rotate_decals), override=TRUE)
if(!isnull(_smoothing))
RegisterSignal(target, COMSIG_ATOM_SMOOTHED_ICON, PROC_REF(smooth_react), TRUE)
if(_cleanable)
@@ -160,6 +155,10 @@
Detach(source)
new_turf.AddElement(type, pic.icon, base_icon_state, directional, pic.plane, pic.layer, pic.alpha, pic.color, smoothing, cleanable, description)
/datum/element/decal/proc/shuttle_rotate(datum/source, list/datum/element/decal/rotating)
SIGNAL_HANDLER
rotating += src
/**
* Reacts to the source atom smoothing.
*
+2
View File
@@ -42,6 +42,7 @@
if(underfloor_accessibility < UNDERFLOOR_INTERACTABLE)
SET_PLANE_IMPLICIT(source, FLOOR_PLANE) // We do this so that turfs that allow you to see what's underneath them don't have to be on the game plane (which causes ambient occlusion weirdness)
ADD_TRAIT(source, TRAIT_UNDERFLOOR, REF(src))
if(tile_overlay)
T.add_overlay(tile_overlay)
@@ -58,6 +59,7 @@
else
SET_PLANE_IMPLICIT(source, initial(source.plane))
REMOVE_TRAIT(source, TRAIT_UNDERFLOOR, REF(src))
if(invisibility_trait)
REMOVE_TRAIT(source, invisibility_trait, ELEMENT_TRAIT(type))