diff --git a/.github/workflows/auxmos.yml b/.github/workflows/auxmos.yml index 9c823ea..820d52c 100644 --- a/.github/workflows/auxmos.yml +++ b/.github/workflows/auxmos.yml @@ -21,7 +21,7 @@ jobs: with: toolchain: stable command: build - args: --target i686-pc-windows-msvc --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,slow_decompression + args: --target i686-pc-windows-msvc --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,explosive_decompression - name: Upload artifact uses: actions/upload-artifact@v1 with: @@ -52,7 +52,7 @@ jobs: with: toolchain: stable command: build - args: --target i686-unknown-linux-gnu --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,slow_decompression + args: --target i686-unknown-linux-gnu --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,explosive_decompression - name: Upload artifact uses: actions/upload-artifact@v1 with: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a4f6c6b..d9e0b3f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: sudo apt update sudo apt install g++-multilib -y - name: Build auxmos - run: cargo build --target=i686-unknown-linux-gnu --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,slow_decompression + run: cargo build --target=i686-unknown-linux-gnu --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,explosive_decompression - uses: actions/upload-artifact@v2 with: name: Linux compile diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a509d47..20a2508 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -16,4 +16,4 @@ jobs: sudo apt update sudo apt install g++-multilib -y - name: Check auxmos build - run: cargo check --target=i686-unknown-linux-gnu --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,slow_decompression + run: cargo check --target=i686-unknown-linux-gnu --release --features trit_fire_hook,plasma_fire_hook,generic_fire_hook,xenomedes_fusion,explosive_decompression diff --git a/Cargo.toml b/Cargo.toml index 7a30eb5..d6db611 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ xenomedes_fusion = [] generic_fire_hook = ["reaction_hooks"] all_reaction_hooks = ["fusion_hook", "trit_fire_hook", "plasma_fire_hook", "generic_fire_hook"] explosive_decompression = ["monstermos"] -slow_decompression = ["explosive_decompression"] putnamos_decompression = ["putnamos"] [lib] diff --git a/src/turfs.rs b/src/turfs.rs index c14ad89..f4ec645 100644 --- a/src/turfs.rs +++ b/src/turfs.rs @@ -157,6 +157,9 @@ static mut TURF_GASES: Option> = Non static mut TURF_TEMPERATURES: Option> = None; // We store planetary atmos by hash of the initial atmos string here for speed. static mut PLANETARY_ATMOS: Option> = None; +// Turfs with firelocks are stored for explosive decompression speed +#[cfg(feature = "explosive_decompression")] +static mut FIRELOCK_TURFS: Option> = None; #[init(partial)] fn _initialize_turf_statics() -> Result<(), String> { @@ -164,6 +167,10 @@ fn _initialize_turf_statics() -> Result<(), String> { 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(()) } @@ -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 @@ -189,6 +200,11 @@ fn turf_temperatures() -> &'static DashMap { unsafe { TURF_TEMPERATURES.as_ref().unwrap() } } +#[cfg(feature = "explosive_decompression")] +fn firelock_turfs() -> &'static DashMap { + 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(|_| { diff --git a/src/turfs/monstermos.rs b/src/turfs/monstermos.rs index 9f04681..4f15a5b 100644 --- a/src/turfs/monstermos.rs +++ b/src/turfs/monstermos.rs @@ -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, @@ -25,7 +41,7 @@ struct MonstermosInfo { const OPP_DIR_INDEX: [usize; 7] = [1, 0, 3, 2, 5, 4, 6]; //only used by slow decomp -const _DECOMP_REMOVE_RATIO: f32 = 5.0; +const DECOMP_REMOVE_RATIO: f32 = 4_f32; impl MonstermosInfo { fn adjust_eq_movement(&mut self, adjacent: &mut Self, dir_index: usize, amount: f32) { @@ -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(); } } @@ -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]; @@ -241,15 +257,15 @@ 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; } } } } } - let _moles_sucked = (total_moles - / ((progression_order.len() - spess_turfs_len) as f64)) as f32 - / _DECOMP_REMOVE_RATIO; + let mut slowable = false; + if progression_order.len() < 500 { + slowable = true + } let hpd = auxtools::Value::globals() .get(byond_string!("SSair"))? .get_list(byond_string!("high_pressure_delta")) @@ -318,14 +334,11 @@ fn explosively_depressurize( )?; } - #[cfg(not(feature = "slow_decompression"))] - { + if slowable == true { + m.clear_vol(m.total_moles() /DECOMP_REMOVE_RATIO); + } else { m.clear_air(); } - #[cfg(feature = "slow_decompression")] - { - m.clear_vol(_moles_sucked); - } byond_turf.call("handle_decompression_floor_rip", &[&Value::from(sum)])?; }