Readds Atmos freezing to loading maps (#28111)

* Adds Z-level freezing to MILLA

spacing fix

lets try that again

Build Rust library

update

* Build Rust library

* Build Rust library

---------

Co-authored-by: paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
This commit is contained in:
Contrabang
2025-02-08 17:07:28 +00:00
committed by GitHub
co-authored by paradisess13[bot] <165046124+paradisess13[bot]@users.noreply.github.com>
parent 21779519a3
commit 5237a148cc
10 changed files with 53 additions and 6 deletions
+7
View File
@@ -57,6 +57,8 @@
/proc/byondapi_stack_trace(err)
CRASH(err)
// MARK: MILLA
/proc/milla_init_z(z)
return RUSTLIB_CALL(milla_initialize, z)
@@ -116,6 +118,11 @@
/proc/create_environment(oxygen, carbon_dioxide, nitrogen, toxins, sleeping_agent, agent_b, temperature)
return RUSTLIB_CALL(milla_create_environment, oxygen, carbon_dioxide, nitrogen, toxins, sleeping_agent, agent_b, temperature)
/proc/set_zlevel_freeze(z, bool_frozen)
return RUSTLIB_CALL(milla_set_zlevel_frozen, z, bool_frozen)
// MARK: MapManip
/proc/mapmanip_read_dmm(mapname)
return RUSTLIB_CALL(mapmanip_read_dmm_file, mapname)
@@ -51,6 +51,9 @@
// if given a multi-z template
// it might need to be adapted for that when that time comes
GLOB.space_manager.add_dirt(placement.z)
var/datum/milla_safe/freeze_z_level/milla_freeze = new()
milla_freeze.invoke_async(T.z)
UNTIL(milla_freeze.done)
try
var/list/bounds = GLOB.maploader.load_map(get_file(), min_x, min_y, placement.z, shouldCropMap = TRUE)
if(!bounds)
@@ -13,6 +13,8 @@
* turf in the world */
if(SSair && SSair.initialized)
SSair.setup_turfs(bot_left, top_right)
log_debug("Unfreezing atmos.")
set_zlevel_freeze(bot_left.z, FALSE)
log_debug("\tTook [stop_watch(subtimer)]s")
subtimer = start_watch()
@@ -39,3 +41,12 @@
for(var/otherthing in T)
qdel(otherthing)
T.ChangeTurf(T.baseturf)
/datum/milla_safe/freeze_z_level
var/done = FALSE
// Ensures that atmos is frozen before loading
/datum/milla_safe/freeze_z_level/on_run(z)
log_debug("Freezing atmos.")
set_zlevel_freeze(z, TRUE)
done = TRUE
+21
View File
@@ -703,6 +703,27 @@ fn milla_get_tick_time() -> eyre::Result<ByondValue> {
))
}
/// BYOND API for freezing a specific z-level.
#[byondapi::bind]
fn milla_set_zlevel_frozen(
byond_z: ByondValue,
byond_frozen: ByondValue,
) -> eyre::Result<ByondValue> {
let z = f32::try_from(byond_z)? as i32 - 1;
let frozen = bool::try_from(byond_frozen)?;
let buffers = BUFFERS.get().ok_or(eyre!("BUFFERS not initialized."))?;
let active = buffers.get_active().read().unwrap();
let maybe_z_level = active.0[z as usize].try_write();
if maybe_z_level.is_err() {
return Err(eyre!(
"Tried to freeze or unfreeze during asynchronous, read-only atmos. Use a /datum/milla_safe/..."
));
}
let mut z_level = maybe_z_level.unwrap();
z_level.frozen = frozen;
Ok(ByondValue::null())
}
// Yay, tests!
#[cfg(test)]
mod tests {
+1 -1
View File
@@ -1,5 +1,5 @@
/// How many Z levels we allow before being suspicious that the wrong number was sent.
pub(crate) const MAX_Z_LEVELS: i32 = 10;
pub(crate) const MAX_Z_LEVELS: i32 = 15;
/// How big is the map? Assumed square.
pub(crate) const MAP_SIZE: usize = 255;
+3
View File
@@ -401,6 +401,7 @@ impl From<&InterestingTile> for Vec<ByondValue> {
pub(crate) struct ZLevel {
tiles: Box<[Tile; MAP_SIZE * MAP_SIZE]>,
pub(crate) active_pressure_chunks: HashSet<(u8, u8)>,
pub(crate) frozen: bool,
}
impl ZLevel {
@@ -412,6 +413,7 @@ impl ZLevel {
ZLevel {
tiles: unbuilt.into_boxed_slice().try_into().unwrap(),
active_pressure_chunks: HashSet::new(),
frozen: false,
}
}
@@ -455,6 +457,7 @@ impl ZLevel {
self.tiles[i].copy_from(&other.tiles[i]);
}
self.active_pressure_chunks = other.active_pressure_chunks.clone();
self.frozen = other.frozen;
}
}
+7 -5
View File
@@ -95,12 +95,14 @@ pub(crate) fn tick_z_level(
// Initialize the new frame as a copy of the old one.
next.copy_from(&prev);
simulate::find_walls(&mut next);
simulate::update_wind(&prev, &mut next);
simulate::flow_air(&prev, &mut next)?;
simulate::post_process(&prev, &mut next, &environments, new_interesting_tiles, z)?;
if !prev.frozen {
simulate::find_walls(&mut next);
simulate::update_wind(&prev, &mut next);
simulate::flow_air(&prev, &mut next)?;
simulate::post_process(&prev, &mut next, &environments, new_interesting_tiles, z)?;
next.active_pressure_chunks.clear();
next.active_pressure_chunks.clear();
}
Ok(())
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.