[MIRROR] Moves /datum/var/signal_enabled to datum flags (#3171)

* Moves /datum/var/signal_enabled to datum flags (#56372)

* Moves /datum/var/signal_enabled to datum flags

`signal_enabled` is a variable on /datum, so present almost every object
in the game. Folding it into the existing `datum_flags` variable will
save allocating a variable on every datum in the game.

- Clown weaponry was using the `signal_enabled` variable to turn their
  attached slippery component on and off when the shield/sword was
  toggled. They now just remove/add the component, rather than touching
  deep datum internals.

* Moves /datum/var/signal_enabled to datum flags

Co-authored-by: coiax <yellowbounder@gmail.com>
This commit is contained in:
SkyratBot
2021-02-07 15:09:15 +01:00
committed by GitHub
parent ee40596467
commit d46f728fa5
5 changed files with 38 additions and 26 deletions

View File

@@ -14,6 +14,11 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
#define DF_USE_TAG (1<<0)
#define DF_VAR_EDITED (1<<1)
#define DF_ISPROCESSING (1<<2)
/**
* Is this datum capable of sending signals?
* Set when a signal has been registered.
*/
#define DF_SIGNAL_ENABLED (1<<3)
//FLAGS BITMASK
// scroll down before changing the numbers on these

View File

@@ -85,6 +85,7 @@ DEFINE_BITFIELD(datum_flags, list(
"DF_ISPROCESSING" = DF_ISPROCESSING,
"DF_VAR_EDITED" = DF_VAR_EDITED,
"DF_USE_TAG" = DF_USE_TAG,
"DF_SIGNAL_ENABLED" = DF_SIGNAL_ENABLED,
))
DEFINE_BITFIELD(disease_flags, list(

View File

@@ -202,7 +202,7 @@
else // Many other things have registered here
lookup[sig_type][src] = TRUE
signal_enabled = TRUE
datum_flags |= DF_SIGNAL_ENABLED
/**
* Stop listening to a given signal from target
@@ -311,14 +311,14 @@
var/target = comp_lookup[sigtype]
if(!length(target))
var/datum/C = target
if(!C.signal_enabled)
if(!(C.datum_flags & DF_SIGNAL_ENABLED))
return NONE
var/proctype = C.signal_procs[src][sigtype]
return NONE | CallAsync(C, proctype, arguments)
. = NONE
for(var/I in target)
var/datum/C = I
if(!C.signal_enabled)
if(!(C.datum_flags & DF_SIGNAL_ENABLED))
continue
var/proctype = C.signal_procs[src][sigtype]
. |= CallAsync(C, proctype, arguments)

View File

@@ -36,12 +36,6 @@
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
/**
* Is this datum capable of sending signals?
*
* Set to true when a signal has been registered
*/
var/signal_enabled = FALSE
/// Datum level flags
var/datum_flags = NONE
@@ -106,7 +100,7 @@
qdel(timer)
//BEGIN: ECS SHIT
signal_enabled = FALSE
datum_flags &= ~DF_SIGNAL_ENABLED
var/list/dc = datum_components
if(dc)

View File

@@ -75,11 +75,18 @@
light_color = COLOR_YELLOW
var/next_trombone_allowed = 0
/obj/item/melee/transforming/energy/sword/bananium/ComponentInitialize()
/obj/item/melee/transforming/energy/sword/bananium/Initialize()
. = ..()
adjust_slipperiness()
/* Adds or removes a slippery component, depending on whether the sword
* is active or not.
*/
/obj/item/melee/transforming/energy/sword/proc/adjust_slipperiness()
if(active)
AddComponent(/datum/component/slippery, 60, GALOSHES_DONT_HELP)
var/datum/component/slippery/slipper = GetComponent(/datum/component/slippery)
slipper.signal_enabled = active
else
qdel(GetComponent(/datum/component/slippery))
/obj/item/melee/transforming/energy/sword/bananium/attack(mob/living/M, mob/living/user)
..()
@@ -102,9 +109,8 @@
return ..()
/obj/item/melee/transforming/energy/sword/bananium/transform_weapon(mob/living/user, supress_message_text)
..()
var/datum/component/slippery/slipper = GetComponent(/datum/component/slippery)
slipper.signal_enabled = active
. = ..()
adjust_slipperiness()
/obj/item/melee/transforming/energy/sword/bananium/ignition_effect(atom/A, mob/user)
return ""
@@ -132,16 +138,22 @@
on_throwforce = 0
on_throw_speed = 1
/obj/item/shield/energy/bananium/ComponentInitialize()
/obj/item/shield/energy/bananium/Initialize()
. = ..()
adjust_slipperiness()
/* Adds or removes a slippery component, depending on whether the shield
* is active or not.
*/
/obj/item/shield/energy/bananium/proc/adjust_slipperiness()
if(active)
AddComponent(/datum/component/slippery, 60, GALOSHES_DONT_HELP)
var/datum/component/slippery/slipper = GetComponent(/datum/component/slippery)
slipper.signal_enabled = active
else
qdel(GetComponent(/datum/component/slippery))
/obj/item/shield/energy/bananium/attack_self(mob/living/carbon/human/user)
..()
var/datum/component/slippery/slipper = GetComponent(/datum/component/slippery)
slipper.signal_enabled = active
. = ..()
adjust_slipperiness()
/obj/item/shield/energy/bananium/throw_at(atom/target, range, speed, mob/thrower, spin=1, diagonals_first = 0, datum/callback/callback, force, gentle = FALSE, quickstart = TRUE)
if(active)