Skip to content

Commit

Permalink
Readds Atmos freezing to loading maps (#28111)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Contrabang and paradisess13[bot] authored Feb 8, 2025
1 parent 2177951 commit 5237a14
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 6 deletions.
7 changes: 7 additions & 0 deletions code/__DEFINES/rust.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
/proc/byondapi_stack_trace(err)
CRASH(err)

// MARK: MILLA

/proc/milla_init_z(z)
return RUSTLIB_CALL(milla_initialize, z)

Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions code/datums/helper_datums/map_template.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions code/modules/awaymissions/zlevel_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 changes: 21 additions & 0 deletions rust/src/milla/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rust/src/milla/constants.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions rust/src/milla/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -412,6 +413,7 @@ impl ZLevel {
ZLevel {
tiles: unbuilt.into_boxed_slice().try_into().unwrap(),
active_pressure_chunks: HashSet::new(),
frozen: false,
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down
12 changes: 7 additions & 5 deletions rust/src/milla/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
Binary file modified rustlibs.dll
Binary file not shown.
Binary file modified rustlibs_prod.dll
Binary file not shown.
Binary file modified tools/ci/librustlibs_ci.so
Binary file not shown.

0 comments on commit 5237a14

Please sign in to comment.