Some performance improvements and cleanup to radiation

This commit is contained in:
ninjanomnom
2018-07-24 09:50:00 -04:00
parent 5afaad1a78
commit efae41db60
4 changed files with 41 additions and 28 deletions
+5
View File
@@ -63,6 +63,11 @@
#define COMSIG_ATOM_DIR_CHANGE "atom_dir_change" //from base of atom/setDir(): (old_dir, new_dir)
#define COMSIG_ATOM_CONTENTS_DEL "atom_contents_del" //from base of atom/handle_atom_del(): (atom/deleted)
#define COMSIG_ATOM_HAS_GRAVITY "atom_has_gravity" //from base of atom/has_gravity(): (turf/location, list/forced_gravities)
#define COMSIG_ATOM_RAD_PROBE "atom_rad_probe" //from proc/get_rad_contents(): ()
#define COMPONENT_BLOCK_RADIATION 1
#define COMSIG_ATOM_RAD_CONTAMINATING "atom_rad_contam" //from base of datum/radiation_wave/radiate(): (strength)
#define COMPONENT_BLOCK_CONTAMINATION 1
#define COMSIG_ATOM_RAD_WAVE_PASSING "atom_rad_wave_pass" //from base of datum/radiation_wave/check_obstructions(): (datum/radiation_wave, width)
/////////////////
#define COMSIG_ATOM_ATTACK_GHOST "atom_attack_ghost" //from base of atom/attack_ghost(): (mob/dead/observer/ghost)
#define COMSIG_ATOM_ATTACK_HAND "atom_attack_hand" //from base of atom/attack_hand(): (mob/user)
+10 -12
View File
@@ -1,26 +1,24 @@
// A special GetAllContents that doesn't search past things with rad insulation
// The protection var only protects the things inside from being affected.
// The protecting object itself will get returned still.
// Components which return COMPONENT_BLOCK_RADIATION prevent further searching into that object's contents. The object itself will get returned still.
// The ignore list makes those objects never return at all
/proc/get_rad_contents(atom/location)
var/static/list/ignored_things = typecacheof(list(
/mob/dead,
/mob/camera,
/obj/effect,
/obj/docking_port,
/atom/movable/lighting_object,
/obj/item/projectile,
))
var/list/processing_list = list(location)
. = list()
while(processing_list.len)
var/static/list/ignored_things = typecacheof(list(
/mob/dead,
/mob/camera,
/obj/effect,
/obj/docking_port,
/atom/movable/lighting_object,
/obj/item/projectile
))
var/atom/thing = processing_list[1]
processing_list -= thing
if(ignored_things[thing.type])
continue
. += thing
var/datum/component/rad_insulation/insulation = thing.GetComponent(/datum/component/rad_insulation)
if(insulation && insulation.protects)
if(SEND_SIGNAL(thing, COMSIG_ATOM_RAD_PROBE) & COMPONENT_BLOCK_RADIATION)
continue
processing_list += thing.contents
+21 -6
View File
@@ -1,9 +1,24 @@
/datum/component/rad_insulation // Yes, this really is just a component to add some vars
/datum/component/rad_insulation
var/amount // Multiplier for radiation strength passing through
var/protects // Does this protect things in its contents from being affected?
var/contamination_proof // Can this object be contaminated?
/datum/component/rad_insulation/Initialize(_amount=RAD_MEDIUM_INSULATION, _protects=TRUE, _contamination_proof=TRUE)
/datum/component/rad_insulation/Initialize(_amount=RAD_MEDIUM_INSULATION, protects=TRUE, contamination_proof=TRUE)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
if(protects) // Does this protect things in its contents from being affected?
RegisterSignal(parent, COMSIG_ATOM_RAD_PROBE, .proc/rad_probe_react)
if(contamination_proof) // Can this object be contaminated?
RegisterSignal(parent, COMSIG_ATOM_RAD_CONTAMINATING, .proc/rad_contaminating)
if(_amount != 1) // If it's 1 it wont have any impact on radiation passing through anyway
RegisterSignal(parent, COMSIG_ATOM_RAD_WAVE_PASSING, .proc/rad_pass)
amount = _amount
protects = _protects
contamination_proof = _contamination_proof
/datum/component/rad_insulation/proc/rad_probe_react()
return COMPONENT_BLOCK_RADIATION
/datum/component/rad_insulation/proc/rad_contaminating(strength)
return COMPONENT_BLOCK_CONTAMINATION
/datum/component/rad_insulation/proc/rad_pass(datum/radiation_wave/wave, width)
wave.intensity = wave.intensity*(1-((1-amount)/width)) // The further out the rad wave goes the less it's affected by insulation (larger width)
+5 -10
View File
@@ -80,12 +80,10 @@
var/atom/thing = atoms[k]
if(!thing)
continue
var/datum/component/rad_insulation/insulation = thing.GetComponent(/datum/component/rad_insulation)
if(!insulation)
continue
intensity = intensity*(1-((1-insulation.amount)/width)) // The further out the rad wave goes the less it's affected by insulation
SEND_SIGNAL(thing, COMSIG_ATOM_RAD_WAVE_PASSING, src, width)
/datum/radiation_wave/proc/radiate(list/atoms, strength)
var/contamination_chance = (strength-RAD_MINIMUM_CONTAMINATION) * RAD_CONTAMINATION_CHANCE_COEFFICIENT * min(1, 1/(steps*range_modifier))
for(var/k in 1 to atoms.len)
var/atom/thing = atoms[k]
if(!thing)
@@ -106,11 +104,8 @@
))
if(!can_contaminate || blacklisted[thing.type])
continue
var/contamination_chance = (strength-RAD_MINIMUM_CONTAMINATION) * RAD_CONTAMINATION_CHANCE_COEFFICIENT * min(1, 1/(steps*range_modifier))
if(prob(contamination_chance)) // Only stronk rads get to have little baby rads
var/datum/component/rad_insulation/insulation = thing.GetComponent(/datum/component/rad_insulation)
if(insulation && insulation.contamination_proof)
if(SEND_SIGNAL(thing, COMSIG_ATOM_RAD_CONTAMINATING, strength) & COMPONENT_BLOCK_CONTAMINATION)
continue
else
var/rad_strength = (strength-RAD_MINIMUM_CONTAMINATION) * RAD_CONTAMINATION_STR_COEFFICIENT
thing.AddComponent(/datum/component/radioactive, rad_strength, source)
var/rad_strength = (strength-RAD_MINIMUM_CONTAMINATION) * RAD_CONTAMINATION_STR_COEFFICIENT
thing.AddComponent(/datum/component/radioactive, rad_strength, source)