Files
CHOMPStation2/code/controllers/Processes/radiation.dm
Leshana 2c8df87899 Tweak to Radiation Optimization
* Optimized garbage collection of radiation sources until we get qdel() hints.
* Made the RADIATION_LOWER_LIMIT configurable (option for people to save some cpu time)
* Added some comments and broke the proccessor into separate procs for profiling purposes
* Added a changelog.
2017-05-30 13:55:53 -04:00

57 lines
1.8 KiB
Plaintext

/datum/controller/process/radiation
var/repository/radiation/linked = null
/datum/controller/process/radiation/setup()
name = "radiation controller"
schedule_interval = 20 // every 2 seconds
linked = radiation_repository
/datum/controller/process/radiation/doWork()
sources_decay()
cache_expires()
irradiate_targets()
// Step 1 - Sources Decay
/datum/controller/process/radiation/proc/sources_decay()
var/list/sources = linked.sources
for(var/thing in sources)
if(deleted(thing))
sources.Remove(thing)
continue
var/datum/radiation_source/S = thing
if(S.decay)
S.update_rad_power(S.rad_power - config.radiation_decay_rate)
if(S.rad_power <= config.radiation_lower_limit)
sources.Remove(S)
SCHECK // This scheck probably just wastes resources, but better safe than sorry in this case.
// Step 2 - Cache Expires
/datum/controller/process/radiation/proc/cache_expires()
var/list/resistance_cache = linked.resistance_cache
for(var/thing in resistance_cache)
if(deleted(thing))
resistance_cache.Remove(thing)
continue
var/turf/T = thing
if((length(T.contents) + 1) != resistance_cache[T])
resistance_cache.Remove(T) // If its stale REMOVE it! It will get added if its needed.
SCHECK
// Step 3 - Registered irradiatable things are checked for radiation
/datum/controller/process/radiation/proc/irradiate_targets()
var/list/registered_listeners = living_mob_list // For now just use this. Nothing else is interested anyway.
if(length(linked.sources) > 0)
for(var/thing in registered_listeners)
if(deleted(thing))
continue
var/atom/A = thing
var/turf/T = get_turf(thing)
var/rads = linked.get_rads_at_turf(T)
if(rads)
A.rad_act(rads)
SCHECK
/datum/controller/process/radiation/statProcess()
..()
stat(null, "[linked.sources.len] sources, [linked.resistance_cache.len] cached turfs")