diff --git a/Cargo.lock b/Cargo.lock index d3221dd6..6c146d6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" +dependencies = [ + "const-random", +] + [[package]] name = "ahash" version = "0.7.6" @@ -28,7 +37,6 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "auxcallback" version = "0.2.1" -source = "git+https://github.com/Putnam3145/auxcallback#82e7561361440a28e7c4381548859c45e73d72f0" dependencies = [ "auxtools", "flume", @@ -37,11 +45,10 @@ dependencies = [ [[package]] name = "auxcleanup" version = "0.1.0" -source = "git+https://github.com/Putnam3145/auxcleanup#28654b8f924359b9852dce01720d5a9323abd6f9" dependencies = [ "auxcleanup-impl", "auxtools", - "detour 0.7.1", + "detour", "inventory", "quote", "syn", @@ -50,7 +57,6 @@ dependencies = [ [[package]] name = "auxcleanup-impl" version = "0.1.0" -source = "git+https://github.com/Putnam3145/auxcleanup#28654b8f924359b9852dce01720d5a9323abd6f9" dependencies = [ "inventory", "proc-macro2", @@ -62,13 +68,13 @@ dependencies = [ name = "auxmos" version = "1.1.1" dependencies = [ - "ahash", + "ahash 0.7.6", "atomic_float", "auxcallback", "auxcleanup", "auxtools", "crossbeam", - "dashmap", + "dashmap 5.3.4", "float-ord", "flume", "fxhash", @@ -84,12 +90,14 @@ dependencies = [ [[package]] name = "auxtools" version = "0.1.0" -source = "git+https://github.com/willox/auxtools#9204e120e2440578259a610ba6aedfa1529463c6" +source = "git+https://github.com/willox/auxtools#9b34d37036cdf59cb15019421c4c6cfaac4762b2" dependencies = [ - "ahash", + "ahash 0.7.6", "auxtools-impl", "cc", - "detour 0.8.1", + "ctor", + "dashmap 3.11.10", + "detour", "fxhash", "inventory", "lazy_static", @@ -101,7 +109,7 @@ dependencies = [ [[package]] name = "auxtools-impl" version = "0.1.0" -source = "git+https://github.com/willox/auxtools#9204e120e2440578259a610ba6aedfa1529463c6" +source = "git+https://github.com/willox/auxtools#9b34d37036cdf59cb15019421c4c6cfaac4762b2" dependencies = [ "hex", "proc-macro2", @@ -145,6 +153,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "const-random" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f590d95d011aa80b063ffe3253422ed5aa462af4e9867d43ce8337562bac77c4" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40" +dependencies = [ + "getrandom", + "lazy_static", + "proc-macro-hack", + "tiny-keccak", +] + [[package]] name = "crossbeam" version = "0.8.1" @@ -214,6 +244,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "ctor" version = "0.1.22" @@ -224,6 +260,17 @@ dependencies = [ "syn", ] +[[package]] +name = "dashmap" +version = "3.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f260e2fc850179ef410018660006951c1b55b79e8087e87111a2c388994b9b5" +dependencies = [ + "ahash 0.3.8", + "cfg-if 0.1.10", + "num_cpus", +] + [[package]] name = "dashmap" version = "5.3.4" @@ -237,22 +284,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "detour" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078595bac2ff1822ae53ae3ca1c1ffca97897ecc959adf0137152bfdc278d0d3" -dependencies = [ - "cfg-if 0.1.10", - "generic-array 0.13.3", - "lazy_static", - "libc", - "libudis86-sys", - "mmap-fixed", - "region", - "slice-pool", -] - [[package]] name = "detour" version = "0.8.1" @@ -260,7 +291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3c83fabcc3bc336e19320c13576ea708a15deec201d6b879b7ad1b92734d7b9" dependencies = [ "cfg-if 1.0.0", - "generic-array 0.14.5", + "generic-array", "lazy_static", "libc", "libudis86-sys", @@ -283,9 +314,9 @@ checksum = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d" [[package]] name = "flume" -version = "0.10.12" +version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" dependencies = [ "futures-core", "futures-sink", @@ -315,15 +346,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "generic-array" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f797e67af32588215eaaab8327027ee8e71b9dd0b2b26996aedf20c030fce309" -dependencies = [ - "typenum", -] - [[package]] name = "generic-array" version = "0.14.5" @@ -398,24 +420,12 @@ dependencies = [ [[package]] name = "inventory" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb5160c60ba1e809707918ee329adb99d222888155835c6feedba19f6c3fd4" +checksum = "84344c6e0b90a9e2b6f3f9abe5cc74402684e348df7b32adca28747e0cef091a" dependencies = [ "ctor", "ghost", - "inventory-impl", -] - -[[package]] -name = "inventory-impl" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548" -dependencies = [ - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -590,6 +600,12 @@ dependencies = [ "syn", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" version = "1.0.39" @@ -691,6 +707,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index c45efa38..1ab7210d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,55 +1,12 @@ -[package] -name = "auxmos" -version = "1.1.1" -authors = ["Putnam "] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -default = ["auxcleanup_gas_deletion", "turf_processing"] -auxcleanup_gas_deletion = ["auxcleanup"] -zas_hooks = [] -turf_processing = [] -equalization = ["turf_processing"] -monstermos = ["equalization"] -putnamos = ["equalization"] -katmos = ["equalization"] -reaction_hooks = [] -plasma_fire_hook = ["reaction_hooks"] -trit_fire_hook = ["reaction_hooks"] -fusion_hook = ["reaction_hooks"] -generic_fire_hook = ["reaction_hooks"] -all_reaction_hooks = ["fusion_hook", "trit_fire_hook", "plasma_fire_hook", "generic_fire_hook"] -explosive_decompression = ["monstermos"] -putnamos_decompression = ["putnamos"] - -[lib] -crate-type = ["cdylib"] - -[dependencies] -auxtools = { git = "https://github.com/willox/auxtools"} -auxcallback = { git = "https://github.com/Putnam3145/auxcallback" } -auxcleanup = { git = "https://github.com/Putnam3145/auxcleanup", optional = true} -itertools = "0.10.3" -rayon = "1.5.1" -float-ord = "0.3.2" -crossbeam = "0.8.1" -flume = "0.10.11" -parking_lot = "0.12.0" -fxhash = "0.2.1" -nonmax = "0.5.0" -ahash = "0.7.6" -lazy_static = "1.4.0" -indexmap = { version = "1.8.0", features = ["rayon"] } -dashmap = { version = "5.2.0", features = ["rayon"] } -atomic_float = "0.1.0" - -[dependencies.tinyvec] -version = "1.5.1" -features = ["rustc_1_55", "alloc"] +[workspace] +members = [ + "crates/auxmos", + "crates/auxcleanup", + "crates/auxcallback", +] [profile.release] -lto = 'thin' +lto = 'fat' debug = true +codegen-units = 1 panic = 'abort' diff --git a/crates/auxcallback/Cargo.toml b/crates/auxcallback/Cargo.toml new file mode 100644 index 00000000..7d32412f --- /dev/null +++ b/crates/auxcallback/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "auxcallback" +version = "0.2.1" +authors = ["Putnam "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["lib"] + +[dependencies] +auxtools = { git = "https://github.com/willox/auxtools" } +flume = "0.10.13" diff --git a/crates/auxcallback/src/lib.rs b/crates/auxcallback/src/lib.rs new file mode 100644 index 00000000..9819a646 --- /dev/null +++ b/crates/auxcallback/src/lib.rs @@ -0,0 +1,122 @@ +use auxtools::*; + +use std::time::{Duration, Instant}; + +use std::sync::{ + atomic::{AtomicBool, Ordering::Relaxed}, + Arc, +}; + +enum Timer { + Fast(Arc), + Slow(Instant, Duration), +} + +impl Timer { + fn new(time: Duration) -> Self { + let done = Arc::new(AtomicBool::new(false)); + let thread_done = Arc::clone(&done); + let builder = std::thread::Builder::new().name("auxcallback-timer".to_string()); + match builder.spawn(move || { + std::thread::sleep(time); + thread_done.store(true, Relaxed); + }) { + Ok(_) => Self::Fast(done), + Err(_) => Self::Slow(Instant::now(), time), + } + } + fn check(&self) -> bool { + match self { + Self::Fast(done) => done.load(Relaxed), + Self::Slow(time, duration) => time.elapsed() >= *duration, + } + } +} + +type DeferredFunc = Box Result<(), Runtime> + Send + Sync>; + +type CallbackChannel = (flume::Sender, flume::Receiver); + +static mut CALLBACK_CHANNEL: Option = None; + +#[init(partial)] +fn _start_callbacks() -> Result<(), String> { + unsafe { + CALLBACK_CHANNEL = Some(flume::bounded(100_000)); + } + Ok(()) +} + +#[shutdown] +fn _clean_callbacks() { + unsafe { CALLBACK_CHANNEL = None } +} + +fn with_callback_receiver(f: impl Fn(&flume::Receiver) -> T) -> T { + f(unsafe { &CALLBACK_CHANNEL.as_ref().unwrap().1 }) +} + +/// This gives you a copy of the callback sender. Send to it with try_send or send, then later it'll be processed +/// if one of the process_callbacks functions is called for any reason. +pub fn byond_callback_sender() -> flume::Sender { + unsafe { CALLBACK_CHANNEL.as_ref().unwrap().0.clone() } +} + +/// Goes through every single outstanding callback and calls them. +fn process_callbacks() { + let stack_trace = Proc::find("/proc/auxtools_stack_trace").unwrap(); + with_callback_receiver(|receiver| { + for callback in receiver.try_iter() { + if let Err(e) = callback() { + let _ = stack_trace.call(&[&Value::from_string(e.message.as_str()).unwrap()]); + } + } + }) +} + +/// Goes through every single outstanding callback and calls them, until a given time limit is reached. +fn process_callbacks_for(duration: Duration) -> bool { + let stack_trace = Proc::find("/proc/auxtools_stack_trace").unwrap(); + let timer = Timer::new(duration); + with_callback_receiver(|receiver| { + for callback in receiver.try_iter() { + if let Err(e) = callback() { + let _ = stack_trace.call(&[&Value::from_string(e.message.as_str()).unwrap()]); + } + if timer.check() { + return true; + } + } + false + }) +} + +/// Goes through every single outstanding callback and calls them, until a given time limit in milliseconds is reached. +pub fn process_callbacks_for_millis(millis: u64) -> bool { + process_callbacks_for(Duration::from_millis(millis)) +} + +/// This function is to be called from byond, preferably once a tick. +/// Calling with no arguments will process every outstanding callback. +/// Calling with one argument will process the callbacks until a given time limit is reached. +/// Time limit is in milliseconds. +/// This has to be manually hooked in the code, e.g. +/// ``` +/// #[hook("/proc/process_atmos_callbacks")] +/// fn _atmos_callback_handle() { +/// auxcallback::callback_processing_hook(args) +/// } +/// ``` + +pub fn callback_processing_hook(args: &mut Vec) -> DMResult { + match args.len() { + 0 => { + process_callbacks(); + Ok(Value::null()) + } + _ => { + let arg_limit = args.get(0).unwrap().as_number()? as u64; + Ok(Value::from(process_callbacks_for_millis(arg_limit))) + } + } +} diff --git a/crates/auxcleanup/Cargo.toml b/crates/auxcleanup/Cargo.toml new file mode 100644 index 00000000..03b4a1dd --- /dev/null +++ b/crates/auxcleanup/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "auxcleanup" +version = "0.1.0" +authors = ["Putnam "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["lib"] + +[dependencies] +auxtools = { git = "https://github.com/willox/auxtools" } +inventory = "0.2.3" +quote = "1.0" +auxcleanup-impl = { path = "./auxcleanup-impl", version = "0.1.0", package = "auxcleanup-impl"} + +[dependencies.detour] +version = "0.8.1" +default-features = false + +[dependencies.syn] +version = "1.0" +features = ["full"] diff --git a/crates/auxcleanup/auxcleanup-impl/Cargo.toml b/crates/auxcleanup/auxcleanup-impl/Cargo.toml new file mode 100644 index 00000000..0c77922b --- /dev/null +++ b/crates/auxcleanup/auxcleanup-impl/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "auxcleanup-impl" +version = "0.1.0" +authors = ["Putnam "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +proc-macro = true + +[dependencies] +inventory = "0.2.3" +quote = "1.0" +proc-macro2 = "1.0" + +[dependencies.syn] +version = "1.0" +features = ["full"] diff --git a/crates/auxcleanup/auxcleanup-impl/src/lib.rs b/crates/auxcleanup/auxcleanup-impl/src/lib.rs new file mode 100644 index 00000000..f2b611eb --- /dev/null +++ b/crates/auxcleanup/auxcleanup-impl/src/lib.rs @@ -0,0 +1,21 @@ +use proc_macro::TokenStream; +use quote::quote; + +#[proc_macro_attribute] +pub fn datum_del(_: TokenStream, item: TokenStream) -> TokenStream { + let func = syn::parse_macro_input!(item as syn::ItemFn); + let func_name = &func.sig.ident; + + let inventory_define = quote! { + inventory::submit!( + DelDatumFunc(#func_name) + ); + }; + + let code = quote! { + #func + #inventory_define + }; + + code.into() +} diff --git a/crates/auxcleanup/src/lib.rs b/crates/auxcleanup/src/lib.rs new file mode 100644 index 00000000..0cd56dc1 --- /dev/null +++ b/crates/auxcleanup/src/lib.rs @@ -0,0 +1,64 @@ +use auxtools::*; + +pub use auxcleanup_impl::datum_del; + +use detour::RawDetour; + +use std::ffi::c_void; + +static mut DEL_DATUM: *const c_void = std::ptr::null(); + +static mut DEL_DATUM_ORIGINAL: Option c_void> = None; + +#[init(full)] +fn del_hooking_init() -> Result<(), String> { + let byondcore = sigscan::Scanner::for_module(BYONDCORE).unwrap(); + if cfg!(windows) { + let ptr = byondcore + .find(signature!( + "55 8b ec 8b 4d 08 3b 0d ?? ?? ?? ?? 73 55 a1 ?? ?? ?? ?? 8b 04 88 85 c0 74 49 8b 50 ?? 81 fa 00 00 00 70" + )) + .ok_or("Couldn't find DEL_DATUM")?; + + unsafe { + DEL_DATUM = ptr as *const c_void; + } + } + + if cfg!(unix) { + let ptr = byondcore + .find(signature!( + "55 89 e5 53 83 ec 44 8b 45 08 3b 05 ?? ?? ?? ?? 73 2c 8b 15 ?? ?? ?? ?? 8b 0c 82 85 c9 74 1f 8b 51 ?? 81 fa 00 00 00 70" + )) + .ok_or("Couldn't find DEL_DATUM")?; + + unsafe { + DEL_DATUM = ptr as *const c_void; + } + } + + unsafe { + let hook = RawDetour::new(DEL_DATUM as *const (), del_datum_hook as *const ()) + .map_err(|_| "Couldn't detour DEL_DATUM")?; + + hook.enable() + .map_err(|_| "Couldn't enable DEL_DATUM detour")?; + + DEL_DATUM_ORIGINAL = Some(std::mem::transmute(hook.trampoline())); + + std::mem::forget(hook); + } + Ok(()) +} + +pub struct DelDatumFunc(pub fn(u32)); + +#[no_mangle] +extern "C" fn del_datum_hook(datum_id: u32) -> c_void { + for hook in inventory::iter:: { + hook.0(datum_id); + } + unsafe { DEL_DATUM_ORIGINAL.unwrap()(datum_id) } +} + +inventory::collect!(DelDatumFunc); diff --git a/crates/auxmos/Cargo.toml b/crates/auxmos/Cargo.toml new file mode 100644 index 00000000..d457c00c --- /dev/null +++ b/crates/auxmos/Cargo.toml @@ -0,0 +1,55 @@ +[package] +name = "auxmos" +version = "1.1.1" +authors = ["Putnam "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = ["auxcleanup_gas_deletion", "turf_processing"] +auxcleanup_gas_deletion = ["auxcleanup"] +zas_hooks = [] +turf_processing = [] +equalization = ["turf_processing"] +monstermos = ["equalization"] +putnamos = ["equalization"] +katmos = ["equalization"] +reaction_hooks = [] +plasma_fire_hook = ["reaction_hooks"] +trit_fire_hook = ["reaction_hooks"] +fusion_hook = ["reaction_hooks"] +generic_fire_hook = ["reaction_hooks"] +all_reaction_hooks = ["fusion_hook", "trit_fire_hook", "plasma_fire_hook", "generic_fire_hook"] +explosive_decompression = ["monstermos"] +putnamos_decompression = ["putnamos"] + +[lib] +crate-type = ["cdylib"] + +[dependencies] +auxtools = { git = "https://github.com/willox/auxtools"} +auxcallback = { path = "./../auxcallback" } +auxcleanup = { path = "./../auxcleanup", optional = true} +itertools = "0.10.3" +rayon = "1.5.1" +float-ord = "0.3.2" +crossbeam = "0.8.1" +flume = "0.10.11" +parking_lot = "0.12.0" +fxhash = "0.2.1" +nonmax = "0.5.0" +ahash = "0.7.6" +lazy_static = "1.4.0" +indexmap = { version = "1.8.0", features = ["rayon"] } +dashmap = { version = "5.2.0", features = ["rayon"] } +atomic_float = "0.1.0" + +[dependencies.tinyvec] +version = "1.5.1" +features = ["rustc_1_55", "alloc"] + +[profile.release] +lto = 'thin' +debug = true +panic = 'abort' diff --git a/src/callbacks.rs b/crates/auxmos/src/callbacks.rs similarity index 100% rename from src/callbacks.rs rename to crates/auxmos/src/callbacks.rs diff --git a/src/gas.rs b/crates/auxmos/src/gas.rs similarity index 100% rename from src/gas.rs rename to crates/auxmos/src/gas.rs diff --git a/src/gas/constants.rs b/crates/auxmos/src/gas/constants.rs similarity index 100% rename from src/gas/constants.rs rename to crates/auxmos/src/gas/constants.rs diff --git a/src/gas/mixture.rs b/crates/auxmos/src/gas/mixture.rs similarity index 100% rename from src/gas/mixture.rs rename to crates/auxmos/src/gas/mixture.rs diff --git a/src/gas/types.rs b/crates/auxmos/src/gas/types.rs similarity index 99% rename from src/gas/types.rs rename to crates/auxmos/src/gas/types.rs index 3a1be360..2525507f 100644 --- a/src/gas/types.rs +++ b/crates/auxmos/src/gas/types.rs @@ -295,7 +295,7 @@ fn _hook_init() { _hook_register_gas( &Value::null(), &Value::null(), - &mut vec![data.get(data.get(i)?)?], + vec![data.get(data.get(i)?)?], )?; } *REACTION_INFO.write() = Some(get_reaction_info()); diff --git a/src/lib.rs b/crates/auxmos/src/lib.rs similarity index 99% rename from src/lib.rs rename to crates/auxmos/src/lib.rs index af581e87..7371190b 100644 --- a/src/lib.rs +++ b/crates/auxmos/src/lib.rs @@ -23,7 +23,7 @@ use gas::constants::{GAS_MIN_MOLES, MINIMUM_MOLES_DELTA_TO_MOVE, STOP_REACTIONS} /// Args: (ms). Runs callbacks until time limit is reached. If time limit is omitted, runs all callbacks. #[hook("/proc/process_atmos_callbacks")] fn _atmos_callback_handle() { - auxcallback::callback_processing_hook(args) + auxcallback::callback_processing_hook(&mut args) } /// Fills in the first unused slot in the gas mixtures vector, or adds another one, then sets the argument Value to point to it. diff --git a/src/reaction.rs b/crates/auxmos/src/reaction.rs similarity index 98% rename from src/reaction.rs rename to crates/auxmos/src/reaction.rs index bb93ae1d..f1f3b328 100644 --- a/src/reaction.rs +++ b/crates/auxmos/src/reaction.rs @@ -1,7 +1,7 @@ #[cfg(feature = "reaction_hooks")] pub mod hooks; -use auxtools::{byond_string, inventory, runtime, shutdown, DMResult, Value}; +use auxtools::{byond_string, runtime, shutdown, DMResult, Value}; use std::cell::RefCell; diff --git a/src/reaction/hooks.rs b/crates/auxmos/src/reaction/hooks.rs similarity index 100% rename from src/reaction/hooks.rs rename to crates/auxmos/src/reaction/hooks.rs diff --git a/src/turfs.rs b/crates/auxmos/src/turfs.rs similarity index 100% rename from src/turfs.rs rename to crates/auxmos/src/turfs.rs diff --git a/src/turfs/katmos.rs b/crates/auxmos/src/turfs/katmos.rs similarity index 99% rename from src/turfs/katmos.rs rename to crates/auxmos/src/turfs/katmos.rs index b96b577e..fc5ed527 100644 --- a/src/turfs/katmos.rs +++ b/crates/auxmos/src/turfs/katmos.rs @@ -196,7 +196,7 @@ fn finalize_eq( .ok_or_else(|| runtime!("Couldn't find stack_trace!"))? .call(&[&Value::from_string(e.message.as_str())?])?; } - Ok(Value::null()) + Ok(()) }))); } } @@ -450,7 +450,7 @@ fn explosively_depressurize( max_x: i32, max_y: i32, equalize_hard_turf_limit: usize, -) -> DMResult { +) -> Result<(), Runtime> { let mut info: HashMap, FxBuildHasher> = HashMap::with_hasher(FxBuildHasher::default()); let mut turfs: IndexSet = @@ -504,7 +504,7 @@ fn explosively_depressurize( } } if warned_about_planet_atmos { - return Ok(Value::null()); // planet atmos > space + return Ok(()); // planet atmos > space } } @@ -512,7 +512,7 @@ fn explosively_depressurize( process_aux_callbacks(crate::callbacks::ADJACENCIES); if space_turfs.is_empty() { - return Ok(Value::null()); + return Ok(()); } for i in space_turfs.iter() { @@ -617,7 +617,7 @@ fn explosively_depressurize( m.clear_air(); byond_turf.call("handle_decompression_floor_rip", &[&Value::from(sum)])?; } - Ok(Value::null()) + Ok(()) // if (total_gases_deleted / turfs.len() as f32) > 20.0 && turfs.len() > 10 { // logging I guess // } } @@ -668,7 +668,7 @@ fn flood_fill_equalize_turfs( // NOT ONE OF YOU IS GONNA SURVIVE THIS // (I just made explosions less laggy, you're welcome) if !ignore_zone { - drop(sender.send(Box::new(move || { + drop(sender.try_send(Box::new(move || { explosively_depressurize(i, max_x, max_y, equalize_hard_turf_limit) }))); } @@ -733,7 +733,7 @@ fn process_planet_turfs( let that_turf = unsafe { Value::turf_by_id_unchecked(loc) }; let this_turf = unsafe { Value::turf_by_id_unchecked(i) }; this_turf.call("consider_firelocks", &[&that_turf])?; - Ok(Value::null()) + Ok(()) }))); } if let Some(adj) = turfs diff --git a/src/turfs/monstermos.rs b/crates/auxmos/src/turfs/monstermos.rs similarity index 100% rename from src/turfs/monstermos.rs rename to crates/auxmos/src/turfs/monstermos.rs diff --git a/src/turfs/processing.rs b/crates/auxmos/src/turfs/processing.rs similarity index 99% rename from src/turfs/processing.rs rename to crates/auxmos/src/turfs/processing.rs index 2fceb08c..6ae6141e 100644 --- a/src/turfs/processing.rs +++ b/crates/auxmos/src/turfs/processing.rs @@ -202,7 +202,7 @@ fn _process_turf_start() -> Result<(), String> { byond_string!("high_pressure_turfs"), Value::from(hpt as f32), )?; - Ok(Value::null()) + Ok(()) }))); (low_pressure_turfs, high_pressure_turfs) }; @@ -236,7 +236,7 @@ fn _process_turf_start() -> Result<(), String> { byond_string!("num_group_turfs_processed"), Value::from(processed_turfs as f32), )?; - Ok(Value::null()) + Ok(()) }))); } if info.equalize_enabled { @@ -299,7 +299,7 @@ fn _process_turf_start() -> Result<(), String> { byond_string!("num_equalize_processed"), Value::from(processed_turfs as f32), )?; - Ok(Value::null()) + Ok(()) }))); } { @@ -322,7 +322,7 @@ fn _process_turf_start() -> Result<(), String> { byond_string!("cost_post_process"), Value::from(0.8 * prev_cost + 0.2 * (bench as f32)), )?; - Ok(Value::null()) + Ok(()) }))); } TASKS_RUNNING.fetch_sub(1, Ordering::SeqCst); @@ -545,7 +545,7 @@ fn fdm( } } } - Ok(Value::null()) + Ok(()) }))); }); } @@ -744,7 +744,7 @@ fn post_process() { update_visuals(&turf)?; } } - Ok(Value::null()) + Ok(()) }))); }); for (k, v) in receiver.drain() { @@ -938,7 +938,7 @@ fn _process_heat_start() -> Result<(), String> { drop(sender.try_send(Box::new(move || { let turf = unsafe { Value::turf_by_id_unchecked(i) }; turf.set(byond_string!("to_be_destroyed"), 1.0)?; - Ok(Value::null()) + Ok(()) }))); } }); diff --git a/src/turfs/putnamos.rs b/crates/auxmos/src/turfs/putnamos.rs similarity index 100% rename from src/turfs/putnamos.rs rename to crates/auxmos/src/turfs/putnamos.rs