Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Atmospherics much faster #27862

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/__DEFINES/rust.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
/proc/milla_init_z(z)
return RUSTLIB_CALL(milla_initialize, z)

/proc/milla_load_turfs(turf/low_corner, turf/high_corner)
ASSERT(istype(low_corner))
ASSERT(istype(high_corner))
return RUSTLIB_CALL(milla_load_turfs, "milla_data", low_corner, high_corner)

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/boxstation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/boxstation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/boxstation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/boxstation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/boxstation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/boxstation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/deltastation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/deltastation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/deltastation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/deltastation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/deltastation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/deltastation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/metastation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/metastation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/metastation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/metastation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/metastation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/metastation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/cerestation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/cerestation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/cerestation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/cerestation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/cerestation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/cerestation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/emeraldstation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/emeraldstation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/emeraldstation, STABLE)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/emeraldstation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/emeraldstation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

Check failure on line 66 in code/__DEFINES/rust.dm

View workflow job for this annotation

GitHub Actions / Unit Tests + SQL Validation (/datum/map/emeraldstation, BETA)

Runtime

tools/ci/librustlibs_ci.so: undefined symbol: milla_load_turfs_ffi

/proc/set_tile_atmos(turf/T, airtight_north, airtight_east, airtight_south, airtight_west, atmos_mode, environment_id, oxygen, carbon_dioxide, nitrogen, toxins, sleeping_agent, agent_b, temperature, innate_heat_capacity, hotspot_temperature, hotspot_volume)
return RUSTLIB_CALL(milla_set_tile, T, airtight_north, airtight_east, airtight_south, airtight_west, atmos_mode, environment_id, oxygen, carbon_dioxide, nitrogen, toxins, sleeping_agent, agent_b, temperature, innate_heat_capacity, hotspot_temperature, hotspot_volume)

Expand Down
13 changes: 4 additions & 9 deletions code/controllers/subsystem/SSair.dm
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ SUBSYSTEM_DEF(air)
in_milla_safe_code = TRUE

setup_overlays() // Assign icons and such for gas-turf-overlays
setup_allturfs()
setup_write_to_milla()
setup_turfs()
setup_atmos_machinery(GLOB.machines)
setup_pipenets(GLOB.machines)
for(var/obj/machinery/atmospherics/A in machinery_to_construct)
Expand Down Expand Up @@ -614,14 +613,10 @@ SUBSYSTEM_DEF(air)
last_bound_mixtures = length(bound_mixtures)
return

/datum/controller/subsystem/air/proc/setup_allturfs(list/turfs_to_init = block(locate(1, 1, 1), locate(world.maxx, world.maxy, world.maxz)))
for(var/turf/T as anything in turfs_to_init)
T.Initialize_Atmos(times_fired)
CHECK_TICK

/datum/controller/subsystem/air/proc/setup_allturfs_sleepless(list/turfs_to_init = block(locate(1, 1, 1), locate(world.maxx, world.maxy, world.maxz)))
for(var/turf/T as anything in turfs_to_init)
/datum/controller/subsystem/air/proc/setup_turfs(turf/low_corner = locate(1, 1, 1), turf/high_corner = locate(world.maxx, world.maxy, world.maxz))
for(var/turf/T as anything in block(low_corner, high_corner))
T.Initialize_Atmos(times_fired)
milla_load_turfs(low_corner, high_corner)

/datum/controller/subsystem/air/proc/setup_write_to_milla()
var/watch = start_watch()
Expand Down
4 changes: 2 additions & 2 deletions code/datums/helper_datums/map_template.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
catch(var/exception/e)
GLOB.space_manager.remove_dirt(placement.z)
var/datum/milla_safe/late_setup_level/milla = new()
milla.invoke_async(block(bot_left, top_right), block(ST_bot_left, ST_top_right))
milla.invoke_async(bot_left, top_right, block(ST_bot_left, ST_top_right))
message_admins("Map template [name] threw an error while loading. Safe exit attempted, but check for errors at [ADMIN_COORDJMP(placement)].")
log_admin("Map template [name] threw an error while loading. Safe exit attempted.")
throw e
GLOB.space_manager.remove_dirt(placement.z)
var/datum/milla_safe/late_setup_level/milla = new()
milla.invoke_async(block(bot_left, top_right), block(ST_bot_left, ST_top_right))
milla.invoke_async(bot_left, top_right, block(ST_bot_left, ST_top_right))

log_game("[name] loaded at [min_x],[min_y],[placement.z]")
return 1
Expand Down
8 changes: 8 additions & 0 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
/// The effect used to render a pressure overlay from this tile.
var/obj/effect/pressure_overlay/pressure_overlay

