mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-25 14:00:18 +01:00
Make some ZAS lists lazy (#2339)
This PR converts some lists in ZAS to be only created when needed instead of always existing and pointlessly using memory. Might lead to reduced server memory usage.
This commit is contained in:
@@ -127,26 +127,26 @@ Class Procs:
|
||||
|
||||
src.A = A
|
||||
src.B = B
|
||||
A.edges.Add(src)
|
||||
B.edges.Add(src)
|
||||
LAZYADD(A.edges, src)
|
||||
LAZYADD(B.edges, src)
|
||||
//id = edge_id(A,B)
|
||||
// log_debug("New edge between [A] and [B]")
|
||||
|
||||
|
||||
/connection_edge/zone/add_connection(connection/c)
|
||||
. = ..()
|
||||
connecting_turfs.Add(c.A)
|
||||
connecting_turfs += c.A
|
||||
|
||||
/connection_edge/zone/remove_connection(connection/c)
|
||||
connecting_turfs.Remove(c.A)
|
||||
connecting_turfs -= c.A
|
||||
. = ..()
|
||||
|
||||
/connection_edge/zone/contains_zone(zone/Z)
|
||||
return A == Z || B == Z
|
||||
|
||||
/connection_edge/zone/erase()
|
||||
A.edges.Remove(src)
|
||||
B.edges.Remove(src)
|
||||
LAZYREMOVE(A.edges, src)
|
||||
LAZYREMOVE(B.edges, src)
|
||||
. = ..()
|
||||
|
||||
/connection_edge/zone/tick()
|
||||
@@ -198,7 +198,7 @@ Class Procs:
|
||||
/connection_edge/unsimulated/New(zone/A, turf/B)
|
||||
src.A = A
|
||||
src.B = B
|
||||
A.edges.Add(src)
|
||||
LAZYADD(A.edges, src)
|
||||
air = B.return_air()
|
||||
//id = 52*A.id
|
||||
// log_debug("New edge from [A] to [B].")
|
||||
@@ -215,7 +215,7 @@ Class Procs:
|
||||
. = ..()
|
||||
|
||||
/connection_edge/unsimulated/erase()
|
||||
A.edges.Remove(src)
|
||||
LAZYREMOVE(A.edges, src)
|
||||
. = ..()
|
||||
|
||||
/connection_edge/unsimulated/contains_zone(zone/Z)
|
||||
|
||||
+27
-16
@@ -11,7 +11,8 @@ If it gains pressure too slowly, it may leak or just rupture instead of explodin
|
||||
#define FIRE_LIGHT_2 3
|
||||
#define FIRE_LIGHT_3 4
|
||||
|
||||
/turf/var/obj/fire/fire = null
|
||||
/turf
|
||||
var/tmp/obj/fire/fire = null
|
||||
|
||||
//Some legacy definitions so fires can be started.
|
||||
atom/proc/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume)
|
||||
@@ -40,7 +41,7 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
return igniting
|
||||
|
||||
/zone/proc/process_fire()
|
||||
var/datum/gas_mixture/burn_gas = air.remove_ratio(vsc.fire_consuption_rate, fire_tiles.len)
|
||||
var/datum/gas_mixture/burn_gas = air.remove_ratio(vsc.fire_consuption_rate, LAZYLEN(fire_tiles))
|
||||
|
||||
var/firelevel = burn_gas.zburn(src, fire_tiles, force_burn = 1, no_check = 1)
|
||||
|
||||
@@ -52,21 +53,23 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
T.fire.firelevel = firelevel
|
||||
else
|
||||
var/obj/effect/decal/cleanable/liquid_fuel/fuel = locate() in T
|
||||
fire_tiles -= T
|
||||
fuel_objs -= fuel
|
||||
LAZYREMOVE(fire_tiles, T)
|
||||
LAZYREMOVE(fuel_objs, fuel)
|
||||
else
|
||||
for(var/turf/simulated/T in fire_tiles)
|
||||
if(istype(T.fire))
|
||||
T.fire.RemoveFire()
|
||||
T.fire = null
|
||||
fire_tiles.Cut()
|
||||
fuel_objs.Cut()
|
||||
LAZYCLEARLIST(fire_tiles)
|
||||
LAZYCLEARLIST(fuel_objs)
|
||||
UNSETEMPTY(fire_tiles)
|
||||
UNSETEMPTY(fuel_objs)
|
||||
|
||||
if(!fire_tiles.len)
|
||||
SSair.active_fire_zones.Remove(src)
|
||||
if(!LAZYLEN(fire_tiles))
|
||||
SSair.active_fire_zones -= src
|
||||
|
||||
/zone/proc/remove_liquidfuel(var/used_liquid_fuel, var/remove_fire=0)
|
||||
if(!fuel_objs.len)
|
||||
if(!LAZYLEN(fuel_objs))
|
||||
return
|
||||
|
||||
//As a simplification, we remove fuel equally from all fuel sources. It might be that some fuel sources have more fuel,
|
||||
@@ -77,12 +80,12 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
for(var/O in fuel_objs)
|
||||
var/obj/effect/decal/cleanable/liquid_fuel/fuel = O
|
||||
if(!istype(fuel))
|
||||
fuel_objs -= fuel
|
||||
LAZYREMOVE(fuel_objs, fuel)
|
||||
continue
|
||||
|
||||
fuel.amount -= fuel_to_remove
|
||||
if(fuel.amount <= 0)
|
||||
fuel_objs -= fuel
|
||||
LAZYREMOVE(fuel_objs, fuel)
|
||||
if(remove_fire)
|
||||
var/turf/T = fuel.loc
|
||||
if(istype(T) && T.fire) qdel(T.fire)
|
||||
@@ -103,8 +106,10 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
SSair.active_fire_zones |= zone
|
||||
|
||||
var/obj/effect/decal/cleanable/liquid_fuel/fuel = locate() in src
|
||||
LAZYINITLIST(zone.fire_tiles)
|
||||
zone.fire_tiles |= src
|
||||
if(fuel) zone.fuel_objs += fuel
|
||||
if(fuel)
|
||||
LAZYADD(zone.fuel_objs, fuel)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -180,8 +185,11 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
else
|
||||
enemy_tile.adjacent_fire_act(loc, air_contents, air_contents.temperature, air_contents.volume)
|
||||
|
||||
animate(src, color = fire_color(air_contents.temperature), 5)
|
||||
set_light(l_color = color)
|
||||
var/list/animate_targets = get_above_oo() + src
|
||||
for (var/thing in animate_targets)
|
||||
var/atom/movable/AM = thing
|
||||
animate(AM, color = fire_color(air_contents.temperature), 5)
|
||||
|
||||
/obj/fire/New(newLoc,fl)
|
||||
..()
|
||||
@@ -197,7 +205,7 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
set_light(3, 1, color)
|
||||
|
||||
firelevel = fl
|
||||
SSair.active_hotspots.Add(src)
|
||||
SSair.active_hotspots += src
|
||||
|
||||
/obj/fire/proc/fire_color(var/env_temperature)
|
||||
var/temperature = max(4000*sqrt(firelevel/vsc.fire_firelevel_multiplier), env_temperature)
|
||||
@@ -215,11 +223,14 @@ turf/proc/hotspot_expose(exposed_temperature, exposed_volume, soh = 0)
|
||||
|
||||
T.fire = null
|
||||
loc = null
|
||||
SSair.active_hotspots.Remove(src)
|
||||
SSair.active_hotspots -= src
|
||||
|
||||
/turf/simulated
|
||||
var/tmp/fire_protection = 0 //Protects newly extinguished tiles from being overrun again.
|
||||
|
||||
/turf/simulated/var/fire_protection = 0 //Protects newly extinguished tiles from being overrun again.
|
||||
/turf/proc/apply_fire_protection()
|
||||
return
|
||||
|
||||
/turf/simulated/apply_fire_protection()
|
||||
fire_protection = world.time
|
||||
|
||||
|
||||
+18
-12
@@ -44,17 +44,17 @@ Class Procs:
|
||||
var/name
|
||||
var/invalid = 0
|
||||
var/list/contents = list()
|
||||
var/list/fire_tiles = list()
|
||||
var/list/fuel_objs = list()
|
||||
var/list/fire_tiles
|
||||
var/list/fuel_objs
|
||||
|
||||
var/needs_update = 0
|
||||
|
||||
var/list/edges = list()
|
||||
var/list/edges
|
||||
|
||||
var/datum/gas_mixture/air = new
|
||||
|
||||
var/list/graphic_add = list()
|
||||
var/list/graphic_remove = list()
|
||||
var/list/graphic_add
|
||||
var/list/graphic_remove
|
||||
|
||||
/zone/New()
|
||||
SSair.add_zone(src)
|
||||
@@ -74,9 +74,10 @@ Class Procs:
|
||||
contents += T
|
||||
if(T.fire)
|
||||
var/obj/effect/decal/cleanable/liquid_fuel/fuel = locate() in T
|
||||
fire_tiles.Add(T)
|
||||
LAZYADD(fire_tiles, T)
|
||||
SSair.active_fire_zones |= src
|
||||
if(fuel) fuel_objs += fuel
|
||||
if (fuel)
|
||||
LAZYADD(fuel_objs, fuel)
|
||||
T.update_graphic(air.graphic)
|
||||
|
||||
/zone/proc/remove(turf/simulated/T)
|
||||
@@ -87,10 +88,10 @@ Class Procs:
|
||||
soft_assert(T in contents, "Lists are weird broseph")
|
||||
#endif
|
||||
contents -= T
|
||||
fire_tiles -= T
|
||||
LAZYREMOVE(fire_tiles, T)
|
||||
if(T.fire)
|
||||
var/obj/effect/decal/cleanable/liquid_fuel/fuel = locate() in T
|
||||
fuel_objs -= fuel
|
||||
LAZYREMOVE(fuel_objs, fuel)
|
||||
T.zone = null
|
||||
T.update_graphic(graphic_remove = air.graphic)
|
||||
if(contents.len)
|
||||
@@ -154,11 +155,16 @@ Class Procs:
|
||||
if(istype(T))
|
||||
T.create_fire(vsc.fire_firelevel_multiplier)
|
||||
|
||||
LAZYINITLIST(graphic_add)
|
||||
LAZYINITLIST(graphic_remove)
|
||||
if(air.check_tile_graphic(graphic_add, graphic_remove))
|
||||
for(var/turf/simulated/T in contents)
|
||||
T.update_graphic(graphic_add, graphic_remove)
|
||||
graphic_add.len = 0
|
||||
graphic_remove.len = 0
|
||||
|
||||
LAZYCLEARLIST(graphic_add)
|
||||
LAZYCLEARLIST(graphic_remove)
|
||||
UNSETEMPTY(graphic_add)
|
||||
UNSETEMPTY(graphic_remove)
|
||||
|
||||
for(var/connection_edge/E in edges)
|
||||
if(E.sleeping)
|
||||
@@ -172,7 +178,7 @@ Class Procs:
|
||||
M << "O2 per N2: [(air.gas["nitrogen"] ? air.gas["oxygen"]/air.gas["nitrogen"] : "N/A")] Moles: [air.total_moles]"
|
||||
M << "Simulated: [contents.len] ([air.group_multiplier])"
|
||||
//M << "Unsimulated: [unsimulated_contents.len]"
|
||||
//M << "Edges: [edges.len]"
|
||||
//M << "Edges: [LAZYLEN(edges)]"
|
||||
if(invalid) M << "Invalid!"
|
||||
var/zone_edges = 0
|
||||
var/space_edges = 0
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
var/group_multiplier = 1
|
||||
|
||||
//List of active tile overlays for this gas_mixture. Updated by check_tile_graphic()
|
||||
var/list/graphic = list()
|
||||
var/list/graphic
|
||||
|
||||
/datum/gas_mixture/New(_volume = CELL_VOLUME, _temperature = 0, _group_multiplier = 1)
|
||||
volume = _volume
|
||||
@@ -349,7 +349,7 @@
|
||||
//Two lists can be passed by reference if you need know specifically which graphics were added and removed.
|
||||
/datum/gas_mixture/proc/check_tile_graphic(list/graphic_add = null, list/graphic_remove = null)
|
||||
for(var/g in gas_data.overlay_limit)
|
||||
if (graphic[gas_data.tile_overlay[g]])
|
||||
if (graphic && graphic[gas_data.tile_overlay[g]])
|
||||
//Overlay is already applied for this gas, check if it's still valid.
|
||||
if(gas[g] <= gas_data.overlay_limit[g])
|
||||
LAZYADD(graphic_remove, gas_data.tile_overlay[g])
|
||||
@@ -361,6 +361,7 @@
|
||||
. = 0
|
||||
//Apply changes
|
||||
if(LAZYLEN(graphic_add))
|
||||
LAZYINITLIST(graphic)
|
||||
for (var/entry in graphic_add)
|
||||
graphic[entry] = TRUE // This is an assoc list to make checking it a bit faster.
|
||||
. = 1
|
||||
@@ -368,6 +369,8 @@
|
||||
graphic -= graphic_remove
|
||||
. = 1
|
||||
|
||||
UNSETEMPTY(graphic)
|
||||
|
||||
//Simpler version of merge(), adjusts gas amounts directly and doesn't account for temperature or group_multiplier.
|
||||
/datum/gas_mixture/proc/add(datum/gas_mixture/right_side)
|
||||
for(var/g in right_side.gas)
|
||||
|
||||
Reference in New Issue
Block a user