From 2d90585ecca0ab7072a9743f78b624450d3b5827 Mon Sep 17 00:00:00 2001 From: Fox-McCloud Date: Sat, 30 Apr 2016 05:17:45 -0400 Subject: [PATCH] Makes Explosion and Singulo Defer Based on CPU --- code/__DEFINES/tick.dm | 5 ++ code/__HELPERS/unsorted.dm | 66 +++++++++++++++++++ code/game/objects/explosion.dm | 25 +++---- .../objects/items/weapons/tanks/watertank.dm | 2 +- code/game/objects/objs.dm | 1 + code/modules/fish/fishtank.dm | 2 +- code/modules/power/singularity/singularity.dm | 23 ++++--- .../procedural_mapping/mapGeneratorModule.dm | 4 +- .../effects/unknown_effect_teleport.dm | 58 ---------------- paradise.dme | 2 +- 10 files changed, 100 insertions(+), 88 deletions(-) create mode 100644 code/__DEFINES/tick.dm delete mode 100644 code/modules/research/xenoarchaeology/artifact/effects/unknown_effect_teleport.dm diff --git a/code/__DEFINES/tick.dm b/code/__DEFINES/tick.dm new file mode 100644 index 00000000000..0469a81a392 --- /dev/null +++ b/code/__DEFINES/tick.dm @@ -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() \ No newline at end of file diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 33a815f2443..2110ff09fe5 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -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. \ No newline at end of file diff --git a/code/game/objects/explosion.dm b/code/game/objects/explosion.dm index caaf79a9981..c03652a1126 100644 --- a/code/game/objects/explosion.dm +++ b/code/game/objects/explosion.dm @@ -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) diff --git a/code/game/objects/items/weapons/tanks/watertank.dm b/code/game/objects/items/weapons/tanks/watertank.dm index cbe3cdde29d..1d9cce844ff 100644 --- a/code/game/objects/items/weapons/tanks/watertank.dm +++ b/code/game/objects/items/weapons/tanks/watertank.dm @@ -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 diff --git a/code/game/objects/objs.dm b/code/game/objects/objs.dm index cf72da26b0b..81b5722e934 100644 --- a/code/game/objects/objs.dm +++ b/code/game/objects/objs.dm @@ -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 diff --git a/code/modules/fish/fishtank.dm b/code/modules/fish/fishtank.dm index 8fe4bfa746d..6da71b3adb2 100644 --- a/code/modules/fish/fishtank.dm +++ b/code/modules/fish/fishtank.dm @@ -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() diff --git a/code/modules/power/singularity/singularity.dm b/code/modules/power/singularity/singularity.dm index ba516cd2181..56da613f48b 100644 --- a/code/modules/power/singularity/singularity.dm +++ b/code/modules/power/singularity/singularity.dm @@ -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 diff --git a/code/modules/procedural_mapping/mapGeneratorModule.dm b/code/modules/procedural_mapping/mapGeneratorModule.dm index 5fa432c1986..030c61e972a 100644 --- a/code/modules/procedural_mapping/mapGeneratorModule.dm +++ b/code/modules/procedural_mapping/mapGeneratorModule.dm @@ -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 diff --git a/code/modules/research/xenoarchaeology/artifact/effects/unknown_effect_teleport.dm b/code/modules/research/xenoarchaeology/artifact/effects/unknown_effect_teleport.dm deleted file mode 100644 index 2c22bb9810e..00000000000 --- a/code/modules/research/xenoarchaeology/artifact/effects/unknown_effect_teleport.dm +++ /dev/null @@ -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() diff --git a/paradise.dme b/paradise.dme index 9077d8b86f4..5ce109ecadd 100644 --- a/paradise.dme +++ b/paradise.dme @@ -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"