converted on_destroyed to lazy events (#27260)

This commit is contained in:
DamianX
2020-07-26 02:32:08 +02:00
committed by GitHub
parent 7ceeeeeeb2
commit 133ca45654
11 changed files with 44 additions and 84 deletions

View File

@@ -489,7 +489,7 @@ var/global/list/radial_menus = list()
// Copying atoms is stupid and this is a stupid solution
var/list/variables_not_to_be_copied = list(
"type","loc","locs","vars","parent","parent_type","verbs","ckey","key",
"group","on_destroyed","on_density_change",
"group","on_density_change","registered_events",
"on_use","on_emote","on_life","on_resist",
"on_spellcast","on_uattack","on_ruattack","on_logout","on_damaged",
"on_death","on_clickon","on_attackhand","on_attackby",

View File

@@ -78,6 +78,13 @@
// atom/movable/mover: the movable itself.
/lazy_event/on_moved
// Called whenever a datum is destroyed.
// Currently, as an optimization, only /atom/movable invokes this but
// it can be changed to /datum if the need arises.
/lazy_event/on_destroyed
// Arguments:
// datum/thing: the datum being destroyed.
/datum
/// Associative list of type path -> list(),
/// where the type path is a descendant of /event_type.

View File

@@ -29,8 +29,6 @@ var/runechat_icon = null
var/scheduled_destruction
/// Contains the approximate amount of lines for height decay
var/approx_lines
/// Reference to on_destroyed event from master
var/destroyed_ev_key
/**
* Constructs a chat message overlay
@@ -56,7 +54,7 @@ var/runechat_icon = null
if (owned_by)
owned_by.seen_messages.Remove(src)
owned_by.images.Remove(message)
owned_by.mob.on_destroyed.Remove(destroyed_ev_key)
owned_by.mob.lazy_unregister_event(/lazy_event/on_destroyed, src, .proc/qdel_self)
owned_by = null
message_loc = null
message = null
@@ -76,7 +74,7 @@ var/runechat_icon = null
set waitfor = FALSE
// Register client who owns this message
owned_by = owner.client
destroyed_ev_key = owner.on_destroyed.Add(src, .proc/qdel_self)
owner.lazy_register_event(/lazy_event/on_destroyed, src, .proc/qdel_self)
// Clip message
var/maxlen = owned_by.prefs.max_chat_length
@@ -161,7 +159,7 @@ var/runechat_icon = null
spawn(lifespan - CHAT_MESSAGE_EOL_FADE)
end_of_life()
/datum/chatmessage/proc/qdel_self()
/datum/chatmessage/proc/qdel_self(datum/thing)
qdel(src)
/**

View File

@@ -87,14 +87,12 @@ var/list/datum/map_element/map_elements = list()
if(!istype(A))
return
A.on_destroyed.Add(src, "clear_references")
A.lazy_register_event(/lazy_event/on_destroyed, src, .proc/clear_references)
return A
/datum/map_element/proc/clear_references(list/params)
var/atom/movable/A = params["atom"]
if(!A)
/datum/map_element/proc/clear_references(datum/thing)
if(!thing)
return
//Remove instances by brute force (there aren't that many vars in map element datums)
@@ -102,11 +100,11 @@ var/list/datum/map_element/map_elements = list()
if(key == "vars")
continue
if(vars[key] == A)
if(vars[key] == thing)
vars[key] = null
else if(istype(vars[key], /list))
var/list/L = vars[key]
//Remove all instances from the list
while(L.Remove(A))
while(L.Remove(thing))
continue

View File

@@ -45,9 +45,6 @@
var/throwpass = 0
var/level = 2
// When the object is qdel'd
var/event/on_destroyed
var/atom/movable/tether_master
var/list/tether_slaves
var/list/current_tethers
@@ -67,8 +64,6 @@
for(var/matID in starting_materials)
materials.addAmount(matID, starting_materials[matID])
on_destroyed = new("owner"=src)
/atom/movable/Destroy()
var/turf/T = loc
if (opacity && istype(T))
@@ -78,10 +73,7 @@
qdel(materials)
materials = null
INVOKE_EVENT(on_destroyed, list("atom" = src)) // 1 argument - the object itself
if(on_destroyed)
on_destroyed.holder = null
on_destroyed = null
lazy_invoke_event(/lazy_event/on_destroyed, list("thing" = src))
var/turf/un_opaque
if (opacity && isturf(loc))
@@ -646,7 +638,6 @@
/atom/movable/overlay
var/atom/master = null
var/follow_proc = /atom/movable/overlay/proc/move_to_turf_or_null
var/master_destroyed_key
anchored = 1
/atom/movable/overlay/New()
@@ -665,17 +656,17 @@
SetInitLoc()
if (istype(master, /atom/movable))
var/atom/movable/AM = master
master_destroyed_key = AM.on_destroyed.Add(src, .proc/qdel_self)
AM.lazy_register_event(/lazy_event/on_destroyed, src, .proc/qdel_self)
verbs.len = 0
/atom/movable/overlay/proc/qdel_self()
/atom/movable/overlay/proc/qdel_self(datum/thing)
qdel(src) // Rest in peace
/atom/movable/overlay/Destroy()
if(istype(master, /atom/movable))
var/atom/movable/AM = master
AM.lazy_unregister_event(/lazy_event/on_moved, src, follow_proc)
AM.on_destroyed.Remove(master_destroyed_key)
AM.lazy_unregister_event(/lazy_event/on_destroyed, src, .proc/qdel_self)
master = null
return ..()

View File

@@ -179,7 +179,6 @@
if (src.holding)
src.holding.forceMove(src.loc)
src.holding = null
INVOKE_EVENT(on_destroyed, list())
nanomanager.update_uis(src)
return 1
else

View File

@@ -34,19 +34,18 @@
detectTime = world.time // start the clock
if (!(target in motionTargets))
motionTargets += target
target.on_destroyed.Add(src, "clearDeletedTarget")
target.lazy_register_event(/lazy_event/on_destroyed, src, .proc/clearDeletedTarget)
return 1
/obj/machinery/camera/proc/lostTarget(var/mob/target)
if (target in motionTargets)
motionTargets -= target
target.on_destroyed.Remove("\ref[src]:clearDeletedTarget")
target.lazy_unregister_event(/lazy_event/on_destroyed, src, .proc/clearDeletedTarget)
if (motionTargets.len == 0)
cancelAlarm()
/obj/machinery/camera/proc/clearDeletedTarget(list/params)
var/atom/destroyed = params["atom"]
lostTarget(destroyed)
/obj/machinery/camera/proc/clearDeletedTarget(datum/thing)
lostTarget(thing)
/obj/machinery/camera/proc/cancelAlarm()
if (detectTime == -1)

View File

@@ -61,7 +61,6 @@
var/stepped=0
var/steps=0 // How many steps we've made from the emitter. Used in infinite loop avoidance.
var/am_connector=0
var/targetDestroyKey=null // Key for the on_destroyed listener.
var/targetDensityKey=null // Key for the on_density_change listener
var/targetContactLoc=null // Where we hit the target (used for target_moved)
var/locDensity=null
@@ -174,23 +173,13 @@
// Disconnect and re-emit.
disconnect()
// Listener for /atom/on_destroyed
/obj/effect/beam/proc/target_destroyed(var/list/args)
// Listener for /lazy_event/on_destroyed
/obj/effect/beam/proc/target_destroyed(datum/thing)
if(master)
beam_testing("Child got target_destroyed! Feeding to master.")
master.target_destroyed(args)
master.target_destroyed(thing)
return
var/event/E = args["event"]
if(!targetDestroyKey)
E.handlers.Remove("\ref[src]:target_destroyed")
beam_testing("Uh oh, got a target_destroyed when we weren't listening for one.")
return
if(E.holder != target)
E.handlers.Remove("\ref[src]:target_destroyed")
return
beam_testing("\ref[src] Disconnecting: \ref[target] Target destroyed.")
// Disconnect and re-emit.
disconnect()
@@ -250,9 +239,7 @@
BM.update_end_icon()
if(istype(AM))
AM.lazy_register_event(/lazy_event/on_moved, BM, .proc/target_moved)
if (!AM.on_destroyed)
AM.on_destroyed = new("owner"=AM)
BM.targetDestroyKey = AM.on_destroyed.Add(BM,"target_destroyed")
AM.lazy_register_event(/lazy_event/on_destroyed, BM, .proc/target_destroyed)
BM.targetDensityKey = AM.on_density_change.Add(BM,"target_density_change")
BM.targetContactLoc = AM.loc
beam_testing("\ref[BM] - Connected to [AM]")
@@ -295,12 +282,9 @@
if(_master.target)
if(ismovable(_master.target))
_master.target.lazy_unregister_event(/lazy_event/on_moved, _master, .proc/target_moved)
if (!_master.target.on_destroyed)
_master.target.on_destroyed = new("owner"=_master.target)
_master.target.on_destroyed.Remove(_master.targetDestroyKey)
_master.target.lazy_unregister_event(/lazy_event/on_destroyed, src, .proc/target_destroyed)
_master.target.beam_disconnect(_master)
_master.target=null
_master.targetDestroyKey=null
//if(_master.next)
// BEAM_DEL(_master.next)
if(re_emit)

View File

@@ -152,18 +152,15 @@
icon_state = "pipe_tomahawk_glass"
item_state = "pipe_tomahawk_glass"
ispipe = 1
var/current_blunt = null
var/obj/item/clothing/mask/cigarette/blunt/rolled/current_blunt = null
var/blunt_name = null
var/is_lit = 0
var/blunt_hook = null //the hook to call the burnout proc when the blunt is destroyed
var/not_burned_out = 0 //prevent the going-out message from qdel()s other than the blunt's own qdel().
slot_flags = SLOT_MASK
/obj/item/weapon/hatchet/tomahawk/pipe/Destroy()
if(blunt_hook && current_blunt)
var/obj/item/clothing/mask/cigarette/blunt/rolled/B = current_blunt
B.on_destroyed.Remove()
if(current_blunt)
current_blunt.lazy_unregister_event(/lazy_event/on_destroyed, src, .proc/burnout)
qdel(current_blunt)
current_blunt = null
..()
@@ -182,7 +179,7 @@
return
to_chat(user, "<span class='notice'>You crush \the [W] into \the [src].</span>")
var/obj/item/clothing/mask/cigarette/blunt/rolled/B = new/obj/item/clothing/mask/cigarette/blunt/rolled(src)
blunt_hook = B.on_destroyed.Add(src, "burnout")
B.lazy_register_event(/lazy_event/on_destroyed, src, .proc/burnout)
B.inside_item = 1
W.reagents.trans_to(B, (W.reagents.total_volume))
B.update_brightness()
@@ -325,7 +322,7 @@
return
to_chat(user, "<span class='notice'>You crush \the [W] into \the [src].</span>")
var/obj/item/clothing/mask/cigarette/blunt/rolled/B = new/obj/item/clothing/mask/cigarette/blunt/rolled(src)
blunt_hook = B.on_destroyed.Add(src, "burnout")
B.lazy_register_event(/lazy_event/on_destroyed, src, .proc/burnout)
B.inside_item = 1
W.reagents.trans_to(B, (W.reagents.total_volume))
B.update_brightness()
@@ -384,7 +381,7 @@
current_blunt = null
verbs -= /obj/item/weapon/broken_pipe_tomahawk/verb/empty_pipe
/obj/item/weapon/broken_pipe_tomahawk/proc/burnout()
/obj/item/weapon/broken_pipe_tomahawk/proc/burnout(datum/thing)
current_blunt = null
set_light(0)
is_lit = 0
@@ -399,4 +396,4 @@
H.update_inv_wear_mask()
verbs -= /obj/item/weapon/broken_pipe_tomahawk/verb/empty_pipe
//BROKEN PIPE TOMAHAWK END
//BROKEN PIPE TOMAHAWK END

View File

@@ -114,13 +114,11 @@
for(var/obj/structure/closet/crate/sokoban/crate in objects)
//check_cheat performs some additional checks first, and only then marks the user as a cheater
crate.on_destroyed.Add(crate, "check_cheat")
crate.lazy_register_event(/lazy_event/on_moved, crate, /obj/structure/closet/crate/sokoban/proc/check_cheat)
crate.parent = src.parent
for(var/obj/structure/sokoban_teleporter/teleporter in objects)
//Teleporters are supposed to be unmovable, so if they're moved or deleted - it's guaranteed cheating
teleporter.on_destroyed.Add(parent, "on_cheat")
teleporter.lazy_register_event(/lazy_event/on_moved, parent, /datum/map_element/vault/sokoban/proc/on_cheat)
if(parent)
@@ -188,6 +186,10 @@ This ladder stuff looks confusing, so here's an illustration!!!
var/datum/map_element/vault/sokoban/parent
/obj/structure/closet/crate/sokoban/Destroy()
check_cheat()
..()
/obj/structure/closet/crate/sokoban/proc/check_cheat(atom/movable/mover)
if(shipped)
return //Teleported crates can be destroyed safely

View File

@@ -238,19 +238,6 @@ var/list/clothing_prices = list() //gets filled on initialize()
/area/vault/supermarket/shop/proc/setup()
spawn()
/*
looping:
for(var/obj/item/I in contents)
for(var/type in shop_prices + circuitboard_prices + clothing_prices)
if(istype(I, type))
I.name = "[I.name] ($[shop_prices[type]])"
I.on_destroyed.Add(src, "item_destroyed") //Only trigger alarm when an item for sale is destroyed
items[I] = shop_prices[type]
continue looping
*/ //This is handled by spawners now
var/area/vault/supermarket/entrance/E = locate(/area/vault/supermarket/entrance)
var/list/protected_objects = list(
/obj/structure/window, //Destroying these objects triggers an alarm
@@ -263,9 +250,7 @@ var/list/clothing_prices = list() //gets filled on initialize()
for(var/atom/movable/AM in (src.contents + E.contents))
if(!is_type_in_list(AM, protected_objects)) continue
if(AM.on_destroyed)
AM.on_destroyed.Add(src, "item_destroyed")
AM.lazy_register_event(/lazy_event/on_destroyed, src, .proc/item_destroyed)
/area/vault/supermarket/shop/Exited(atom/movable/AM, atom/newloc)
..()
@@ -290,8 +275,8 @@ var/list/clothing_prices = list() //gets filled on initialize()
map_element.goods_purchased++
map_element.credits_spent += price
/area/vault/supermarket/shop/proc/item_destroyed(list/params)
var/atom/destroyed = params["atom"]
/area/vault/supermarket/shop/proc/item_destroyed(datum/thing)
var/atom/destroyed = thing
if(istype(destroyed, /obj/item))
if(items.Find(destroyed))
@@ -738,7 +723,7 @@ var/list/clothing_prices = list() //gets filled on initialize()
var/price = to_spawn[new_item_type]
I.name = "[I.name] ($[price])"
I.on_destroyed.Add(S, "item_destroyed") //Only trigger alarm when an item for sale is destroyed
I.lazy_register_event(/lazy_event/on_destroyed, S, /area/vault/supermarket/shop/proc/item_destroyed) //Only trigger alarm when an item for sale is destroyed
S.items[I] = price
@@ -777,4 +762,4 @@ var/list/clothing_prices = list() //gets filled on initialize()
destination = /obj/docking_port/destination/vault/supermarket
/obj/docking_port/destination/vault/supermarket
areaname = "Spessmart"
areaname = "Spessmart"