Merge pull request #4326 from Fox-McCloud/even-less-lag

Makes Explosion and Singulo Defer Based on CPU
This commit is contained in:
TheDZD
2016-04-30 09:57:01 -04:00
10 changed files with 100 additions and 88 deletions
+5
View File
@@ -0,0 +1,5 @@
#define TICK_LIMIT_RUNNING 90
#define TICK_LIMIT_TO_RUN 85
#define TICK_CHECK ( world.tick_usage > TICK_LIMIT_RUNNING ? stoplag() : 0 )
#define CHECK_TICK if (world.tick_usage > TICK_LIMIT_RUNNING) stoplag()
+66
View File
@@ -1575,6 +1575,59 @@ var/mob/dview/dview_mob = new
return I
//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
//ultra range (no limitations on distance, faster than range for distances > 8); including areas drastically decreases performance
/proc/urange(dist=0, atom/center=usr, orange=0, areas=0)
if(!dist)
@@ -1670,3 +1723,16 @@ var/global/list/g_fancy_list_of_types = null
// Use this to send to a client's chat, no exceptions (except this proc itself).
/proc/to_chat(var/thing, var/output)
thing << output
//Key thing that stops lag. Cornerstone of performance in ss13, Just sitting here, in unsorted.dm.
/proc/stoplag()
. = 1
sleep(world.tick_lag)
if (world.tick_usage > TICK_LIMIT_TO_RUN) //woke up, still not enough tick, sleep for more.
. += 2
sleep(world.tick_lag*2)
if (world.tick_usage > TICK_LIMIT_TO_RUN) //woke up, STILL not enough tick, sleep for more.
. += 4
sleep(world.tick_lag*4)
//you might be thinking of adding more steps to this, or making it use a loop and a counter var
// not worth it.
+8 -17
View File
@@ -1,18 +1,5 @@
//TODO: Flash range does nothing currently
/proc/trange(var/Dist=0,var/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)
src = null //so we don't abort once src is deleted
epicenter = get_turf(epicenter)
@@ -84,7 +71,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/A in affected_turfs) // we cache the explosion block rating of every turf in the explosion area
@@ -96,10 +83,12 @@
for(var/obj/machinery/door/D in T)
if(D.density && D.explosion_block)
cached_exp_block[T] += D.explosion_block
CHECK_TICK
for(var/A in affected_turfs)
var/turf/T = A
if(!T)
continue
var/dist = cheap_hypotenuse(T.x, T.y, x0, y0)
if(config.reactionary_explosions)
@@ -142,8 +131,10 @@
var/atom/AM = atom
if(AM && AM.simulated)
AM.ex_act(dist)
CHECK_TICK
T.ex_act(dist)
CHECK_TICK
//--- THROW ITEMS AROUND ---
/*
if(throw_dist > 0)
@@ -172,7 +163,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)
/client/proc/check_bomb_impacts()
@@ -213,7 +204,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)
@@ -342,7 +342,7 @@
F.set_up(amount, 0, src.loc)
F.start()
if(blast)
for(var/turf/T in trange(2, src.loc))
for(var/turf/T in spiral_range_turfs(2, src.loc))
Chilled(T)
return
+1
View File
@@ -53,6 +53,7 @@
/obj/item/proc/is_used_on(obj/O, mob/user)
/obj/proc/process()
set waitfor = 0
processing_objects.Remove(src)
return 0
+1 -1
View File
@@ -387,7 +387,7 @@
var/turf/simulated/S = T
S.MakeSlippery()
if("wall") //Wall-tank: Wets it's own tile and the surrounding 8 tiles (3x3 square)
for(var/turf/T in trange(1, src.loc))
for(var/turf/T in spiral_range_turfs(1, src.loc))
if(!istype(T, /turf/simulated)) continue
var/turf/simulated/S = T
S.MakeSlippery()
+15 -8
View File
@@ -237,16 +237,23 @@
/obj/singularity/proc/eat()
set background = BACKGROUND_ENABLED
for(var/atom/X in orange(grav_pull,src))
var/dist = get_dist(X, src)
var/obj/singularity/S = src
if(dist > consume_range)
X.singularity_pull(S, current_size)
else if(dist <= consume_range)
consume(X)
for(var/tile in spiral_range_turfs(grav_pull, src, 1))
var/turf/T = tile
if(!T)
continue
if(get_dist(T, src) > consume_range)
T.singularity_pull(src, current_size)
else
consume(T)
for(var/thing in T)
var/atom/movable/X = thing
if(get_dist(X, src) > consume_range)
X.singularity_pull(src, current_size)
else
consume(X)
CHECK_TICK
return
/obj/singularity/proc/consume(var/atom/A)
var/gain = A.singularity_act(current_size)
src.energy += gain
@@ -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 spiral_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 spiral_range_turfs(clustering,T))
if(!(istype(F,turfPath)))
skipLoopIteration = TRUE
break
@@ -1,58 +0,0 @@
/datum/artifact_effect/teleport
effecttype = "teleport"
effect_type = 6
/datum/artifact_effect/teleport/DoEffectTouch(var/mob/user)
var/weakness = GetAnomalySusceptibility(user)
if(prob(100 * weakness))
to_chat(user, "\red You are suddenly zapped away elsewhere!")
if (user.buckled)
user.buckled.unbuckle_mob()
var/datum/effect/system/spark_spread/sparks = new /datum/effect/system/spark_spread()
sparks.set_up(3, 0, get_turf(user))
sparks.start()
//
user.forceMove(pick(trange(50, get_turf(holder))))
sparks = new /datum/effect/system/spark_spread()
sparks.set_up(3, 0, get_turf(user))
sparks.start()
/datum/artifact_effect/teleport/DoEffectAura()
if(holder)
var/turf/T = get_turf(holder)
for (var/mob/living/M in range(src.effectrange,T))
var/weakness = GetAnomalySusceptibility(M)
if(prob(100 * weakness))
to_chat(M, "\red You are displaced by a strange force!")
if(M.buckled)
M.buckled.unbuckle_mob()
var/datum/effect/system/spark_spread/sparks = new /datum/effect/system/spark_spread()
sparks.set_up(3, 0, get_turf(M))
sparks.start()
//
M.forceMove(pick(trange(50, T)))
sparks = new /datum/effect/system/spark_spread()
sparks.set_up(3, 0, get_turf(M))
sparks.start()
/datum/artifact_effect/teleport/DoEffectPulse()
if(holder)
var/turf/T = get_turf(holder)
for (var/mob/living/M in range(src.effectrange, T))
var/weakness = GetAnomalySusceptibility(M)
if(prob(100 * weakness))
to_chat(M, "\red You are displaced by a strange force!")
if(M.buckled)
M.buckled.unbuckle_mob()
var/datum/effect/system/spark_spread/sparks = new /datum/effect/system/spark_spread()
sparks.set_up(3, 0, get_turf(M))
sparks.start()
//
M.forceMove(pick(trange(50, T)))
sparks = new /datum/effect/system/spark_spread()
sparks.set_up(3, 0, get_turf(M))
sparks.start()
+1 -1
View File
@@ -41,6 +41,7 @@
#include "code\__DEFINES\sight.dm"
#include "code\__DEFINES\snpc.dm"
#include "code\__DEFINES\stat.dm"
#include "code\__DEFINES\tick.dm"
#include "code\__HELPERS\_string_lists.dm"
#include "code\__HELPERS\constants.dm"
#include "code\__HELPERS\experimental.dm"
@@ -1913,7 +1914,6 @@
#include "code\modules\research\xenoarchaeology\artifact\effects\unknown_effect_robohurt.dm"
#include "code\modules\research\xenoarchaeology\artifact\effects\unknown_effect_sleepy.dm"
#include "code\modules\research\xenoarchaeology\artifact\effects\unknown_effect_stun.dm"
#include "code\modules\research\xenoarchaeology\artifact\effects\unknown_effect_teleport.dm"
#include "code\modules\research\xenoarchaeology\finds\finds.dm"
#include "code\modules\research\xenoarchaeology\finds\finds_defines.dm"
#include "code\modules\research\xenoarchaeology\finds\finds_fossils.dm"