var/list/milla_atmos_airtight = list(FALSE, FALSE, FALSE, FALSE)
var/list/milla_superconductivity = list(
OPEN_HEAT_TRANSFER_COEFFICIENT,
OPEN_HEAT_TRANSFER_COEFFICIENT,
OPEN_HEAT_TRANSFER_COEFFICIENT,
OPEN_HEAT_TRANSFER_COEFFICIENT)
var/list/milla_data = list()

/turf/Initialize(mapload)
SHOULD_CALL_PARENT(FALSE)
if(initialized)
Expand Down
69 changes: 32 additions & 37 deletions code/modules/atmospherics/environmental/LINDA_turf_tile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,10 @@
#define INDEX_WEST 4

/turf/proc/Initialize_Atmos(times_fired)
recalculate_atmos_connectivity()

if(!blocks_air)
var/datum/gas_mixture/air = new()
air.set_oxygen(oxygen)
air.set_carbon_dioxide(carbon_dioxide)
air.set_nitrogen(nitrogen)
air.set_toxins(toxins)
air.set_sleeping_agent(sleeping_agent)
air.set_agent_b(agent_b)
air.set_temperature(temperature)
blind_set_air(air)
// This is one of two places expected to call this otherwise-unsafe method.
private_unsafe_recalculate_atmos_connectivity()
var/list/air = list(oxygen, carbon_dioxide, nitrogen, toxins, sleeping_agent, agent_b, temperature)
milla_data = milla_atmos_airtight + list(atmos_mode, SSmapping.environments[atmos_environment]) + air + milla_superconductivity

/turf/proc/recalculate_atmos_connectivity()
var/datum/milla_safe/recalculate_atmos_connectivity/milla = new()
Expand All @@ -192,48 +184,51 @@
/datum/milla_safe/recalculate_atmos_connectivity

/datum/milla_safe/recalculate_atmos_connectivity/on_run(turf/T)
if(isnull(T))
if(!istype(T))
return

if(T.blocks_air)
set_tile_airtight(T, list(TRUE, TRUE, TRUE, TRUE))
// Will be needed when we go back to having solid tile conductivity.
//reset_superconductivity(src)
reduce_superconductivity(T, list(0, 0, 0, 0))
// This is one of two places expected to call this otherwise-unsafe method.
T.private_unsafe_recalculate_atmos_connectivity()

set_tile_airtight(T, T.milla_atmos_airtight)
reset_superconductivity(T)
reduce_superconductivity(T, T.milla_superconductivity)

/// This method is unsafe to use because it only updates milla_* properties, but does not write them to MILLA. Use recalculate_atmos_connectivity() instead.
/turf/proc/private_unsafe_recalculate_atmos_connectivity()
if(blocks_air)
milla_atmos_airtight = list(TRUE, TRUE, TRUE, TRUE)
milla_superconductivity = list(0, 0, 0, 0)
return

var/list/atmos_airtight = list(
!T.CanAtmosPass(NORTH, FALSE),
!T.CanAtmosPass(EAST, FALSE),
!T.CanAtmosPass(SOUTH, FALSE),
!T.CanAtmosPass(WEST, FALSE))
milla_atmos_airtight = list(
!CanAtmosPass(NORTH, FALSE),
!CanAtmosPass(EAST, FALSE),
!CanAtmosPass(SOUTH, FALSE),
!CanAtmosPass(WEST, FALSE))

