Merge branch 'master' of https://github.com/tgstation/-tg-station into warnstandardization

Conflicts:
	code/_onclick/telekinesis.dm
	code/game/sound.dm
This commit is contained in:
Miauw
2014-03-30 20:48:03 +02:00
337 changed files with 34182 additions and 32968 deletions

View File

@@ -1,131 +1,128 @@
#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
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))
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)
/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/refID = destroyed[1]
var/GCd_at_time = destroyed[refID]
if(GCd_at_time > time_to_kill)
// testing("GC: [refID] not old enough, breaking at [world.time] for [GCd_at_time - time_to_kill] deciseconds until [GCd_at_time + GC_COLLECTION_TIMEOUT]")
break // Everything else is newer, skip them
var/atom/A = locate(refID)
// 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() --")
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)
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++
del(A)
return
// Let our friend know they're about to get fucked up.
A.Destroy()
garbage.AddTrash(A)
/*
// Uncomment this verb and run it on things to report blockages.
/atom/verb/qdel_test()
set name = "qdel with test"
set category = "Debug"
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(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.")
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.")
*/
#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()
/datum/controller/garbage_collector
var/dels = 0 // number of del()'s we've done this tick
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/datum/A)
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_TICK
while(destroyed.len && --checkRemain >= 0)
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]
var/GCd_at_time = destroyed[refID]
if(GCd_at_time > time_to_kill)
// testing("GC: [refID] not old enough, breaking at [world.time] for [GCd_at_time - time_to_kill] deciseconds until [GCd_at_time + GC_COLLECTION_TIMEOUT]")
break // Everything else is newer, skip them
var/atom/A = locate(refID)
// 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.
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)
// 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(!istype(A))
//warning("qdel() passed object of type [A.type]. qdel() can only handle /datum types.")
del(A)
if(garbage)
garbage.dels++
else if(isnull(A.gc_destroyed))
// 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)
/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
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 [thing.type]'s [varname] var.")
else if(islist(variable))
if(src in variable)
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

View File

