From 3656217c29282d61da92f61cfeea220c41099bd6 Mon Sep 17 00:00:00 2001 From: YotaXP Date: Mon, 10 Mar 2014 16:19:48 -0400 Subject: [PATCH 1/2] Modified qdel() to accept any datum. The garbage controller no longer bothers nulling out every variable on destroyed objects. An object can opt to not be collected by returning true from Destroy(). Useful for pools or other edge cases. Fixed boxes not being collected, along with a couple other things. Turfs will not be monitored for collection. generate_ion_law() is no longer a /datum proc, and I am an admin in the repo. Deal with it. --- code/_onclick/hud/screen_objects.dm | 4 + code/controllers/garbage.dm | 170 +++++++++--------- code/game/atoms.dm | 12 +- code/game/atoms_movable.dm | 2 +- code/game/gamemodes/blob/blobs/factory.dm | 1 + code/game/gamemodes/blob/theblob.dm | 4 - code/game/gamemodes/nuclear/nuclearbomb.dm | 8 +- .../objects/items/weapons/storage/storage.dm | 2 + code/modules/events/ion_storm.dm | 2 +- code/modules/mob/mob.dm | 2 +- config/admins.txt | 1 + 11 files changed, 101 insertions(+), 107 deletions(-) diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm index 4b1a3e225ea..3ff85556f96 100644 --- a/code/_onclick/hud/screen_objects.dm +++ b/code/_onclick/hud/screen_objects.dm @@ -13,6 +13,10 @@ unacidable = 1 var/obj/master = null //A reference to the object in the slot. Grabs or items, generally. +/obj/screen/Destroy() + master = null + ..() + /obj/screen/text icon = null diff --git a/code/controllers/garbage.dm b/code/controllers/garbage.dm index 95ed79b2723..bffd686bb78 100644 --- a/code/controllers/garbage.dm +++ b/code/controllers/garbage.dm @@ -1,67 +1,31 @@ -#define GC_COLLECTIONS_PER_TICK 100 // how many objects we're going to null the vars of per tick -#define GC_COLLECTION_TIMEOUT 300 // deciseconds to wait to let running procs finish before we just say fuck it and force del() the object -#define GC_DEL_CHECK_PER_TICK 100 // number of tests per tick to make sure our GC'd objects are actually GC'd -#define GC_FORCE_DEL_PER_TICK 20 // max force del() calls per tick +#define GC_COLLECTION_TIMEOUT 300 // deciseconds to wait to let running procs finish before we just say fuck it and force del() the object +#define GC_DEL_CHECK_PER_CYCLE 100 // number of tests per cycle to make sure our GC'd objects are actually GC'd +#define GC_FORCE_DEL_PER_CYCLE 20 // max force del() calls per cycle var/datum/controller/garbage_collector/garbage = new() -var/list/uncollectable_vars=list( -// "bounds", // bounds and its ilk are all caught by the issaved() check later on - "contents", - "gc_destroyed", - "invisibility", - "gender", // Causes runtimes if the logging is on - "parent", - "step_size", -) -// These are the vars left from /vg/'s implementation that aren't const or global -// I dunno how many are necessary but since most of these are numbers anyways, I don't care. /datum/controller/garbage_collector var/dels = 0 // number of del()'s we've done this tick - var/list/queue = list() // list of things that have yet to have all their vars nulled out var/list/destroyed = list() // list of refID's of things that should be garbage collected // refID's are associated with the time at which they time out and need to be manually del() // we do this so we aren't constantly locating them and preventing them from being gc'd -/datum/controller/garbage_collector/proc/AddTrash(var/atom/movable/A) - if(!istype(A)) +/datum/controller/garbage_collector/proc/AddTrash(var/datum/A) + if(!istype(A) || A.gc_destroyed) return // testing("GC: AddTrash([A.type])") - queue |= A - -/datum/controller/garbage_collector/proc/Pop() - var/atom/movable/A = queue[1] - if(!A) - queue.Cut(1, 2) -// testing("GC: Pop() given null") - return - if(!istype(A,/atom/movable)) -// testing("GC: -- Pop() given [A.type] --") - queue.Cut(1, 2) - dels++ - del(A) - return - for(var/vname in A.vars) - if(!issaved(A.vars[vname])) -// testing("GC: Skipping [vname] in [A.type]: it's const|global|tmp") - continue - if(vname in uncollectable_vars) -// testing("GC: Skipping [vname] in [A.type]: it's uncollectable") - continue -// testing("GC: Unsetting [vname] in [A.type]") - A.vars[vname] = null -// testing("GC: Pop([A.type]) - destroyed\[\ref[A]\] = [A.gc_destroyed] current time: [world.time] first:[queue[1]] second:[queue.len > 1 ? "[queue[2]]" : "NOTHING"]") - destroyed["\ref[A]"] = A.gc_destroyed - queue.Cut(1, 2) + A.gc_destroyed = world.time + destroyed["\ref[A]"] = world.time /datum/controller/garbage_collector/proc/process() dels = 0 - var/i - for(i = 1, queue.len && i <= GC_COLLECTIONS_PER_TICK, i++) - Pop() var/time_to_kill = world.time - GC_COLLECTION_TIMEOUT // Anything qdel() but not GC'd BEFORE this time needs to be manually del() - for(i = 1, destroyed.len && i <= GC_DEL_CHECK_PER_TICK, i++) + var/checkRemain = GC_DEL_CHECK_PER_CYCLE + while(destroyed.len && --checkRemain >= 0) + if(dels > GC_FORCE_DEL_PER_CYCLE) +// testing("GC: Reached max force dels per tick [dels] vs [GC_FORCE_DEL_PER_TICK]") + break // Server's already pretty pounded, everything else can wait 2 seconds var/refID = destroyed[1] var/GCd_at_time = destroyed[refID] if(GCd_at_time > time_to_kill) @@ -71,61 +35,93 @@ var/list/uncollectable_vars=list( // testing("GC: [refID] old enough to test: GCd_at_time: [GCd_at_time] time_to_kill: [time_to_kill] current: [world.time]") if(A && A.gc_destroyed == GCd_at_time) // So if something else coincidently gets the same ref, it's not deleted by mistake // Something's still referring to the qdel'd object. Kill it. - if(dels >= GC_FORCE_DEL_PER_TICK) -// testing("GC: Reached max force dels per tick [dels] vs [GC_FORCE_DEL_PER_TICK]") - break // Server's already pretty pounded, everything else can wait 2 seconds - testing("GC: -- \ref[A] | [A.type] was unable to be garbage collected and was force del() --") + testing("GC: -- \ref[A] | [A.type] was unable to be GC'd and was deleted --") del(A) dels++ // else // testing("GC: [refID] properly GC'd at [world.time] with timeout [GCd_at_time]") destroyed.Cut(1, 2) -/** -* NEVER USE THIS FOR ANYTHING OTHER THAN /atom/movable -* OTHER TYPES CANNOT BE QDEL'D BECAUSE THEIR LOC IS LOCKED OR THEY DON'T HAVE ONE. -* While I'm leaving the above comment in since /atoms cannot be garbage collected, datums and lists can be garbage collected just fine. -* Read the DM guide on it. Hit f1 and search for "garbage collection" -*/ -/proc/qdel(var/atom/movable/A) +// Should be treated as a replacement for the 'del' keyword. +// Datums passed to this will be given a chance to clean up references to allow the GC to collect them. +/proc/qdel(var/datum/A) if(!A) return - if(!garbage) - del(A) - return if(!istype(A)) - warning("qdel() passed object of type [A.type]. qdel() can only handle /atom/movable types.") - garbage.dels++ + //warning("qdel() passed object of type [A.type]. qdel() can only handle /datum types.") del(A) - return - // Let our friend know they're about to get fucked up. - A.Destroy() - garbage.AddTrash(A) + if(garbage) + garbage.dels++ + else + // Let our friend know they're about to get fucked up. + . = !A.Destroy() + if(. && A) + if(garbage && !isturf(A)) + garbage.AddTrash(A) + else + del(A) +// Default implementation of clean-up code. +// This should be overridden to remove all references pointing to the object being destroyed. +// Return true if the the GC controller should allow the object to continue existing. (Useful if pooling objects.) +/datum/proc/Destroy() + del(src) -/* -// Uncomment this verb and run it on things to report blockages. -/atom/verb/qdel_test() - set name = "qdel with test" +/datum/var/gc_destroyed //Time when this object was destroyed. + +#ifdef TESTING +/client/var/running_find_references + +/atom/verb/find_references() set category = "Debug" + set name = "Find References" set background = 1 set src in world - qdel(src) - for(var/datum/everything) //Yes this works. - for(var/everyvar in everything.vars) - var/variable = everything.vars[everyvar] + if(!usr || !usr.client) + return + + if(usr.client.running_find_references) + testing("CANCELLED search for references to a [usr.client.running_find_references].") + usr.client.running_find_references = null + return + + if(alert("Running this will create a lot of lag until it finishes. You can cancel it by running it again. Would you like to begin the search?", "Find References", "Yes", "No") == "No") + return + + // Remove this object from the list of things to be auto-deleted. + if(garbage) + garbage.destroyed -= "\ref[src]" + + usr.client.running_find_references = type + testing("Beginning search for references to a [type].") + var/list/things = list() + for(var/client/thing) + things += thing + for(var/datum/thing) + things += thing + for(var/atom/thing) + things += thing + testing("Collected list of things in search for references to a [type]. ([things.len] Thing\s)") + for(var/datum/thing in things) + if(!usr.client.running_find_references) return + for(var/varname in thing.vars) + var/variable = thing.vars[varname] if(variable == src) - testing("Found [src.type] \ref[src] in [everything.type]'s [everyvar] var.") + testing("Found [src.type] \ref[src] in [thing.type]'s [varname] var.") else if(islist(variable)) if(src in variable) - testing("Found [src.type]\ref[src] in [everything.type]'s [everyvar] var.") - for(var/atom/movable/everything) //The slow part. - for(var/everyvar in everything.vars) - var/variable = everything.vars[everyvar] - if(variable == src) - testing("Found [src.type] \ref[src] in [everything.type]'s [everyvar] var.") - else if(islist(variable)) - if(src in variable) - testing("Found [src.type]\ref[src] in [everything.type]'s [everyvar] var.") -*/ \ No newline at end of file + testing("Found [src.type] \ref[src] in [thing.type]'s [varname] list var.") + testing("Completed search for references to a [type].") + usr.client.running_find_references = null + +/client/verb/purge_all_destroyed_objects() + set category = "Debug" + if(garbage) + while(garbage.destroyed.len) + var/datum/o = locate(garbage.destroyed[1]) + if(istype(o) && o.gc_destroyed) + del(o) + garbage.dels++ + garbage.destroyed.Cut(1, 2) +#endif \ No newline at end of file diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 7b8854eb22a..ed72976967f 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -17,9 +17,6 @@ // replaced by OPENCONTAINER flags and atom/proc/is_open_container() ///Chemistry. - // Garbage collection - var/gc_destroyed //Time when this object - /atom/proc/throw_impact(atom/hit_atom) if(istype(hit_atom,/mob/living)) var/mob/living/M = hit_atom @@ -50,15 +47,12 @@ Destroy() ..() -// Like Del(), but for qdel. -// Called BEFORE qdel moves shit. -// Also called on del() -/atom/proc/Destroy() - gc_destroyed = world.time +/atom/Destroy() if(reagents) reagents.delete() - del(reagents) // Technically I think the reagent holder will gc, but let's be careful here and delete all the reagents and the holder too + qdel(reagents) invisibility = 101 + // Do not call ..() /atom/proc/assume_air(datum/gas_mixture/giver) del(giver) diff --git a/code/game/atoms_movable.dm b/code/game/atoms_movable.dm index 02c1879151b..58a9156fb91 100644 --- a/code/game/atoms_movable.dm +++ b/code/game/atoms_movable.dm @@ -35,7 +35,7 @@ loc = null // can never null their loc enough really for(var/atom/movable/AM in contents) qdel(AM) - . = ..() + ..() // Previously known as HasEntered() // This is automatically called when something enters your square diff --git a/code/game/gamemodes/blob/blobs/factory.dm b/code/game/gamemodes/blob/blobs/factory.dm index 24a18f59da0..21a1b044bdf 100644 --- a/code/game/gamemodes/blob/blobs/factory.dm +++ b/code/game/gamemodes/blob/blobs/factory.dm @@ -128,3 +128,4 @@ if(contents) for(var/mob/M in contents) M.loc = src.loc + ..() diff --git a/code/game/gamemodes/blob/theblob.dm b/code/game/gamemodes/blob/theblob.dm index e114c39f09d..e65c33ea4b9 100644 --- a/code/game/gamemodes/blob/theblob.dm +++ b/code/game/gamemodes/blob/theblob.dm @@ -184,10 +184,6 @@ luminosity = 0 health = 21 -/obj/effect/blob/normal/Destroy() - src.loc = null - blobs -= src - /obj/effect/blob/normal/update_icon() if(health <= 0) playsound(src.loc, 'sound/effects/splat.ogg', 50, 1) diff --git a/code/game/gamemodes/nuclear/nuclearbomb.dm b/code/game/gamemodes/nuclear/nuclearbomb.dm index cf4080a840d..9004ddf96e2 100644 --- a/code/game/gamemodes/nuclear/nuclearbomb.dm +++ b/code/game/gamemodes/nuclear/nuclearbomb.dm @@ -207,7 +207,7 @@ var/bomb_set /obj/item/weapon/disk/nuclear/Destroy() if(blobstart.len > 0) - var/obj/D = new /obj/item/weapon/disk/nuclear(pick(blobstart)) - message_admins("[src] has been destroyed. Spawning [D] at ([D.x], [D.y], [D.z]).") - log_game("[src] has been destroyed. Spawning [D] at ([D.x], [D.y], [D.z]).") - ..() + loc = pick(blobstart) + message_admins("[src] has been destroyed. Moving it to ([x], [y], [z]).") + log_game("[src] has been destroyed. Moving it to ([x], [y], [z]).") + return 1 // Cancel destruction. diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index 9fe4356f693..0a8dd56bc59 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -417,6 +417,8 @@ /obj/item/weapon/storage/Destroy() close_all() + qdel(boxes) + qdel(closer) ..() diff --git a/code/modules/events/ion_storm.dm b/code/modules/events/ion_storm.dm index 9b0e6967f96..af4dbb2c68b 100644 --- a/code/modules/events/ion_storm.dm +++ b/code/modules/events/ion_storm.dm @@ -41,7 +41,7 @@ if(prob(botEmagChance)) bot.Emag() -/datum/proc/generate_ion_law(ionMessage) +/proc/generate_ion_law(ionMessage) //Threats are generally bad things, silly or otherwise. Plural. var/ionthreats = pick("ALIENS", "BEARS", "CLOWNS", "XENOS", "PETES", "BOMBS", "FETISHES", "WIZARDS", "SYNDICATE AGENTS", "CENTCOM OFFICERS", "SPACE PIRATES", "TRAITORS", "MONKEYS", "BEES", "CARP", "CRABS", "EELS", "BANDITS", "LIGHTS", "INSECTS", "VIRUSES", "SERIAL KILLERS", "ROGUE CYBORGS", "CORGIS", "SPIDERS", "BUTTS", "NINJAS", "PIRATES", "SPACE NINJAS", "CHANGELINGS", "ZOMBIES", "GOLEMS", "VAMPIRES", "WEREWOLVES", "COWBOYS", "INDIANS", "COMMUNISTS", "SOVIETS", "NERDS", "GRIFFONS", "DINOSAURS", "SMALL BIRDS", "BIRDS OF PREY", "OWLS", "VELOCIRAPTORS", "DARK GODS", "HORRORTERRORS", "ILLEGAL IMMIGRANTS", "DRUGS", "MEXICANS", "CANADIANS", "HULKS", "SLIMES", "SKELETONS", "CAPITALISTS", "SINGULARITIES", "ANGRY BLACK MEN", "GODS", "THIEVES", "ASSHOLES", "TERRORISTS", "SNOWMEN", "PINE TREES", "UNKNOWN CREATURES", "THINGS UNDER THE BED", "BOOGEYMEN", "PREDATORS", "PACKETS", "ARTIFICIAL PRESERVATIVES") //Objects are anything that can be found on the station or elsewhere, plural. diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 8ed2822ce7b..e4d3626f718 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -599,7 +599,7 @@ var/list/slot_equipment_priority = list( \ stat(null,"Obj-[master_controller.objects_cost]\t#[processing_objects.len]") stat(null,"Net-[master_controller.networks_cost]\tPnet-[master_controller.powernets_cost]") stat(null,"NanoUI-[master_controller.nano_cost]\t#[nanomanager.processing_uis.len]") - stat(null,"GC-[master_controller.gc_cost]\t#[garbage.destroyed.len + garbage.queue.len]-#dels[garbage.dels]") + stat(null,"GC-[master_controller.gc_cost]\t#[garbage.destroyed.len]-#dels[garbage.dels]") stat(null,"Tick-[master_controller.ticker_cost]\tALL-[master_controller.total_cost]") else stat(null,"MasterController-ERROR") diff --git a/config/admins.txt b/config/admins.txt index c8846e169f8..e7e65d1657d 100644 --- a/config/admins.txt +++ b/config/admins.txt @@ -55,3 +55,4 @@ rumia29 = Game Master bobylein = Game Master sirbayer = Game Master hornygranny = Game Master +yota = Game Master From 1db872f61ddbda931ccc644a0cab92b5cc444322 Mon Sep 17 00:00:00 2001 From: YotaXP Date: Mon, 24 Mar 2014 13:37:13 -0400 Subject: [PATCH 2/2] Undid the silly rename I made weeks ago. Prevented repeated qdel calls from calling Destroy multiple times for non-pooled objects. Ensured that newly qdel'd objects are added to the end of the `destroyed` list. --- code/controllers/garbage.dm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/code/controllers/garbage.dm b/code/controllers/garbage.dm index bffd686bb78..f6e22ac25fa 100644 --- a/code/controllers/garbage.dm +++ b/code/controllers/garbage.dm @@ -1,6 +1,6 @@ -#define GC_COLLECTION_TIMEOUT 300 // deciseconds to wait to let running procs finish before we just say fuck it and force del() the object -#define GC_DEL_CHECK_PER_CYCLE 100 // number of tests per cycle to make sure our GC'd objects are actually GC'd -#define GC_FORCE_DEL_PER_CYCLE 20 // max force del() calls per cycle +#define GC_COLLECTION_TIMEOUT 300 // deciseconds to wait to let running procs finish before we just say fuck it and force del() the object +#define GC_DEL_CHECK_PER_TICK 100 // number of tests per master controller tick to make sure our GC'd objects are actually GC'd +#define GC_FORCE_DEL_PER_TICK 20 // max force del() calls per master controller tick var/datum/controller/garbage_collector/garbage = new() @@ -12,18 +12,19 @@ var/datum/controller/garbage_collector/garbage = new() // we do this so we aren't constantly locating them and preventing them from being gc'd /datum/controller/garbage_collector/proc/AddTrash(var/datum/A) - if(!istype(A) || A.gc_destroyed) + if(!istype(A) || !isnull(A.gc_destroyed)) return // testing("GC: AddTrash([A.type])") A.gc_destroyed = world.time + destroyed -= "\ref[A]" // Removing any previous references that were GC'd so that the current object will be at the end of the list. destroyed["\ref[A]"] = world.time /datum/controller/garbage_collector/proc/process() dels = 0 var/time_to_kill = world.time - GC_COLLECTION_TIMEOUT // Anything qdel() but not GC'd BEFORE this time needs to be manually del() - var/checkRemain = GC_DEL_CHECK_PER_CYCLE + var/checkRemain = GC_DEL_CHECK_PER_TICK while(destroyed.len && --checkRemain >= 0) - if(dels > GC_FORCE_DEL_PER_CYCLE) + if(dels > GC_FORCE_DEL_PER_TICK) // testing("GC: Reached max force dels per tick [dels] vs [GC_FORCE_DEL_PER_TICK]") break // Server's already pretty pounded, everything else can wait 2 seconds var/refID = destroyed[1] @@ -52,7 +53,7 @@ var/datum/controller/garbage_collector/garbage = new() del(A) if(garbage) garbage.dels++ - else + else if(isnull(A.gc_destroyed)) // Let our friend know they're about to get fucked up. . = !A.Destroy() if(. && A)