var/list/superconductivity = list(
milla_superconductivity = list(
OPEN_HEAT_TRANSFER_COEFFICIENT,
OPEN_HEAT_TRANSFER_COEFFICIENT,
OPEN_HEAT_TRANSFER_COEFFICIENT,
OPEN_HEAT_TRANSFER_COEFFICIENT)

for(var/obj/O in T)
for(var/obj/O in src)
if(istype(O, /obj/item))
// Items can't block atmos.
continue
if(!O.CanAtmosPass(NORTH))
atmos_airtight[INDEX_NORTH] = TRUE
milla_atmos_airtight[INDEX_NORTH] = TRUE
if(!O.CanAtmosPass(EAST))
atmos_airtight[INDEX_EAST] = TRUE
milla_atmos_airtight[INDEX_EAST] = TRUE
if(!O.CanAtmosPass(SOUTH))
atmos_airtight[INDEX_SOUTH] = TRUE
milla_atmos_airtight[INDEX_SOUTH] = TRUE
if(!O.CanAtmosPass(WEST))
atmos_airtight[INDEX_WEST] = TRUE
superconductivity[INDEX_NORTH] = min(superconductivity[INDEX_NORTH], O.get_superconductivity(NORTH))
superconductivity[INDEX_EAST] = min(superconductivity[INDEX_EAST], O.get_superconductivity(EAST))
superconductivity[INDEX_SOUTH] = min(superconductivity[INDEX_SOUTH], O.get_superconductivity(SOUTH))
superconductivity[INDEX_WEST] = min(superconductivity[INDEX_WEST], O.get_superconductivity(WEST))

set_tile_airtight(T, atmos_airtight)
reset_superconductivity(T)
reduce_superconductivity(T, superconductivity)
milla_atmos_airtight[INDEX_WEST] = TRUE
milla_superconductivity[INDEX_NORTH] = min(milla_superconductivity[INDEX_NORTH], O.get_superconductivity(NORTH))
milla_superconductivity[INDEX_EAST] = min(milla_superconductivity[INDEX_EAST], O.get_superconductivity(EAST))
milla_superconductivity[INDEX_SOUTH] = min(milla_superconductivity[INDEX_SOUTH], O.get_superconductivity(SOUTH))
milla_superconductivity[INDEX_WEST] = min(milla_superconductivity[INDEX_WEST], O.get_superconductivity(WEST))

/obj/effect/wind
anchored = TRUE
Expand Down
6 changes: 3 additions & 3 deletions code/modules/awaymissions/zlevel_helpers.dm
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/datum/milla_safe/late_setup_level

// Ensures that atmos and environment are set up.
/datum/milla_safe/late_setup_level/on_run(turfs, smoothTurfs)
/datum/milla_safe/late_setup_level/on_run(turf/bot_left, turf/top_right, smoothTurfs)
var/total_timer = start_watch()
var/subtimer = start_watch()
if(!smoothTurfs)
smoothTurfs = turfs
smoothTurfs = block(bot_left, top_right)

log_debug("Setting up atmos")
/* setup_allturfs is superfluous during server initialization because
* air subsystem will call subsequently call setup_allturfs with _every_
* turf in the world */
if(SSair && SSair.initialized)
SSair.setup_allturfs_sleepless(turfs)
SSair.setup_turfs(bot_left, top_right)
log_debug("\tTook [stop_watch(subtimer)]s")

subtimer = start_watch()
Expand Down
49 changes: 49 additions & 0 deletions rust/src/milla/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::milla::simulate;
use crate::milla::statics::*;
use crate::milla::tick;
use byondapi::global_call::call_global;
use byondapi::map::byond_block;
use byondapi::map::byond_xyz;
use byondapi::prelude::*;
use eyre::eyre;
Expand Down Expand Up @@ -97,6 +98,54 @@ pub(crate) fn internal_create_environment(
buffers.create_environment(tile)
}

/// BYOND API for loading a block of turfs into MILLA with their default air.
#[byondapi::bind]
fn milla_load_turfs(data_property: ByondValue, low_corner: ByondValue, high_corner: ByondValue) -> eyre::Result<ByondValue> {
let property_ref = data_property.get_strid()?;
for turf in byond_block(byond_xyz(&low_corner)?, byond_xyz(&high_corner)?)? {
let (x, y, z) = byond_xyz(&turf)?.coordinates();
let data = turf.read_var_id(property_ref)?.get_list_values()?;
if data.len() != 17 {
return Err(eyre!("data property has the wrong length: {} vs {}", data.len(), 17));
}

internal_set_tile(
x as i32 - 1,
y as i32 - 1,
z as i32 - 1,
conversion::byond_to_option_f32(data[0])?,
conversion::byond_to_option_f32(data[1])?,
conversion::byond_to_option_f32(data[2])?,
conversion::byond_to_option_f32(data[3])?,
conversion::byond_to_option_f32(data[4])?,
conversion::byond_to_option_f32(data[5])?,
conversion::bounded_byond_to_option_f32(data[6], 0.0, f32::INFINITY)?,
conversion::bounded_byond_to_option_f32(data[7], 0.0, f32::INFINITY)?,
conversion::bounded_byond_to_option_f32(data[8], 0.0, f32::INFINITY)?,
conversion::bounded_byond_to_option_f32(data[9], 0.0, f32::INFINITY)?,
conversion::bounded_byond_to_option_f32(data[10], 0.0, f32::INFINITY)?,
conversion::bounded_byond_to_option_f32(data[11], 0.0, f32::INFINITY)?,
conversion::bounded_byond_to_option_f32(data[12], 0.0, f32::INFINITY)?,
None,
Some(0.0),
Some(0.0),
Some(0.0),
)?;

internal_reset_superconductivity(x as i32 - 1, y as i32 - 1, z as i32 - 1)?;
internal_reduce_superconductivity(
x as i32 - 1,
y as i32 - 1,
z as i32 - 1,
conversion::bounded_byond_to_option_f32(data[13], 0.0, 1.0)?,
conversion::bounded_byond_to_option_f32(data[14], 0.0, 1.0)?,
conversion::bounded_byond_to_option_f32(data[15], 0.0, 1.0)?,
conversion::bounded_byond_to_option_f32(data[16], 0.0, 1.0)?,
)?;
}
Ok(ByondValue::null())
}

/// BYOND API for setting the atmos details of a tile.
#[byondapi::bind]
fn milla_set_tile(
Expand Down
Loading