@@ -1,84 +1,84 @@
//TODO: rewrite and standardise all controller datums to the datum/controller type
//TODO: allow all controllers to be deleted for clean restarts (see WIP master controller stuff) - MC done - lighting done
/client/proc/restart_controller(controller in list("Master","Failsafe","Lighting","Supply Shuttle"))
set category = "Debug"
set name = "Restart Controller"
set desc = "Restart one of the various periodic loop controllers for the game (be careful!)"
if(!holder) return
usr = null
src = null
switch(controller)
if("Master")
new /datum/controller/game_controller()
master_controller.process()
feedback_add_details("admin_verb","RMC")
if("Failsafe")
new /datum/controller/failsafe()
feedback_add_details("admin_verb","RFailsafe")
if("Lighting")
new /datum/controller/lighting()
lighting_controller.process()
feedback_add_details("admin_verb","RLighting")
if("Supply Shuttle")
supply_shuttle.process()
feedback_add_details("admin_verb","RSupply")
message_admins("Admin [key_name_admin(usr)] has restarted the [controller] controller.")
return
/client/proc/debug_controller(controller in list("Master","Failsafe","Ticker","Lighting","Garbage","Air","Jobs","Sun","Radio","Supply Shuttle","Emergency Shuttle","Configuration","pAI", "Cameras", "Events"))
set category = "Debug"
set name = "Debug Controller"
set desc = "Debug the various periodic loop controllers for the game (be careful!)"
if(!holder) return
switch(controller)
if("Master")
debug_variables(master_controller)
feedback_add_details("admin_verb","DMC")
if("Failsafe")
debug_variables(Failsafe)
feedback_add_details("admin_verb","DFailsafe")
if("Ticker")
debug_variables(ticker)
feedback_add_details("admin_verb","DTicker")
if("Lighting")
debug_variables(lighting_controller)
feedback_add_details("admin_verb","DLighting")
if("Garbage")
debug_variables(garbage)
feedback_add_details("admin_verb","DGarbage")
if("Air")
debug_variables(air_master)
feedback_add_details("admin_verb","DAir")
if("Jobs")
debug_variables(job_master)
feedback_add_details("admin_verb","DJobs")
if("Sun")
debug_variables(sun)
feedback_add_details("admin_verb","DSun")
if("Radio")
debug_variables(radio_controller)
feedback_add_details("admin_verb","DRadio")
if("Supply Shuttle")
debug_variables(supply_shuttle)
feedback_add_details("admin_verb","DSupply")
if("Emergency Shuttle")
debug_variables(emergency_shuttle)
feedback_add_details("admin_verb","DEmergency")
if("Configuration")
debug_variables(config)
feedback_add_details("admin_verb","DConf")
if("pAI")
debug_variables(paiController)
feedback_add_details("admin_verb","DpAI")
if("Cameras")
debug_variables(cameranet)
feedback_add_details("admin_verb","DCameras")
if("Events")
debug_variables(events)
feedback_add_details("admin_verb","DEvents")
message_admins("Admin [key_name_admin(usr)] is debugging the [controller] controller.")
return
//TODO: rewrite and standardise all controller datums to the datum/controller type
//TODO: allow all controllers to be deleted for clean restarts (see WIP master controller stuff) - MC done - lighting done
/client/proc/restart_controller(controller in list("Master","Failsafe","Lighting","Supply Shuttle"))
set category = "Debug"
set name = "Restart Controller"
set desc = "Restart one of the various periodic loop controllers for the game (be careful!)"
if(!holder) return
usr = null
src = null
switch(controller)
if("Master")
new /datum/controller/game_controller()
master_controller.process()
feedback_add_details("admin_verb","RMC")
if("Failsafe")
new /datum/controller/failsafe()
feedback_add_details("admin_verb","RFailsafe")
if("Lighting")
new /datum/controller/lighting()
lighting_controller.process()
feedback_add_details("admin_verb","RLighting")
if("Supply Shuttle")
supply_shuttle.process()
feedback_add_details("admin_verb","RSupply")
message_admins("Admin [key_name_admin(usr)] has restarted the [controller] controller.")
return
/client/proc/debug_controller(controller in list("Master","Failsafe","Ticker","Lighting","Garbage","Air","Jobs","Sun","Radio","Supply Shuttle","Emergency Shuttle","Configuration","pAI", "Cameras", "Events"))
set category = "Debug"
set name = "Debug Controller"
set desc = "Debug the various periodic loop controllers for the game (be careful!)"
if(!holder) return
switch(controller)
if("Master")
debug_variables(master_controller)
feedback_add_details("admin_verb","DMC")
if("Failsafe")
debug_variables(Failsafe)
feedback_add_details("admin_verb","DFailsafe")
if("Ticker")
debug_variables(ticker)
feedback_add_details("admin_verb","DTicker")
if("Lighting")
debug_variables(lighting_controller)
feedback_add_details("admin_verb","DLighting")
if("Garbage")
debug_variables(garbage)
feedback_add_details("admin_verb","DGarbage")
if("Air")
debug_variables(air_master)
feedback_add_details("admin_verb","DAir")
if("Jobs")
debug_variables(job_master)
feedback_add_details("admin_verb","DJobs")
if("Sun")
debug_variables(sun)
feedback_add_details("admin_verb","DSun")
if("Radio")
debug_variables(radio_controller)
feedback_add_details("admin_verb","DRadio")
if("Supply Shuttle")
debug_variables(supply_shuttle)
feedback_add_details("admin_verb","DSupply")
if("Emergency Shuttle")
debug_variables(emergency_shuttle)
feedback_add_details("admin_verb","DEmergency")
if("Configuration")
debug_variables(config)
feedback_add_details("admin_verb","DConf")
if("pAI")
debug_variables(paiController)
feedback_add_details("admin_verb","DpAI")
if("Cameras")
debug_variables(cameranet)
feedback_add_details("admin_verb","DCameras")
if("Events")
debug_variables(events)
feedback_add_details("admin_verb","DEvents")
message_admins("Admin [key_name_admin(usr)] is debugging the [controller] controller.")
return