Explosions and singulo use spiral range (and other changes)

This commit is contained in:
MrStonedOne
2016-03-15 03:39:41 -07:00
parent 257d3eb701
commit 09fb8c2b10
14 changed files with 99 additions and 43 deletions
+53
View File
@@ -1194,6 +1194,59 @@ B --><-- A
return L
//similar function to RANGE_TURFS(), but will search spiralling outwards from the center (like the above, but only turfs)
/proc/spiral_range_turfs(dist=0, center=usr, orange=0)
if(!dist)
if(!orange)
return list(center)
else
return list()
var/turf/t_center = get_turf(center)
if(!t_center)
return list()
var/list/L = list()
var/turf/T
var/y
var/x
var/c_dist = 1
if(!orange)
L += t_center
while( c_dist <= dist )
y = t_center.y + c_dist
x = t_center.x - c_dist + 1
for(x in x to t_center.x+c_dist)
T = locate(x,y,t_center.z)
if(T)
L += T
y = t_center.y + c_dist - 1
x = t_center.x + c_dist
for(y in t_center.y-c_dist to y)
T = locate(x,y,t_center.z)
if(T)
L += T
y = t_center.y - c_dist
x = t_center.x + c_dist - 1
for(x in t_center.x-c_dist to x)
T = locate(x,y,t_center.z)
if(T)
L += T
y = t_center.y - c_dist + 1
x = t_center.x - c_dist
for(y in y to t_center.y+c_dist)
T = locate(x,y,t_center.z)
if(T)
L += T
c_dist++
return L
/atom/proc/contains(var/atom/A)
if(!A)
return 0
+10 -11
View File
@@ -13,9 +13,7 @@ var/global/datum/controller/master/Master = new()
/datum/controller/master
name = "Master"
// The minimum length of time between MC ticks (in deciseconds).
// The highest this can be without affecting schedules is the GCD of all subsystem waits.
// Set to 0 to disable all processing.
// are we processing (higher values increase the processing delay)
var/processing = 1
// The iteration of the MC.
var/iteration = 0
@@ -158,8 +156,8 @@ var/global/datum/controller/master/Master = new()
#endif
break
#if DM_VERSION >= 510
if (priorityrunning)
if (!priority_queue.len || !(SS in priority_queue))
if(priorityrunning)
if(!priority_queue.len || !(SS in priority_queue))
priorityrunning = 0 //end of priority queue items
else
priority_queue -= SS
@@ -167,8 +165,9 @@ var/global/datum/controller/master/Master = new()
if(SS.can_fire > 0)
if(priorityrunning || ((SS.next_fire <= world.time) && (SS.last_fire + (SS.wait * 0.75) <= world.time)))
#if DM_VERSION >= 510
if ((world.tick_usage + SS.tick_usage > 75) && (SS.last_fire + (SS.wait*1.25) > world.time))
priority_queue += SS
if(!priorityrunning && (world.tick_usage + SS.tick_usage > 75) && (SS.last_fire + (SS.wait*1.25) > world.time))
if(!SS.dynamic_wait)
priority_queue += SS
continue
#endif
//we can't reset SS.paused after we fire, incase it pauses again, so we cache it and
@@ -184,10 +183,10 @@ var/global/datum/controller/master/Master = new()
#endif
SS.fire(paused) // Fire the subsystem
#if DM_VERSION >= 510
if (priorityrunning)
if(priorityrunning)
priorityrunning--
var/newusage = max(world.tick_usage - tick_usage, 0)
if (newusage < SS.tick_usage)
if(newusage < SS.tick_usage)
SS.tick_usage = MC_AVERAGE_SLOW(SS.tick_usage,world.tick_usage - tick_usage)
else
SS.tick_usage = MC_AVERAGE_FAST(SS.tick_usage,world.tick_usage - tick_usage)
@@ -204,9 +203,9 @@ var/global/datum/controller/master/Master = new()
SS.wait = Clamp(newwait, SS.dwait_lower, SS.dwait_upper)
SS.next_fire = world.time + SS.wait
else
if (!paused)
if(!paused)
SS.next_fire += SS.wait
if (!SS.paused)
if(!SS.paused)
SS.times_fired++
#if DM_VERSION < 510
sleep(0)
+7 -5
View File
@@ -19,7 +19,7 @@ var/datum/subsystem/air/SSair
var/list/excited_groups = list()
var/list/active_turfs = list()
var/list/processing = list()
var/list/currentrun = list()
var/list/hotspots = list()
var/list/networks = list()
var/list/obj/machinery/atmos_machinery = list()
@@ -132,10 +132,12 @@ var/datum/subsystem/air/SSair
//cache for sanic speed
var/fire_count = times_fired
if (!resumed)
processing = active_turfs.Copy()
while(processing.len)
var/turf/simulated/T = processing[1]
processing.Cut(1, 2)
src.currentrun = active_turfs.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/turf/simulated/T = currentrun[1]
currentrun.Cut(1, 2)
if (T)
T.process_cell(fire_count)
if (MC_TICK_CHECK)
+2 -1
View File
@@ -60,6 +60,7 @@ var/datum/subsystem/garbage_collector/SSgarbage
//If you see this proc high on the profile, what you are really seeing is the garbage collection/soft delete overhead in byond.
//Don't attempt to optimize, not worth the effort.
/datum/subsystem/garbage_collector/proc/HandleToBeQueued(time_to_stop)
var/list/tobequeued = src.tobequeued
while(tobequeued.len && world.timeofday < time_to_stop)
if (MC_TICK_CHECK)
break
@@ -71,7 +72,7 @@ var/datum/subsystem/garbage_collector/SSgarbage
delslasttick = 0
gcedlasttick = 0
var/time_to_kill = world.time - collection_timeout // Anything qdel() but not GC'd BEFORE this time needs to be manually del()
var/list/queue = src.queue
while(queue.len && world.timeofday < time_to_stop)
if (MC_TICK_CHECK)
break
+2
View File
@@ -31,6 +31,7 @@ var/datum/subsystem/lighting/SSlighting
//Any light that returns 1 in check() deletes itself
//By using queues we are ensuring we don't perform more updates than are necessary
/datum/subsystem/lighting/fire(resumed = 0)
var/list/changed_lights = src.changed_lights
if (!resumed)
changed_lights_workload = MC_AVERAGE(changed_lights_workload, changed_lights.len)
while (changed_lights.len)
@@ -40,6 +41,7 @@ var/datum/subsystem/lighting/SSlighting
if (MC_TICK_CHECK)
return
var/list/changed_turfs = src.changed_turfs
if (!resumed)
changed_turfs_workload = MC_AVERAGE(changed_turfs_workload, changed_turfs.len)
while (changed_turfs.len)
+5 -1
View File
@@ -38,7 +38,11 @@ var/datum/subsystem/machines/SSmachine
if (!resumed)
for(var/datum/powernet/Powernet in powernets)
Powernet.reset() //reset the power state.
currentrun = processing.Copy()
src.currentrun = processing.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
var/seconds = wait * 0.1
while(currentrun.len)
var/datum/thing = currentrun[1]
+5 -1
View File
@@ -18,7 +18,11 @@ var/datum/subsystem/mobs/SSmob
/datum/subsystem/mobs/fire(resumed = 0)
var/seconds = wait * 0.1
if (!resumed)
currentrun = mob_list.Copy()
src.currentrun = mob_list.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/mob/M = currentrun[1]
currentrun.Cut(1, 2)
+4 -1
View File
@@ -32,7 +32,10 @@ var/datum/subsystem/objects/SSobj
/datum/subsystem/objects/fire(resumed = 0)
if (!resumed)
currentrun = processing.Copy()
src.currentrun = processing.Copy()
//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun
while(currentrun.len)
var/datum/thing = currentrun[1]
currentrun.Cut(1, 2)
+1
View File
@@ -182,6 +182,7 @@
/atom/proc/contents_explosion(severity, target)
for(var/atom/A in contents)
A.ex_act(severity, target)
CHECK_TICK
/atom/proc/ex_act(severity, target)
contents_explosion(severity, target)
@@ -186,7 +186,7 @@
/datum/effect_system/smoke_spread/freezing/start()
if(blast)
for(var/turf/T in trange(2, location))
for(var/turf/T in RANGE_TURFS(2, location))
Chilled(T)
..()
+5 -17
View File
@@ -1,18 +1,5 @@
//TODO: Flash range does nothing currently
/proc/trange(Dist=0,turf/Center=null)//alternative to range (ONLY processes turfs and thus less intensive)
if(Center==null) return
//var/x1=((Center.x-Dist)<1 ? 1 : Center.x-Dist)
//var/y1=((Center.y-Dist)<1 ? 1 : Center.y-Dist)
//var/x2=((Center.x+Dist)>world.maxx ? world.maxx : Center.x+Dist)
//var/y2=((Center.y+Dist)>world.maxy ? world.maxy : Center.y+Dist)
var/turf/x1y1 = locate(((Center.x-Dist)<1 ? 1 : Center.x-Dist),((Center.y-Dist)<1 ? 1 : Center.y-Dist),Center.z)
var/turf/x2y2 = locate(((Center.x+Dist)>world.maxx ? world.maxx : Center.x+Dist),((Center.y+Dist)>world.maxy ? world.maxy : Center.y+Dist),Center.z)
return block(x1y1,x2y2)
/proc/explosion(turf/epicenter, devastation_range, heavy_impact_range, light_impact_range, flash_range, adminlog = 1, ignorecap = 0, flame_range = 0 ,silent = 0)
set waitfor = 0
src = null //so we don't abort once src is deleted
@@ -91,7 +78,7 @@
var/y0 = epicenter.y
var/z0 = epicenter.z
var/list/affected_turfs = trange(max_range, epicenter)
var/list/affected_turfs = spiral_range_turfs(max_range, epicenter)
if(config.reactionary_explosions)
for(var/turf/T in affected_turfs) // we cache the explosion block rating of every turf in the explosion area
@@ -112,7 +99,7 @@
CHECK_TICK
for(var/turf/T in affected_turfs)
CHECK_TICK
if (!T)
continue
var/dist = cheap_hypotenuse(T.x, T.y, x0, y0)
@@ -156,6 +143,7 @@
I.throw_speed = 4 //Temporarily change their throw_speed for embedding purposes (Reset when it finishes throwing, regardless of hitting anything)
I.throw_at_fast(throw_at, throw_range, 2)//Throw it at 2 speed, this is purely visual anyway.
CHECK_TICK
var/took = (world.timeofday-start)/10
//You need to press the DebugGame verb to see these now....they were getting annoying and we've collected a fair bit of data. Just -test- changes to explosion code using this please so we can compare
@@ -172,7 +160,7 @@
/proc/secondaryexplosion(turf/epicenter, range)
for(var/turf/tile in trange(range, epicenter))
for(var/turf/tile in spiral_range_turfs(range, epicenter))
tile.ex_act(2)
@@ -214,7 +202,7 @@
var/x0 = epicenter.x
var/y0 = epicenter.y
var/list/wipe_colours = list()
for(var/turf/T in trange(max_range, epicenter))
for(var/turf/T in spiral_range_turfs(max_range, epicenter))
wipe_colours += T
var/dist = cheap_hypotenuse(T.x, T.y, x0, y0)
+1 -1
View File
@@ -188,7 +188,7 @@
used = TRUE
sleep(50)
var/clear = TRUE
for(var/unclear in trange(3, src))
for(var/unclear in RANGE_TURFS(3, src))
var/turf/T = unclear
if(istype(T, /turf/simulated/mineral) || !T.density)
continue
@@ -236,8 +236,7 @@
/obj/singularity/proc/eat()
set background = BACKGROUND_ENABLED
var/list/L = grav_pull > 8 ? urange(grav_pull, src, 1) : orange(grav_pull, src)
for(var/atom/X in L)
for(var/atom/X in spiral_range(grav_pull, src, 1))
var/dist = get_dist(X, src)
var/obj/singularity/S = src
if(dist > consume_range)
@@ -42,7 +42,7 @@
//You're the same as me? I hate you I'm going home
if(clusterCheckFlags & CLUSTER_CHECK_SAME_TURFS)
clustering = rand(clusterMin,clusterMax)
for(var/turf/F in trange(clustering,T))
for(var/turf/F in RANGE_TURFS(clustering,T))
if(istype(F,turfPath))
skipLoopIteration = TRUE
break
@@ -53,7 +53,7 @@
//You're DIFFERENT to me? I hate you I'm going home
if(clusterCheckFlags & CLUSTER_CHECK_DIFFERENT_TURFS)
clustering = rand(clusterMin,clusterMax)
for(var/turf/F in trange(clustering,T))
for(var/turf/F in RANGE_TURFS(clustering,T))
if(!(istype(F,turfPath)))
skipLoopIteration = TRUE
break