Explosion Optimizations

Implements a trange that internally checks only turfs and thus less
intensive.

Conflicts:
	code/game/objects/explosion.dm
This commit is contained in:
ChuckTheSheep
2014-01-04 19:29:17 -05:00
committed by Mloc-Argent
parent dfdeed7434
commit 533600eaa5
2 changed files with 31 additions and 40 deletions

View File

@@ -6,31 +6,12 @@
/obj
var/explosion_resistance
/datum/explosion_turf
var/turf/turf //The turf which will get ex_act called on it
var/max_power //The largest amount of power the turf sustained
New()
..()
max_power = 0
proc/save_power_if_larger(power)
if(power > max_power)
max_power = power
return 1
return 0
var/list/explosion_turfs = list()
var/list/datum/explosion_turf/explosion_turfs = list()
var/explosion_in_progress = 0
proc/get_explosion_turf(var/turf/T)
for( var/datum/explosion_turf/ET in explosion_turfs )
if( T == ET.turf )
return ET
var/datum/explosion_turf/ET = new()
ET.turf = T
explosion_turfs += ET
return ET
proc/explosion_rec(turf/epicenter, power)
@@ -52,9 +33,8 @@ proc/explosion_rec(turf/epicenter, power)
explosion_in_progress = 1
explosion_turfs = list()
var/datum/explosion_turf/ETE = get_explosion_turf()
ETE.turf = epicenter
ETE.max_power = power
explosion_turfs[epicenter] = power
//This steap handles the gathering of turfs which will be ex_act() -ed in the next step. It also ensures each turf gets the maximum possible amount of power dealt to it.
for(var/direction in cardinal)
@@ -62,22 +42,21 @@ proc/explosion_rec(turf/epicenter, power)
T.explosion_spread(power - epicenter.explosion_resistance, direction)
//This step applies the ex_act effects for the explosion, as planned in the previous step.
for( var/datum/explosion_turf/ET in explosion_turfs )
if(ET.max_power <= 0) continue
if(!ET.turf) continue
for(var/turf/T in explosion_turfs)
if(explosion_turfs[T] <= 0) continue
if(!T) continue
//Wow severity looks confusing to calculate... Fret not, I didn't leave you with any additional instructions or help. (just kidding, see the line under the calculation)
var/severity = 4 - round(max(min( 3, ((ET.max_power - ET.turf.explosion_resistance) / (max(3,(power/3)))) ) ,1), 1)
//sanity effective power on tile divided by either 3 or one third the total explosion power
var/severity = 4 - round(max(min( 3, ((explosion_turfs[T] - T.explosion_resistance) / (max(3,(power/3)))) ) ,1), 1) //sanity effective power on tile divided by either 3 or one third the total explosion power
// One third because there are three power levels and I
// want each one to take up a third of the crater
var/x = ET.turf.x
var/y = ET.turf.y
var/z = ET.turf.z
ET.turf.ex_act(severity)
if(!ET.turf)
ET.turf = locate(x,y,z)
for( var/atom/A in ET.turf )
var/x = T.x
var/y = T.y
var/z = T.z
T.ex_act(severity)
if(!T)
T = locate(x,y,z)
for(var/atom/A in T)
A.ex_act(severity)
explosion_in_progress = 0
@@ -123,10 +102,9 @@ proc/explosion_rec(turf/epicenter, power)
new/obj/effect/debugging/marker(src)
*/
var/datum/explosion_turf/ET = get_explosion_turf(src)
if(ET.max_power >= power)
if(explosion_turfs[src] >= power)
return //The turf already sustained and spread a power greated than what we are dealing with. No point spreading again.
ET.max_power = power
explosion_turfs[src] = power
var/spread_power = power - src.explosion_resistance //This is the amount of power that will be spread to the tile in the direction of the blast
var/side_spread_power = power - 2 * src.explosion_resistance //This is the amount of power that will be spread to the side tiles