From 031d4cf8ee611baeedf89d82e9575d0697d20b8e Mon Sep 17 00:00:00 2001 From: skeeyui <19658265+skeyuui@users.noreply.github.com> Date: Sun, 1 Sep 2024 16:58:50 -0300 Subject: [PATCH] Ports: 'Atmos bandaid to save cpu time' --- code/controllers/subsystem/air.dm | 110 +----------- .../atmospherics/environmental/LINDA_fire.dm | 3 - .../environmental/LINDA_system.dm | 24 +-- .../environmental/LINDA_turf_tile.dm | 160 +----------------- 4 files changed, 8 insertions(+), 289 deletions(-) diff --git a/code/controllers/subsystem/air.dm b/code/controllers/subsystem/air.dm index 83db0eeeb..90fe8af82 100644 --- a/code/controllers/subsystem/air.dm +++ b/code/controllers/subsystem/air.dm @@ -22,7 +22,6 @@ SUBSYSTEM_DEF(air) var/cost_pipenets = 0 var/cost_atmos_machinery = 0 - var/list/excited_groups = list() var/list/active_turfs = list() var/list/hotspots = list() var/list/networks = list() @@ -55,7 +54,6 @@ SUBSYSTEM_DEF(air) msg += "AM:[round(cost_atmos_machinery,1)]" msg += "} " msg += "AT:[active_turfs.len]|" - msg += "EG:[excited_groups.len]|" msg += "HS:[hotspots.len]|" msg += "PN:[networks.len]|" msg += "HP:[high_pressure_delta.len]|" @@ -224,21 +222,7 @@ SUBSYSTEM_DEF(air) return /datum/controller/subsystem/air/proc/process_excited_groups(resumed = 0) - if (!resumed) - src.currentrun = excited_groups.Copy() - //cache for sanic speed (lists are references anyways) - var/list/currentrun = src.currentrun - while(currentrun.len) - var/datum/excited_group/EG = currentrun[currentrun.len] - currentrun.len-- - EG.breakdown_cooldown++ - EG.dismantle_cooldown++ - if(EG.breakdown_cooldown >= EXCITED_GROUP_BREAKDOWN_CYCLES) - EG.self_breakdown() - else if(EG.dismantle_cooldown >= EXCITED_GROUP_DISMANTLE_CYCLES) - EG.dismantle() - if (MC_TICK_CHECK) - return + return /datum/controller/subsystem/air/proc/remove_from_active(turf/open/T) @@ -250,29 +234,9 @@ SUBSYSTEM_DEF(air) #endif if(istype(T)) T.excited = 0 - if(T.excited_group) - T.excited_group.garbage_collect() /datum/controller/subsystem/air/proc/add_to_active(turf/open/T, blockchanges = 1) - if(istype(T) && T.air) - #ifdef VISUALIZE_ACTIVE_TURFS - T.add_atom_colour("#00ff00", TEMPORARY_COLOUR_PRIORITY) - #endif - T.excited = 1 - active_turfs |= T - if(currentpart == SSAIR_ACTIVETURFS) - currentrun |= T - if(blockchanges && T.excited_group) - T.excited_group.garbage_collect() - else if(T.flags_1 & INITIALIZED_1) - for(var/turf/S in T.atmos_adjacent_turfs) - add_to_active(S) - else if(map_loading) - if(queued_for_activation) - queued_for_activation[T] = T - return - else - T.requires_activation = TRUE + return /datum/controller/subsystem/air/StartLoadingMap() LAZYINITLIST(queued_for_activation) @@ -285,75 +249,11 @@ SUBSYSTEM_DEF(air) queued_for_activation.Cut() /datum/controller/subsystem/air/proc/setup_allturfs() - var/list/turfs_to_init = block(locate(1, 1, 1), locate(world.maxx, world.maxy, world.maxz)) - var/list/active_turfs = src.active_turfs - var/times_fired = ++src.times_fired - - // Clear active turfs - faster than removing every single turf in the world - // one-by-one, and Initalize_Atmos only ever adds `src` back in. - active_turfs.Cut() - - for(var/thing in turfs_to_init) - var/turf/T = thing - if (T.blocks_air) - continue - T.Initalize_Atmos(times_fired) - CHECK_TICK - - if(active_turfs.len) - var/starting_ats = active_turfs.len - sleep(world.tick_lag) - var/timer = world.timeofday - log_mapping("There are [starting_ats] active turfs at roundstart caused by a difference of the air between the adjacent turfs. You can see its coordinates using \"Mapping -> Show roundstart AT list\" verb (debug verbs required).") - for(var/turf/T in active_turfs) - GLOB.active_turfs_startlist += T - - //now lets clear out these active turfs - var/list/turfs_to_check = active_turfs.Copy() - do - var/list/new_turfs_to_check = list() - for(var/turf/open/T in turfs_to_check) - new_turfs_to_check += T.resolve_active_graph() - CHECK_TICK - - active_turfs += new_turfs_to_check - turfs_to_check = new_turfs_to_check - - while (turfs_to_check.len) - var/ending_ats = active_turfs.len - for(var/thing in excited_groups) - var/datum/excited_group/EG = thing - EG.self_breakdown(space_is_all_consuming = 1) - EG.dismantle() - CHECK_TICK - var/msg = "" - log_game("HEY! LISTEN! [DisplayTimeText(world.timeofday - timer)] were wasted processing [starting_ats] turf(s) (connected to [ending_ats] other turfs) with atmos differences at round start.") - to_chat(world, span_boldannounce("[msg]")) - warning(msg) + return /turf/open/proc/resolve_active_graph() - . = list() - var/datum/excited_group/EG = excited_group - if (blocks_air || !air) - return - if (!EG) - EG = new - EG.add_turf(src) - - for (var/turf/open/ET in atmos_adjacent_turfs) - if ( ET.blocks_air || !ET.air) - continue - - var/ET_EG = ET.excited_group - if (ET_EG) - if (ET_EG != EG) - EG.merge_groups(ET_EG) - EG = excited_group //merge_groups() may decide to replace our current EG - else - EG.add_turf(ET) - if (!ET.excited) - ET.excited = 1 - . += ET + return list() + /turf/open/space/resolve_active_graph() return list() diff --git a/code/modules/atmospherics/environmental/LINDA_fire.dm b/code/modules/atmospherics/environmental/LINDA_fire.dm index 321d4b891..d50af5d52 100644 --- a/code/modules/atmospherics/environmental/LINDA_fire.dm +++ b/code/modules/atmospherics/environmental/LINDA_fire.dm @@ -187,9 +187,6 @@ perform_exposure() return - if(location.excited_group) - location.excited_group.reset_cooldowns() - if((temperature < FIRE_MINIMUM_TEMPERATURE_TO_EXIST) || (volume <= 1)) qdel(src) return diff --git a/code/modules/atmospherics/environmental/LINDA_system.dm b/code/modules/atmospherics/environmental/LINDA_system.dm index cc854a857..a8d191383 100644 --- a/code/modules/atmospherics/environmental/LINDA_system.dm +++ b/code/modules/atmospherics/environmental/LINDA_system.dm @@ -44,25 +44,7 @@ return FALSE /turf/proc/ImmediateCalculateAdjacentTurfs() - var/canpass = CANATMOSPASS(src, src) - var/canvpass = CANVERTICALATMOSPASS(src, src) - for(var/direction in GLOB.cardinals_multiz) - var/turf/T = get_step_multiz(src, direction) - if(!isopenturf(T)) - continue - if(!(blocks_air || T.blocks_air) && ((direction & (UP|DOWN))? (canvpass && CANVERTICALATMOSPASS(T, src)) : (canpass && CANATMOSPASS(T, src))) ) - LAZYINITLIST(atmos_adjacent_turfs) - LAZYINITLIST(T.atmos_adjacent_turfs) - atmos_adjacent_turfs[T] = TRUE - T.atmos_adjacent_turfs[src] = TRUE - else - if (atmos_adjacent_turfs) - atmos_adjacent_turfs -= T - if (T.atmos_adjacent_turfs) - T.atmos_adjacent_turfs -= src - UNSETEMPTY(T.atmos_adjacent_turfs) - UNSETEMPTY(atmos_adjacent_turfs) - src.atmos_adjacent_turfs = atmos_adjacent_turfs + return //returns a list of adjacent turfs that can share air with this one. //alldir includes adjacent diagonal tiles that can share @@ -106,9 +88,7 @@ T.air_update_turf(command) /turf/air_update_turf(command = 0) - if(command) - ImmediateCalculateAdjacentTurfs() - SSair.add_to_active(src,command) + return /atom/movable/proc/move_update_air(turf/T) if(isturf(T)) diff --git a/code/modules/atmospherics/environmental/LINDA_turf_tile.dm b/code/modules/atmospherics/environmental/LINDA_turf_tile.dm index 678aefaf5..a47f7fa3b 100644 --- a/code/modules/atmospherics/environmental/LINDA_turf_tile.dm +++ b/code/modules/atmospherics/environmental/LINDA_turf_tile.dm @@ -24,7 +24,6 @@ var/pressure_difference = 0 var/pressure_direction = 0 - var/datum/excited_group/excited_group var/excited = FALSE var/datum/gas_mixture/turf/air @@ -146,16 +145,6 @@ /////////////////////////////SIMULATION/////////////////////////////////// -#define LAST_SHARE_CHECK \ - var/last_share = our_air.last_share;\ - if(last_share > MINIMUM_AIR_TO_SUSPEND){\ - our_excited_group.reset_cooldowns();\ - cached_atmos_cooldown = 0;\ - } else if(last_share > MINIMUM_MOLES_DELTA_TO_MOVE) {\ - our_excited_group.dismantle_cooldown = 0;\ - cached_atmos_cooldown = 0;\ - } - /turf/proc/process_cell(fire_count) SSair.remove_from_active(src) @@ -166,84 +155,18 @@ current_cycle = fire_count //cache for sanic speed - var/list/adjacent_turfs = atmos_adjacent_turfs - var/datum/excited_group/our_excited_group = excited_group - var/adjacent_turfs_length = LAZYLEN(adjacent_turfs) var/cached_atmos_cooldown = atmos_cooldown + 1 - var/planet_atmos = planetary_atmos - if (planet_atmos) - adjacent_turfs_length++ - var/datum/gas_mixture/our_air = air - for(var/t in adjacent_turfs) - var/turf/open/enemy_tile = t - if(!istype(enemy_tile)) - continue - - if(fire_count <= enemy_tile.current_cycle) - continue - enemy_tile.archive() - - /******************* GROUP HANDLING START *****************************************************************/ - - var/should_share_air = FALSE - var/datum/gas_mixture/enemy_air = enemy_tile.air - - //cache for sanic speed - var/datum/excited_group/enemy_excited_group = enemy_tile.excited_group - - if(our_excited_group && enemy_excited_group) - if(our_excited_group != enemy_excited_group) - //combine groups (this also handles updating the excited_group var of all involved turfs) - our_excited_group.merge_groups(enemy_excited_group) - our_excited_group = excited_group //update our cache - should_share_air = TRUE - - else if(our_air.compare(enemy_air)) - if(!enemy_tile.excited) - SSair.add_to_active(enemy_tile) - var/datum/excited_group/EG = our_excited_group || enemy_excited_group || new - if(!our_excited_group) - EG.add_turf(src) - if(!enemy_excited_group) - EG.add_turf(enemy_tile) - our_excited_group = excited_group - should_share_air = TRUE - - //air sharing - if(should_share_air) - var/difference = our_air.share(enemy_air, adjacent_turfs_length) - if(difference) - if(difference > 0) - consider_pressure_difference(enemy_tile, difference) - else - enemy_tile.consider_pressure_difference(src, -difference) - LAST_SHARE_CHECK - /******************* GROUP HANDLING FINISH *********************************************************************/ - if (planet_atmos) //share our air with the "atmosphere" "above" the turf - var/datum/gas_mixture/G = new - G.copy_from_turf(src) - G.archive() - if(our_air.compare(G)) - if(!our_excited_group) - var/datum/excited_group/EG = new - EG.add_turf(src) - our_excited_group = excited_group - our_air.share(G, adjacent_turfs_length) - LAST_SHARE_CHECK - our_air.react(src) update_visuals() - if((!our_excited_group && !(our_air.temperature > MINIMUM_TEMPERATURE_START_SUPERCONDUCTION && consider_superconductivity(starting = TRUE))) \ - || (cached_atmos_cooldown > (EXCITED_GROUP_DISMANTLE_CYCLES * 2))) - SSair.remove_from_active(src) + SSair.remove_from_active(src) atmos_cooldown = cached_atmos_cooldown @@ -278,87 +201,6 @@ step(src, direction) last_high_pressure_movement_air_cycle = SSair.times_fired -///////////////////////////EXCITED GROUPS///////////////////////////// - -/datum/excited_group - var/list/turf_list = list() - var/breakdown_cooldown = 0 - var/dismantle_cooldown = 0 - -/datum/excited_group/New() - SSair.excited_groups += src - -/datum/excited_group/proc/add_turf(turf/open/T) - turf_list += T - T.excited_group = src - reset_cooldowns() - -/datum/excited_group/proc/merge_groups(datum/excited_group/E) - if(turf_list.len > E.turf_list.len) - SSair.excited_groups -= E - for(var/t in E.turf_list) - var/turf/open/T = t - T.excited_group = src - turf_list += T - reset_cooldowns() - else - SSair.excited_groups -= src - for(var/t in turf_list) - var/turf/open/T = t - T.excited_group = E - E.turf_list += T - E.reset_cooldowns() - -/datum/excited_group/proc/reset_cooldowns() - breakdown_cooldown = 0 - dismantle_cooldown = 0 - -//argument is so world start can clear out any turf differences quickly. -/datum/excited_group/proc/self_breakdown(space_is_all_consuming = FALSE) - var/datum/gas_mixture/A = new - - //make local for sanic speed - var/list/A_gases = A.gases - var/list/turf_list = src.turf_list - var/turflen = turf_list.len - var/space_in_group = FALSE - - for(var/t in turf_list) - var/turf/open/T = t - if (space_is_all_consuming && !space_in_group && istype(T.air, /datum/gas_mixture/immutable/space)) - space_in_group = TRUE - qdel(A) - A = new /datum/gas_mixture/immutable/space() - A_gases = A.gases //update the cache - break - A.merge(T.air) - - for(var/id in A_gases) - A_gases[id][MOLES] /= turflen - - for(var/t in turf_list) - var/turf/open/T = t - T.air.copy_from(A) - T.atmos_cooldown = 0 - T.update_visuals() - - breakdown_cooldown = 0 - -/datum/excited_group/proc/dismantle() - for(var/t in turf_list) - var/turf/open/T = t - T.excited = FALSE - T.excited_group = null - SSair.active_turfs -= T - garbage_collect() - -/datum/excited_group/proc/garbage_collect() - for(var/t in turf_list) - var/turf/open/T = t - T.excited_group = null - turf_list.Cut() - SSair.excited_groups -= src - ////////////////////////SUPERCONDUCTIVITY///////////////////////////// /turf/proc/conductivity_directions() if(archived_cycle < SSair.times_fired)