further optimizes performance by making all of the meta gas properties use their own individual lists instead of being in a messy nested list

This commit is contained in:
deathride58
2019-04-14 16:40:37 -04:00
parent f7203a3428
commit 905f32b193
22 changed files with 101 additions and 61 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
for(var/id in env_gases)
var/moles = env_gases[id]
if (moles >= 0.00001)
lines += "[GLOB.meta_gas_info[id][META_GAS_NAME]]: [moles] mol"
lines += "[GLOB.meta_gas_names[id]]: [moles] mol"
to_chat(usr, lines.Join("\n"))
/client/proc/air_status(turf/target)
@@ -121,9 +121,8 @@
if (nonoverlaying_gases[id])
continue
var/gas = gases[id]
var/gas_meta = GLOB.meta_gas_info[id]
var/gas_overlay = gas_meta[META_GAS_OVERLAY]
if(gas_overlay && gas > gas_meta[META_GAS_MOLES_VISIBLE])
var/gas_overlay = GLOB.meta_gas_overlays[id]
if(gas_overlay && gas > GLOB.meta_gas_visibility[id])
. += gas_overlay[min(FACTOR_GAS_VISIBLE_MAX, CEILING(gas / MOLES_GAS_VISIBLE_STEP, 1))]
/proc/typecache_of_gases_with_no_overlays()
@@ -5,7 +5,16 @@ What are the archived variables for?
*/
#define MINIMUM_HEAT_CAPACITY 0.0003
#define MINIMUM_MOLE_COUNT 0.01
GLOBAL_LIST_INIT(meta_gas_info, meta_gas_list()) //see ATMOSPHERICS/gas_types.dm
//Unomos - global list inits for all of the meta gas lists.
//This setup allows procs to only look at one list instead of trying to dig around in lists-within-lists
GLOBAL_LIST_INIT(meta_gas_specific_heats, meta_gas_heat_list())
GLOBAL_LIST_INIT(meta_gas_names, meta_gas_name_list())
GLOBAL_LIST_INIT(meta_gas_visibility, meta_gas_visibility_list())
GLOBAL_LIST_INIT(meta_gas_overlays, meta_gas_overlay_list())
GLOBAL_LIST_INIT(meta_gas_dangers, meta_gas_danger_list())
GLOBAL_LIST_INIT(meta_gas_ids, meta_gas_id_list())
GLOBAL_LIST_INIT(meta_gas_fusions, meta_gas_fusion_list())
/datum/gas_mixture
var/list/gases = list()
var/temperature = 0 //kelvins
@@ -24,10 +33,10 @@ GLOBAL_LIST_INIT(meta_gas_info, meta_gas_list()) //see ATMOSPHERICS/gas_types.dm
/datum/gas_mixture/proc/heat_capacity() //joules per kelvin
var/list/cached_gases = gases
var/list/cached_gasinfo = GLOB.meta_gas_info
var/list/cached_gasheats = GLOB.meta_gas_specific_heats
. = 0
for(var/id in cached_gases)
. += cached_gases[id] * cached_gasinfo[id][META_GAS_SPECIFIC_HEAT] //TODO - itll absolutely be worth splitting the meta_gas_info list into multiple lists to bypass the overhead associated with accessing lists within lists
. += cached_gases[id] * cached_gasheats[id]
/datum/gas_mixture/turf/heat_capacity()
. = ..()
@@ -228,13 +237,15 @@ GLOBAL_LIST_INIT(meta_gas_info, meta_gas_list()) //see ATMOSPHERICS/gas_types.dm
//we're gonna define these vars outside of this for loop because as it turns out, var declaration is pricy
var/delta
var/gas_heat_capacity
//and also cache this shit rq because that results in sanic speed for reasons byond explanation
var/list/cached_gasheats = GLOB.meta_gas_specific_heats
//GAS TRANSFER
for(var/id in cached_gases | sharer_gases) // transfer gases
delta = QUANTIZE(cached_gases[id] - sharer_gases[id])/(atmos_adjacent_turfs+1) //the amount of gas that gets moved between the mixtures
if(delta && abs_temperature_delta > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER)
gas_heat_capacity = delta * GLOB.meta_gas_info[id][META_GAS_SPECIFIC_HEAT]
gas_heat_capacity = delta * cached_gasheats[id]
if(delta > 0)
heat_capacity_self_to_sharer += gas_heat_capacity
else
@@ -1,33 +1,66 @@
GLOBAL_LIST_INIT(hardcoded_gases, list(/datum/gas/oxygen, /datum/gas/nitrogen, /datum/gas/carbon_dioxide, /datum/gas/plasma)) //the main four gases, which were at one time hardcoded
GLOBAL_LIST_INIT(nonreactive_gases, typecacheof(list(/datum/gas/oxygen, /datum/gas/nitrogen, /datum/gas/carbon_dioxide, /datum/gas/pluoxium, /datum/gas/stimulum, /datum/gas/nitryl))) //unable to react amongst themselves
/proc/meta_gas_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/list/gas_info = new(7)
var/datum/gas/gas = gas_path
gas_info[META_GAS_SPECIFIC_HEAT] = initial(gas.specific_heat)
gas_info[META_GAS_NAME] = initial(gas.name)
gas_info[META_GAS_MOLES_VISIBLE] = initial(gas.moles_visible)
if(initial(gas.moles_visible) != null)
gas_info[META_GAS_OVERLAY] = new /list(FACTOR_GAS_VISIBLE_MAX)
for(var/i in 1 to FACTOR_GAS_VISIBLE_MAX)
gas_info[META_GAS_OVERLAY][i] = new /obj/effect/overlay/gas(initial(gas.gas_overlay), i * 255 / FACTOR_GAS_VISIBLE_MAX)
gas_info[META_GAS_FUSION_POWER] = initial(gas.fusion_power)
gas_info[META_GAS_DANGER] = initial(gas.dangerous)
gas_info[META_GAS_ID] = initial(gas.id)
.[gas_path] = gas_info
/proc/gas_id2path(id)
var/list/meta_gas = GLOB.meta_gas_info
var/list/meta_gas = GLOB.meta_gas_ids
if(id in meta_gas)
return id
for(var/path in meta_gas)
if(meta_gas[path][META_GAS_ID] == id)
if(meta_gas[path] == id)
return path
return ""
//Unomos - oh god oh fuck oh shit oh lord have mercy this is messy as fuck oh god
//my addiction to seeing better performance numbers isn't healthy, kids
//you see this shit, children?
//i am not a good idol. don't take after me.
//this is literally worse than my alcohol addiction
/proc/meta_gas_heat_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = initial(gas.specific_heat)
/proc/meta_gas_name_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = initial(gas.name)
/proc/meta_gas_visibility_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = initial(gas.moles_visible)
/proc/meta_gas_overlay_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = 0 //gotta make sure if(GLOB.meta_gas_overlays[gaspath]) doesn't break
if(initial(gas.moles_visible) != null)
.[gas_path] = new /list(FACTOR_GAS_VISIBLE_MAX)
for(var/i in 1 to FACTOR_GAS_VISIBLE_MAX)
.[gas_path][i] = new /obj/effect/overlay/gas(initial(gas.gas_overlay), i * 255 / FACTOR_GAS_VISIBLE_MAX)
/proc/meta_gas_danger_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = initial(gas.dangerous)
/proc/meta_gas_id_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = initial(gas.id)
/proc/meta_gas_fusion_list()
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/datum/gas/gas = gas_path
.[gas_path] = initial(gas.fusion_power)
/*||||||||||||||/----------\||||||||||||||*\
||||||||||||||||[GAS DATUMS]||||||||||||||||
||||||||||||||||\__________/||||||||||||||||
@@ -228,7 +228,7 @@
var/old_heat_capacity = air.heat_capacity()
var/reaction_energy = 0
var/mediation = FUSION_MEDIATION_FACTOR*(air.heat_capacity()-(cached_gases[/datum/gas/plasma]*GLOB.meta_gas_info[/datum/gas/plasma][META_GAS_SPECIFIC_HEAT]))/(air.total_moles()-cached_gases[/datum/gas/plasma]) //This is the average specific heat of the mixture,not including plasma.
var/mediation = FUSION_MEDIATION_FACTOR*(air.heat_capacity()-(cached_gases[/datum/gas/plasma]*GLOB.meta_gas_specific_heats[/datum/gas/plasma]))/(air.total_moles()-cached_gases[/datum/gas/plasma]) //This is the average specific heat of the mixture,not including plasma.
var/gases_fused = air.total_moles() - cached_gases[/datum/gas/plasma]
var/plasma_differential = (cached_gases[/datum/gas/plasma] - gases_fused) / air.total_moles()
@@ -236,7 +236,7 @@
var/gas_power = 0
for (var/gas_id in cached_gases)
gas_power += reaction_efficiency * (GLOB.meta_gas_info[gas_id][META_GAS_FUSION_POWER]*cached_gases[gas_id])
gas_power += reaction_efficiency * (GLOB.meta_gas_fusions[gas_id]*cached_gases[gas_id])
var/power_ratio = gas_power/mediation
cached_scan_results[id] = power_ratio //used for analyzer feedback
@@ -282,7 +282,7 @@
continue
cur_tlv = TLV[gas_id]
data["environment_data"] += list(list(
"name" = GLOB.meta_gas_info[gas_id][META_GAS_NAME],
"name" = GLOB.meta_gas_names[gas_id],
"value" = environment.gases[gas_id] / total_moles * 100,
"unit" = "%",
"danger_level" = cur_tlv.get_danger_level(environment.gases[gas_id] * partial_pressure)
@@ -352,11 +352,11 @@
thresholds[thresholds.len]["settings"] += list(list("env" = "temperature", "val" = "max1", "selected" = selected.max1))
thresholds[thresholds.len]["settings"] += list(list("env" = "temperature", "val" = "max2", "selected" = selected.max2))
for(var/gas_id in GLOB.meta_gas_info)
for(var/gas_id in GLOB.meta_gas_names)
if(!(gas_id in TLV)) // We're not interested in this gas, it seems.
continue
selected = TLV[gas_id]
thresholds += list(list("name" = GLOB.meta_gas_info[gas_id][META_GAS_NAME], "settings" = list()))
thresholds += list(list("name" = GLOB.meta_gas_names[gas_id], "settings" = list()))
thresholds[thresholds.len]["settings"] += list(list("env" = gas_id, "val" = "min2", "selected" = selected.min2))
thresholds[thresholds.len]["settings"] += list(list("env" = gas_id, "val" = "min1", "selected" = selected.min1))
thresholds[thresholds.len]["settings"] += list(list("env" = gas_id, "val" = "max1", "selected" = selected.max1))
@@ -190,9 +190,8 @@
data["filter_types"] = list()
data["filter_types"] += list(list("name" = "Nothing", "path" = "", "selected" = !filter_type))
for(var/path in GLOB.meta_gas_info)
var/list/gas = GLOB.meta_gas_info[path]
data["filter_types"] += list(list("name" = gas[META_GAS_NAME], "id" = gas[META_GAS_ID], "selected" = (path == gas_id2path(filter_type))))
for(var/path in GLOB.meta_gas_ids)
data["filter_types"] += list(list("name" = GLOB.meta_gas_names[path], "id" = GLOB.meta_gas_ids[path], "selected" = (path == gas_id2path(filter_type))))
return data
@@ -223,9 +222,9 @@
filter_type = null
var/filter_name = "nothing"
var/gas = gas_id2path(params["mode"])
if(gas in GLOB.meta_gas_info)
if(gas in GLOB.meta_gas_names)
filter_type = gas
filter_name = GLOB.meta_gas_info[gas][META_GAS_NAME]
filter_name = GLOB.meta_gas_names[gas]
investigate_log("was set to filter [filter_name] by [key_name(usr)]", INVESTIGATE_ATMOS)
. = TRUE
update_icon()
@@ -18,7 +18,7 @@
air_contents.temperature = T20C
if(gas_type)
air_contents.gases[gas_type] = AIR_CONTENTS
name = "[name] ([GLOB.meta_gas_info[gas_type][META_GAS_NAME]])"
name = "[name] ([GLOB.meta_gas_names[gas_type]])"
/obj/machinery/atmospherics/components/unary/tank/carbon_dioxide
gas_type = /datum/gas/carbon_dioxide
@@ -120,9 +120,8 @@
return FALSE
var/list/f_types = list()
for(var/path in GLOB.meta_gas_info)
var/list/gas = GLOB.meta_gas_info[path]
f_types += list(list("gas_id" = gas[META_GAS_ID], "gas_name" = gas[META_GAS_NAME], "enabled" = (path in filter_types)))
for(var/path in GLOB.meta_gas_ids)
f_types += list(list("gas_id" = GLOB.meta_gas_ids[path], "gas_name" = GLOB.meta_gas_names[path], "enabled" = (path in filter_types)))
var/datum/signal/signal = new(list(
"tag" = id_tag,
@@ -437,10 +437,10 @@
var/list/danger = list()
for(var/id in air_contents.gases)
var/gas = air_contents.gases[id]
if(!GLOB.meta_gas_info[id][META_GAS_DANGER])
if(!GLOB.meta_gas_dangers[id])
continue
if(gas > (GLOB.meta_gas_info[id][META_GAS_MOLES_VISIBLE] || MOLES_GAS_VISIBLE)) //if moles_visible is undefined, default to default visibility
danger[GLOB.meta_gas_info[id][META_GAS_NAME]] = gas //ex. "plasma" = 20
if(gas > (GLOB.meta_gas_visibility[id] || MOLES_GAS_VISIBLE)) //if moles_visible is undefined, default to default visibility
danger[GLOB.meta_gas_names[id]] = gas //ex. "plasma" = 20
if(danger.len)
message_admins("[ADMIN_LOOKUPFLW(usr)] opened a canister that contains the following at [ADMIN_VERBOSEJMP(src)]:")
@@ -78,9 +78,8 @@
data["id_tag"] = -1 //must be defined in order to reuse code between portable and vent scrubbers
data["filter_types"] = list()
for(var/path in GLOB.meta_gas_info)
var/list/gas = GLOB.meta_gas_info[path]
data["filter_types"] += list(list("gas_id" = gas[META_GAS_ID], "gas_name" = gas[META_GAS_NAME], "enabled" = (path in scrubbing)))
for(var/path in GLOB.meta_gas_ids)
data["filter_types"] += list(list("gas_id" = GLOB.meta_gas_ids[path], "gas_name" = GLOB.meta_gas_names[path], "enabled" = (path in scrubbing)))
if(holding)
data["holding"] = list()
@@ -371,7 +371,7 @@ obj/item/integrated_circuit/atmospherics/connector/portableConnectorReturnAir()
for(var/filtered_gas in removed.gases)
//Get the name of the gas and see if it is in the list
if(GLOB.meta_gas_info[filtered_gas][META_GAS_NAME] in wanted)
if(GLOB.meta_gas_names[filtered_gas] in wanted)
//The gas that is put in all the filtered out gases
filtered_out.temperature = removed.temperature
filtered_out.gases[filtered_gas] = removed.gases[filtered_gas]
@@ -1165,7 +1165,7 @@
var/list/gas_names = list()
var/list/gas_amounts = list()
for(var/id in gases)
var/name = GLOB.meta_gas_info[id][META_GAS_NAME]
var/name = GLOB.meta_gas_names[id]
var/amt = round(gases[id], 0.001)
gas_names.Add(name)
gas_amounts.Add(amt)
@@ -546,7 +546,7 @@
for(var/id in env_gases)
var/gas_level = env_gases[id]/total_moles
if(gas_level > 0.01)
dat += "[GLOB.meta_gas_info[id][META_GAS_NAME]]: [round(gas_level*100)]%<br>"
dat += "[GLOB.meta_gas_names[id]]: [round(gas_level*100)]%<br>"
dat += "Temperature: [round(environment.temperature-T0C)]&deg;C<br>"
dat += "<a href='byond://?src=[REF(src)];software=atmosensor;sub=0'>Refresh Reading</a> <br>"
dat += "<br>"
+1 -1
View File
@@ -68,7 +68,7 @@
for(var/id in environment.gases)
var/gas = environment.gases[id]
if(gas)
t+="<span class='notice'>[GLOB.meta_gas_info[id][META_GAS_NAME]]: [gas] \n</span>"
t+="<span class='notice'>[GLOB.meta_gas_names[id]]: [gas] \n</span>"
to_chat(usr, t)
@@ -81,13 +81,13 @@
if(air.total_moles())
for(var/gasid in air.gases)
gasdata.Add(list(list(
"name"= GLOB.meta_gas_info[gasid][META_GAS_NAME],
"name"= GLOB.meta_gas_names[gasid],
"amount" = round(100*air.gases[gasid]/air.total_moles(),0.01))))
else
for(var/gasid in air.gases)
gasdata.Add(list(list(
"name"= GLOB.meta_gas_info[gasid][META_GAS_NAME],
"name"= GLOB.meta_gas_names[gasid],
"amount" = 0)))
data["gases"] = gasdata