Optimization/Rewrite of Radiation Controller

* The performance of the radiation controller as-is was not fast enough for inclusion in production servers, but it has some nice featuers, so rewrote it to be more performant.
* Instead of storing the radiation strength for every turf, we only store the sources of radiation, and calculate the strength only for mobs who might be in range.
   * Old method was ray-tracing to every turf in range whether anything was there to be irradiated or not.  Could be hundreds of turfs.  New method only lazily calcualtes strength at a turf if we actually need to know it.   Often times this is zero turfs if nobody is standing in engineering.
  * Removed the automatic processing of objects with "rad_power" set.  Objects are responsible for calling the repository to create/update their radiation sources.   Saves some extra overhead that in practice was redundant with other process controllers.
  * Also tweaked to be more respectful of qdel'd objects and added some comments.
This commit is contained in:
Leshana
2017-05-24 16:37:06 -04:00
parent b1250a4391
commit 34c73dab69
16 changed files with 172 additions and 150 deletions

View File

@@ -7,37 +7,43 @@
linked = radiation_repository
/datum/controller/process/radiation/doWork()
// set background = 1
for(var/turf/T in linked.irradiated_turfs)
if(!T)
linked.irradiated_turfs.Remove(T)
// Step 1 - Sources Decay
var/list/sources = linked.sources
for(var/thing in sources)
if(deleted(thing))
sources.Remove(thing)
continue
linked.irradiated_turfs[T] -= config.radiation_decay_rate
if(linked.irradiated_turfs[T] <= config.radiation_lower_limit)
linked.irradiated_turfs.Remove(T)
SCHECK
for(var/mob/living/L in linked.irradiated_mobs)
if(!L)
linked.irradiated_mobs.Remove(L)
continue
if(get_turf(L) in linked.irradiated_turfs)
L.rad_act(linked.irradiated_turfs[get_turf(L)])
if(!L.radiation)
linked.irradiated_mobs.Remove(L)
SCHECK
for(var/thing in linked.sources)
if(!thing)
linked.sources.Remove(thing)
continue
var/atom/emitter = thing
linked.radiate(emitter, emitter.rad_power)
to_process.Cut()
SCHECK
for(var/thing in linked.resistance_cache)
if(!thing)
linked.resistance_cache.Remove(thing)
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
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) != linked.resistance_cache[T])
T.calc_rad_resistance()
SCHECK
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
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")