Skip to content

Commit

Permalink
firelock caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Sep 4, 2021
1 parent 6579c9f commit ec3aa4d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
16 changes: 16 additions & 0 deletions src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ static mut TURF_GASES: Option<DashMap<TurfID, TurfMixture, FxBuildHasher>> = Non
static mut TURF_TEMPERATURES: Option<DashMap<TurfID, ThermalInfo, FxBuildHasher>> = None;
// We store planetary atmos by hash of the initial atmos string here for speed.
static mut PLANETARY_ATMOS: Option<DashMap<u32, Mixture, FxBuildHasher>> = None;
// Turfs with firelocks are stored for explosive decompression speed
#[cfg(feature = "explosive_decompression")]
static mut FIRELOCK_TURFS: Option<DashMap<TurfID, (), FxBuildHasher>> = None;

#[init(partial)]
fn _initialize_turf_statics() -> Result<(), String> {
unsafe {
TURF_GASES = Some(DashMap::with_hasher(FxBuildHasher::default()));
TURF_TEMPERATURES = Some(DashMap::with_hasher(FxBuildHasher::default()));
PLANETARY_ATMOS = Some(DashMap::with_hasher(FxBuildHasher::default()));
#[cfg(feature = "explosive_decompression")]
{
FIRELOCK_TURFS = Some(DashMap::with_hasher(FxBuildHasher::default()));
}
};
Ok(())
}
Expand All @@ -174,6 +181,10 @@ fn _shutdown_turfs() {
TURF_GASES = None;
TURF_TEMPERATURES = None;
PLANETARY_ATMOS = None;
#[cfg(feature = "explosive_decompression")]
{
FIRELOCK_TURFS = None;
}
};
}
// this would lead to undefined info if it were possible for something to put a None on it during operation, but nothing's going to do that
Expand All @@ -189,6 +200,11 @@ fn turf_temperatures() -> &'static DashMap<TurfID, ThermalInfo, FxBuildHasher> {
unsafe { TURF_TEMPERATURES.as_ref().unwrap() }
}

#[cfg(feature = "explosive_decompression")]
fn firelock_turfs() -> &'static DashMap<TurfID, (), FxBuildHasher> {
unsafe { FIRELOCK_TURFS.as_ref().unwrap() }
}

#[hook("/turf/proc/update_air_ref")]
fn _hook_register_turf() {
let simulation_level = args[0].as_number().map_err(|_| {
Expand Down
34 changes: 23 additions & 11 deletions src/turfs/monstermos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ type TransferInfo = [f32; 7];

type MixWithID = (TurfID, TurfMixture);

#[cfg(feature = "explosive_decompression")]
#[hook("/turf/proc/register_firelocks")]
fn _hook_register_firelocks() {
let id = unsafe { src.raw.data.id };
firelock_turfs().insert(id, ());
Ok(Value::null())
}

#[cfg(feature = "explosive_decompression")]
#[hook("/turf/proc/unregister_firelocks")]
fn _hook_unregister_firelocks() {
let id = unsafe { src.raw.data.id };
firelock_turfs().remove(&id);
Ok(Value::null())
}

#[derive(Copy, Clone, Default)]
struct MonstermosInfo {
transfer_dirs: TransferInfo,
Expand Down Expand Up @@ -203,10 +219,12 @@ fn explosively_depressurize(
insert_success = turfs.insert((loc, *adj_m))
};
if insert_success == true {
unsafe { Value::turf_by_id_unchecked(i) }.call(
"consider_firelocks",
&[&unsafe { Value::turf_by_id_unchecked(loc) }],
)?;
if firelock_turfs().contains_key(&loc) {
unsafe { Value::turf_by_id_unchecked(i) }.call(
"consider_firelocks",
&[&unsafe { Value::turf_by_id_unchecked(loc) }],
)?;
}
info.entry(loc).or_default().take();
}
}
Expand All @@ -219,8 +237,6 @@ fn explosively_depressurize(
let cur_info = info.entry(*i).or_default().get_mut();
cur_info.curr_transfer_dir = 6;
}
let spess_turfs_len = progression_order.len();
let mut total_moles: f64 = 0.0;
cur_queue_idx = 0;
while cur_queue_idx < progression_order.len() {
let (i, m) = progression_order[cur_queue_idx];
Expand All @@ -241,7 +257,6 @@ fn explosively_depressurize(
unsafe { Value::turf_by_id_unchecked(loc) }
.set(byond_string!("pressure_specific_target"), &cur_target_turf)?;
adj_orig.set(adj_info);
total_moles += adj_m.total_moles() as f64;
}
}
}
Expand All @@ -251,9 +266,6 @@ fn explosively_depressurize(
if progression_order.len() < 500 {
slowable = true
}
let moles_sucked = (total_moles
/ ((progression_order.len() - spess_turfs_len) as f64)) as f32
/ DECOMP_REMOVE_RATIO;
let hpd = auxtools::Value::globals()
.get(byond_string!("SSair"))?
.get_list(byond_string!("high_pressure_delta"))
Expand Down Expand Up @@ -323,7 +335,7 @@ fn explosively_depressurize(
}

if slowable == true {
m.clear_vol(moles_sucked);
m.clear_vol(m.total_moles() /DECOMP_REMOVE_RATIO);
} else {
m.clear_air();
}
Expand Down

0 comments on commit ec3aa4d

Please sign in to comment.