diff --git a/Cargo.lock b/Cargo.lock index 98e60ab..871bfe3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,8 +123,8 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byondapi" -version = "0.2.1" -source = "git+https://github.com/jupyterkat/byondapi-rs#e4fb95cae12eb6a665472e198f5e01b9929e79db" +version = "0.3.0" +source = "git+https://github.com/jupyterkat/byondapi-rs#ce9d6a76a12da1a7d59023916c101825c3a778e7" dependencies = [ "byondapi-sys", "inventory", @@ -154,7 +154,7 @@ dependencies = [ [[package]] name = "byondapi-sys" version = "0.10.1" -source = "git+https://github.com/jupyterkat/byondapi-rs#e4fb95cae12eb6a665472e198f5e01b9929e79db" +source = "git+https://github.com/jupyterkat/byondapi-rs#ce9d6a76a12da1a7d59023916c101825c3a778e7" dependencies = [ "bindgen", "libloading 0.8.1", @@ -276,12 +276,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -360,9 +360,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ "ahash", "allocator-api2", @@ -374,7 +374,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -411,9 +411,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -453,7 +453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -563,7 +563,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -594,9 +594,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -693,7 +693,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -794,9 +794,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -804,9 +804,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -819,9 +819,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -829,9 +829,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -842,9 +842,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "which" @@ -895,7 +895,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", ] [[package]] @@ -904,13 +913,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -919,42 +943,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "zerocopy" version = "0.7.26" diff --git a/Cargo.toml b/Cargo.toml index cd118a4..09cce0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["turf_processing"] +default = ["turf_processing", "katmos"] zas_hooks = [] turf_processing = [] superconductivity = ["turf_processing"] @@ -50,7 +50,7 @@ ahash = "0.8.6" lazy_static = "1.4.0" indexmap = { version = "2.1.0", features = ["rayon"] } dashmap = { version = "5.5.3", features = ["rayon"] } -hashbrown = "0.14.2" +hashbrown = "0.14.3" atomic_float = "0.1.0" petgraph = "0.6.4" bitflags = "2.4.1" diff --git a/crates/auxcallback/src/lib.rs b/crates/auxcallback/src/lib.rs index e02338f..49abd74 100644 --- a/crates/auxcallback/src/lib.rs +++ b/crates/auxcallback/src/lib.rs @@ -42,7 +42,11 @@ fn process_callbacks() { for callback in receiver.try_iter() { if let Err(e) = callback() { let error_string = format!("{e:?}").try_into().unwrap(); - byondapi::global_call::call_global("stack_trace", &[error_string]).unwrap(); + byondapi::global_call::call_global_id( + byond_string!("stack_trace"), + &[error_string], + ) + .unwrap(); } } }) @@ -56,7 +60,11 @@ fn process_callbacks_for(duration: Duration) -> bool { for callback in receiver.try_iter() { if let Err(e) = callback() { let error_string = format!("{e:?}").try_into().unwrap(); - byondapi::global_call::call_global("stack_trace", &[error_string]).unwrap(); + byondapi::global_call::call_global_id( + byond_string!("stack_trace"), + &[error_string], + ) + .unwrap(); } if timer.elapsed() >= duration { return true; diff --git a/crates/byondapi-binds/byondapi-impl/src/lib.rs b/crates/byondapi-binds/byondapi-impl/src/lib.rs index d56f3cc..5caadcd 100644 --- a/crates/byondapi-binds/byondapi-impl/src/lib.rs +++ b/crates/byondapi-binds/byondapi-impl/src/lib.rs @@ -105,7 +105,7 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream { Ok(val) => val, Err(e) => { let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap(); - ::byondapi::global_call::call_global("stack_trace", &[error_string]).unwrap(); + ::byondapi::global_call::call_global_id(byond_string!("stack_trace"), &[error_string]).unwrap(); ::byondapi::value::ByondValue::null() } } @@ -204,7 +204,7 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream { Ok(val) => val, Err(e) => { let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap(); - ::byondapi::global_call::call_global("stack_trace", &[error_string]).unwrap(); + ::byondapi::global_call::call_global_id(byond_string!("stack_trace"), &[error_string]).unwrap(); ::byondapi::value::ByondValue::null() } } diff --git a/src/gas.rs b/src/gas.rs index 489d8c7..ae7c3a5 100644 --- a/src/gas.rs +++ b/src/gas.rs @@ -186,7 +186,7 @@ impl GasArena { /// If not called from the main thread /// If `NEXT_GAS_IDS` is not initialized, somehow. pub fn register_mix(mut mix: ByondValue) -> Result { - let init_volume = mix.read_number("initial_volume")?; + let init_volume = mix.read_number_id(byond_string!("initial_volume"))?; if NEXT_GAS_IDS.read().as_ref().unwrap().is_empty() { let mut gas_lock = GAS_MIXTURES.write(); let gas_mixtures = gas_lock.as_mut().unwrap(); @@ -232,7 +232,7 @@ impl GasArena { /// If not called from the main thread /// If `NEXT_GAS_IDS` hasn't been initialized, somehow. pub fn unregister_mix(mix: &ByondValue) { - if let Ok(idx) = mix.read_number("_extools_pointer_gasmixture") { + if let Ok(idx) = mix.read_number_id(byond_string!("_extools_pointer_gasmixture")) { let mut next_gas_ids = NEXT_GAS_IDS.write(); next_gas_ids.as_mut().unwrap().push(idx as usize); } else { @@ -248,7 +248,10 @@ pub fn with_mix(mix: &ByondValue, f: F) -> Result where F: FnOnce(&Mixture) -> Result, { - GasArena::with_gas_mixture(mix.read_number("_extools_pointer_gasmixture")? as usize, f) + GasArena::with_gas_mixture( + mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, + f, + ) } /// As `with_mix`, but mutable. @@ -258,7 +261,10 @@ pub fn with_mix_mut(mix: &ByondValue, f: F) -> Result where F: FnOnce(&mut Mixture) -> Result, { - GasArena::with_gas_mixture_mut(mix.read_number("_extools_pointer_gasmixture")? as usize, f) + GasArena::with_gas_mixture_mut( + mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, + f, + ) } /// As `with_mix`, but with two mixes. @@ -269,8 +275,8 @@ where F: FnOnce(&Mixture, &Mixture) -> Result, { GasArena::with_gas_mixtures( - src_mix.read_number("_extools_pointer_gasmixture")? as usize, - arg_mix.read_number("_extools_pointer_gasmixture")? as usize, + src_mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, + arg_mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, f, ) } @@ -283,8 +289,8 @@ where F: FnOnce(&mut Mixture, &mut Mixture) -> Result, { GasArena::with_gas_mixtures_mut( - src_mix.read_number("_extools_pointer_gasmixture")? as usize, - arg_mix.read_number("_extools_pointer_gasmixture")? as usize, + src_mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, + arg_mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, f, ) } @@ -297,8 +303,8 @@ where F: FnMut(&RwLock, &RwLock) -> Result, { GasArena::with_gas_mixtures_custom( - src_mix.read_number("_extools_pointer_gasmixture")? as usize, - arg_mix.read_number("_extools_pointer_gasmixture")? as usize, + src_mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, + arg_mix.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize, f, ) } diff --git a/src/gas/types.rs b/src/gas/types.rs index 6df4cd6..48d1c49 100644 --- a/src/gas/types.rs +++ b/src/gas/types.rs @@ -154,51 +154,63 @@ impl GasType { fn new(gas: &ByondValue, idx: GasIDX) -> Result { Ok(Self { idx, - id: gas.read_string("id")?.into_boxed_str(), - name: gas.read_string("name")?.into_boxed_str(), - flags: gas.read_number("flags").unwrap_or_default() as u32, - specific_heat: gas.read_number("specific_heat")?, - fusion_power: gas.read_number("fusion_power").unwrap_or_default(), - moles_visible: gas.read_number("moles_visible").ok(), + id: gas.read_string_id(byond_string!("id"))?.into_boxed_str(), + name: gas.read_string_id(byond_string!("name"))?.into_boxed_str(), + flags: gas + .read_number_id(byond_string!("flags")) + .unwrap_or_default() as u32, + specific_heat: gas.read_number_id(byond_string!("specific_heat"))?, + fusion_power: gas + .read_number_id(byond_string!("fusion_power")) + .unwrap_or_default(), + moles_visible: gas.read_number_id(byond_string!("moles_visible")).ok(), fire_info: { - if let Ok(temperature) = gas.read_number("oxidation_temperature") { + if let Ok(temperature) = gas.read_number_id(byond_string!("oxidation_temperature")) + { FireInfo::Oxidation(OxidationInfo { temperature, - power: gas.read_number("oxidation_rate")?, + power: gas.read_number_id(byond_string!("oxidation_rate"))?, }) - } else if let Ok(temperature) = gas.read_number("fire_temperature") { + } else if let Ok(temperature) = + gas.read_number_id(byond_string!("fire_temperature")) + { FireInfo::Fuel(FuelInfo { temperature, - burn_rate: gas.read_number("fire_burn_rate")?, + burn_rate: gas.read_number_id(byond_string!("fire_burn_rate"))?, }) } else { FireInfo::None } }, - fire_products: gas.read_var("fire_products").ok().and_then(|product_info| { - if product_info.is_list() { - Some(FireProductInfo::Generic( - product_info - .iter() - .unwrap() - .filter_map(|(k, v)| { - k.get_string().ok().and_then(|s_str| { - v.get_number() - .ok() - .map(|amt| (GasRef::Deferred(s_str), amt)) + fire_products: gas + .read_var_id(byond_string!("fire_products")) + .ok() + .and_then(|product_info| { + if product_info.is_list() { + Some(FireProductInfo::Generic( + product_info + .iter() + .unwrap() + .filter_map(|(k, v)| { + k.get_string().ok().and_then(|s_str| { + v.get_number() + .ok() + .map(|amt| (GasRef::Deferred(s_str), amt)) + }) }) - }) - .collect(), - )) - } else if product_info.is_num() { - Some(FireProductInfo::Plasma) // if we add another snowflake later, add it, but for now we hack this in - } else { - None - } - }), - enthalpy: gas.read_number("enthalpy").unwrap_or_default(), + .collect(), + )) + } else if product_info.is_num() { + Some(FireProductInfo::Plasma) // if we add another snowflake later, add it, but for now we hack this in + } else { + None + } + }), + enthalpy: gas + .read_number_id(byond_string!("enthalpy")) + .unwrap_or_default(), fire_radiation_released: gas - .read_number("fire_radiation_released") + .read_number_id(byond_string!("fire_radiation_released")) .unwrap_or_default(), }) } @@ -233,7 +245,7 @@ pub fn destroy_gas_info_structs() { #[byondapi_binds::bind("/proc/_auxtools_register_gas")] fn hook_register_gas(gas: ByondValue) { - let gas_id = gas.read_string("id")?; + let gas_id = gas.read_string_id(byond_string!("id"))?; match { GAS_INFO_BY_STRING .read() @@ -274,7 +286,7 @@ fn hook_register_gas(gas: ByondValue) { #[byondapi_binds::bind("/proc/auxtools_atmos_init")] fn hook_init(gas_data: ByondValue) { - let data = gas_data.read_var("datums")?; + let data = gas_data.read_var_id(byond_string!("datums"))?; data.iter()? .map(|(_, gas)| hook_register_gas(gas)) .try_for_each(|res| res.map(drop)) @@ -284,7 +296,8 @@ fn hook_init(gas_data: ByondValue) { } fn get_reaction_info() -> BTreeMap { - let gas_reactions = byondapi::global_call::call_global("get_reactions", &[]).unwrap(); + let gas_reactions = + byondapi::global_call::call_global_id(byond_string!("get_reactions"), &[]).unwrap(); let mut reaction_cache: BTreeMap = Default::default(); let sender = byond_callback_sender(); for (reaction, _) in gas_reactions.iter().unwrap() { diff --git a/src/lib.rs b/src/lib.rs index 5da326b..7cf86a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -568,7 +568,7 @@ fn equalize_all_hook(gas_list: ByondValue) { .iter()? .filter_map(|(value, _)| { value - .read_number("_extools_pointer_gasmixture") + .read_number_id(byond_string!("_extools_pointer_gasmixture")) .ok() .map(|f| f as usize) }) diff --git a/src/reaction.rs b/src/reaction.rs index 9052af9..5d296f4 100644 --- a/src/reaction.rs +++ b/src/reaction.rs @@ -58,7 +58,7 @@ pub fn react_by_id( || Err(eyre::eyre!("Reaction with invalid id")), |reaction| match reaction { ReactionSide::ByondSide(val) => val - .call("react", &[src, holder]) + .call_id(byond_string!("react"), &[src, holder]) .wrap_err("calling byond side react in react_by_id"), ReactionSide::RustSide(func) => func(src, holder), }, @@ -71,11 +71,11 @@ impl Reaction { pub fn from_byond_reaction(reaction: ByondValue) -> Result { let priority = FloatOrd( reaction - .read_number("priority") + .read_number_id(byond_string!("priority")) .map_err(|_| eyre::eyre!("Reaction priority must be a number!"))?, ); let string_id = reaction - .read_string("id") + .read_string_id(byond_string!("id")) .map_err(|_| eyre::eyre!("Reaction id must be a string!"))?; let func = { #[cfg(feature = "reaction_hooks")] @@ -90,7 +90,7 @@ impl Reaction { let id = fxhash::hash64(string_id.as_bytes()); let our_reaction = { if let Some(min_reqs) = reaction - .read_var("min_requirements") + .read_var_id(byond_string!("min_requirements")) .map_or(None, |value| value.is_list().then_some(value)) { let mut min_gas_reqs: Vec<(GasIDX, f32)> = Vec::new(); diff --git a/src/reaction/hooks.rs b/src/reaction/hooks.rs index 635743a..d8093a0 100644 --- a/src/reaction/hooks.rs +++ b/src/reaction/hooks.rs @@ -87,7 +87,7 @@ fn plasma_fire(byond_air: ByondValue, holder: ByondValue) -> Result air.garbage_collect(); Ok(new_temp) })?; - let mut cached_results = byond_air.read_var("reaction_results")?; + let mut cached_results = byond_air.read_var_id(byond_string!("reaction_results"))?; cached_results.write_list_index("fire", fire_amount)?; if temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST { byondapi::global_call::call_global( @@ -134,7 +134,7 @@ fn tritium_fire(byond_air: ByondValue, holder: ByondValue) -> Result air.adjust_moles(water, burned_fuel / TRITIUM_BURN_OXY_FACTOR); let energy_released = FIRE_HYDROGEN_ENERGY_RELEASED * burned_fuel; let new_temp = (initial_energy + energy_released) / air.heat_capacity(); - let mut cached_results = byond_air.read_var("reaction_results")?; + let mut cached_results = byond_air.read_var_id(byond_string!("reaction_results"))?; cached_results.write_list_index("fire", burned_fuel)?; air.set_temperature(new_temp); air.garbage_collect(); @@ -205,7 +205,7 @@ fn fusion(byond_air: ByondValue, holder: ByondValue) -> Result { } }; let instability = (gas_power * INSTABILITY_GAS_POWER_FACTOR).rem_euclid(toroidal_size); - byond_air.call("set_analyzer_results", &[instability.into()])?; + byond_air.call_id("set_analyzer_results", &[instability.into()])?; let mut thermal_energy = initial_energy; //We have to scale the amounts of carbon and plasma down a significant amount in order to show the chaotic dynamics we want @@ -393,7 +393,7 @@ fn generic_fire(byond_air: ByondValue, holder: ByondValue) -> Result ); Ok(air.get_temperature()) })?; - let mut cached_results = byond_air.read_var("reaction_results")?; + let mut cached_results = byond_air.read_var_id(byond_string!("reaction_results"))?; cached_results.write_list_index("fire", fire_amount)?; if temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST { byondapi::global_call::call_global( diff --git a/src/turfs.rs b/src/turfs.rs index c514ace..5386709 100644 --- a/src/turfs.rs +++ b/src/turfs.rs @@ -432,7 +432,7 @@ where fn hook_register_turf(src: ByondValue, flag: ByondValue) { let id = src.get_ref()?; let flag = flag.get_number()? as i32; - if let Ok(blocks) = src.read_number("blocks_air") { + if let Ok(blocks) = src.read_number_id(byond_string!("blocks_air")) { if blocks > 0.0 { with_turf_gases_write(|arena| arena.remove_turf(id)); #[cfg(feature = "superconductivity")] @@ -442,14 +442,14 @@ fn hook_register_turf(src: ByondValue, flag: ByondValue) { } if flag >= 0 { let mut to_insert: TurfMixture = TurfMixture::default(); - let air = src.read_var("air")?; - to_insert.mix = air.read_number("_extools_pointer_gasmixture")? as usize; + let air = src.read_var_id(byond_string!("air"))?; + to_insert.mix = air.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize; to_insert.flags = SimulationFlags::from_bits_truncate(flag as u8); to_insert.id = id; - if let Ok(is_planet) = src.read_number("planetary_atmos") { + if let Ok(is_planet) = src.read_number_id(byond_string!("planetary_atmos")) { if is_planet != 0.0 { - if let Ok(at_str) = src.read_string("initial_gas_mix") { + if let Ok(at_str) = src.read_string_id(byond_string!("initial_gas_mix")) { with_planetary_atmos_upgradeable_read(|lock| { to_insert.planetary_atmos = Some(fxhash::hash32(&at_str)); if lock @@ -494,11 +494,11 @@ const OPEN_TURF: i32 = 2; //hardcoded because we can't have nice things fn determine_turf_flag(src: &ByondValue) -> i32 { let path = src - .read_string("type") + .read_string_id(byond_string!("("type") .unwrap_or_else(|_| "TYPPENOTFOUND".to_string()); if !path.as_str().starts_with("/turf/open") { CLOSED_TURF - } else if src.read_number("planetary_atmos").unwrap_or(0.0) > 0.0 { + } else if src.read_number_id(byond_string!("planetary_atmos")).unwrap_or(0.0) > 0.0 { PLANET_TURF } else if path.as_str().starts_with("/turf/open/space") { SPACE_TURF @@ -513,7 +513,7 @@ fn hook_infos(src: ByondValue) { let id = src.get_ref()?; with_turf_gases_write(|arena| -> Result<()> { if let Some(adjacent_list) = src - .read_var("atmos_adjacent_turfs") + .read_var_id(byond_string!("atmos_adjacent_turfs")) .ok() .and_then(|adjs| adjs.is_list().then_some(adjs)) { @@ -536,12 +536,13 @@ fn hook_infos(src: ByondValue) { /// If auxgm wasn't implemented properly or there's an invalid gas mixture. fn update_visuals(src: ByondValue) -> Result { use super::gas; - match src.read_var("air") { + match src.read_var_id(byond_string!("air")) { Err(_) => Ok(ByondValue::null()), Ok(air) => { let mut overlay_types = Vec::new(); - let gas_overlays = byondapi::global_call::call_global("get_overlays", &[])?; - let ptr = air.read_number("_extools_pointer_gasmixture")? as usize; + let gas_overlays = + byondapi::global_call::call_global_id(byond_string!("get_overlays"), &[])?; + let ptr = air.read_number_id(byond_string!("_extools_pointer_gasmixture"))? as usize; GasArena::with_gas_mixture(ptr, |mix| { mix.for_each_gas(|idx, moles| { if let Some(amt) = gas::types::gas_visibility(idx) { @@ -559,7 +560,10 @@ fn update_visuals(src: ByondValue) -> Result { }) })?; - Ok(src.call("set_visuals", &[overlay_types.as_slice().try_into()?])?) + Ok(src.call_id( + byond_string!("set_visuals"), + &[overlay_types.as_slice().try_into()?], + )?) } } } diff --git a/src/turfs/groups.rs b/src/turfs/groups.rs index 3663d24..d9b00ec 100644 --- a/src/turfs/groups.rs +++ b/src/turfs/groups.rs @@ -23,7 +23,7 @@ pub fn send_to_groups(sent: BTreeSet) { #[byondapi_binds::bind("/datum/controller/subsystem/air/proc/process_excited_groups_auxtools")] fn groups_hook(mut src: ByondValue, remaining: ByondValue) { let group_pressure_goal = src - .read_number("excited_group_pressure_goal") + .read_number_id(byond_string!("excited_group_pressure_goal")) .unwrap_or(0.5); let remaining_time = Duration::from_millis(remaining.get_number().unwrap_or(50.0) as u64); let start_time = Instant::now(); @@ -40,14 +40,16 @@ fn groups_hook(mut src: ByondValue, remaining: ByondValue) { }); let bench = start_time.elapsed().as_millis(); - let prev_cost = src.read_number("cost_groups").map_err(|_| { - eyre::eyre!( - "Attempt to interpret non-number value as number {} {}:{}", - std::file!(), - std::line!(), - std::column!() - ) - })?; + let prev_cost = src + .read_number_id(byond_string!("cost_groups")) + .map_err(|_| { + eyre::eyre!( + "Attempt to interpret non-number value as number {} {}:{}", + std::file!(), + std::line!(), + std::column!() + ) + })?; src.write_var( "cost_groups", &(0.8 * prev_cost + 0.2 * (bench as f32)).into(), diff --git a/src/turfs/katmos.rs b/src/turfs/katmos.rs index 3d9a4b9..704e635 100644 --- a/src/turfs/katmos.rs +++ b/src/turfs/katmos.rs @@ -382,8 +382,10 @@ fn explosively_depressurize(initial_index: TurfID, equalize_hard_turf_limit: usi Ok(()) })?; for (cur, adj) in firelock_considerations { - ByondValue::new_ref(TURF_TYPE, cur) - .call("consider_firelocks", &[ByondValue::new_ref(TURF_TYPE, adj)])?; + ByondValue::new_ref(TURF_TYPE, cur).call_id( + byond_string!("consider_firelocks"), + &[ByondValue::new_ref(TURF_TYPE, adj)], + )?; } if warned_about_planet_atmos { @@ -432,7 +434,7 @@ fn explosively_depressurize(initial_index: TurfID, equalize_hard_turf_limit: usi adj_info.curr_transfer_dir = Some(cur_index); let cur_target_turf = ByondValue::new_ref(TURF_TYPE, cur_mixture.id) - .read_var("pressure_specific_target")?; + .read_var_id(byond_string!("pressure_specific_target"))?; ByondValue::new_ref(TURF_TYPE, adj_mixture.id) .write_var("pressure_specific_target", &cur_target_turf)?; adj_orig.set(adj_info); @@ -443,7 +445,7 @@ fn explosively_depressurize(initial_index: TurfID, equalize_hard_turf_limit: usi let _average_moles = total_moles / (progression_order.len() - space_turf_len) as f32; - let mut hpd = byondapi::global_call::call_global("get_hpds", &[])?; + let mut hpd = byondapi::global_call::call_global_id(byond_string!("get_hpds"), &[])?; for &cur_index in progression_order.iter().rev() { let cur_orig = info.entry(cur_index).or_default(); @@ -508,7 +510,7 @@ fn explosively_depressurize(initial_index: TurfID, equalize_hard_turf_limit: usi Ok(floor_rip_turfs) })?; for (turf, sum) in floor_rip_turfs { - turf.call("handle_decompression_floor_rip", &[sum])?; + turf.call_id(byond_string!("handle_decompression_floor_rip"), &[sum])?; } Ok(()) @@ -570,7 +572,6 @@ fn flood_fill_zones( drop(sender.try_send(Box::new(move || { planet_equalize(cur_turf_id, equalize_hard_turf_limit) }))); - ignore_zone = true; } } } @@ -628,10 +629,12 @@ fn planet_equalize(initial_index: TurfID, equalize_hard_turf_limit: usize) -> Re Ok(()) })?; for (cur, adj) in firelock_considerations { - ByondValue::new_ref(TURF_TYPE, cur) - .call("consider_firelocks", &[ByondValue::new_ref(TURF_TYPE, adj)])?; + ByondValue::new_ref(TURF_TYPE, cur).call_id( + byond_string!("consider_firelocks"), + &[ByondValue::new_ref(TURF_TYPE, adj)], + )?; } - if warned_about_space { + if warned_about_space || planet_turfs.is_empty() { break; } } @@ -717,8 +720,14 @@ fn send_pressure_differences( let real_amount = ByondValue::from(amt); let turf = ByondValue::new_ref(TURF_TYPE, cur_turf); let other_turf = ByondValue::new_ref(TURF_TYPE, adj_turf); - if let Err(e) = turf.call("consider_pressure_difference", &[other_turf, real_amount]) { - byondapi::global_call::call_global("stack_trace", &[format!("{e:?}").try_into()?])?; + if let Err(e) = turf.call_id( + byond_string!("consider_pressure_difference"), + &[other_turf, real_amount], + ) { + byondapi::global_call::call_global_id( + byond_string!("stack_trace"), + &[format!("{e:?}").try_into()?], + )?; } Ok(()) }))); @@ -728,9 +737,8 @@ fn send_pressure_differences( #[byondapi_binds::bind("/datum/controller/subsystem/air/proc/process_turf_equalize_auxtools")] fn equalize_hook(mut src: ByondValue, remaining: ByondValue) { let equalize_hard_turf_limit = src - .read_number("equalize_hard_turf_limit") + .read_number_id(byond_string!("equalize_hard_turf_limit")) .unwrap_or(2000.0) as usize; - let planet_enabled: bool = src.read_number("planet_equalize_enabled").unwrap_or(1.0) != 0.0; let remaining_time = Duration::from_millis(remaining.get_number().unwrap_or(50.0) as u64); let start_time = Instant::now(); let (num_eq, is_cancelled) = with_equalizes(|thing| { @@ -738,7 +746,6 @@ fn equalize_hook(mut src: ByondValue, remaining: ByondValue) { equalize( equalize_hard_turf_limit, &high_pressure_turfs, - planet_enabled, (&start_time, remaining_time), ) } else { @@ -747,7 +754,7 @@ fn equalize_hook(mut src: ByondValue, remaining: ByondValue) { }); let bench = start_time.elapsed().as_millis(); - let prev_cost = src.read_number("cost_equalize")?; + let prev_cost = src.read_number_id(byond_string!("cost_equalize"))?; src.write_var( "cost_equalize", &(0.8 * prev_cost + 0.2 * (bench as f32)).into(), @@ -759,7 +766,6 @@ fn equalize_hook(mut src: ByondValue, remaining: ByondValue) { fn equalize( equalize_hard_turf_limit: usize, high_pressure_turfs: &BTreeSet, - _planet_enabled: bool, (start_time, remaining_time): (&Instant, Duration), ) -> (usize, bool) { let turfs_processed: AtomicUsize = AtomicUsize::new(0); diff --git a/src/turfs/processing.rs b/src/turfs/processing.rs index 767eff0..6672bdc 100644 --- a/src/turfs/processing.rs +++ b/src/turfs/processing.rs @@ -1,4 +1,4 @@ -use byondapi::prelude::*; +use byondapi::{byond_string, prelude::*}; use super::*; @@ -27,8 +27,11 @@ fn finish_process_turfs(time_remaining: ByondValue) { #[byondapi_binds::bind("/datum/controller/subsystem/air/proc/process_turfs_auxtools")] fn process_turf_hook(src: ByondValue, remaining: ByondValue) { let remaining_time = Duration::from_millis(remaining.get_number().unwrap_or(50.0) as u64); - let fdm_max_steps = src.read_number("share_max_steps").unwrap_or(1.0) as i32; - let equalize_enabled = cfg!(feature = "fastmos") && src.read_number("equalize_enabled")? != 0.0; + let fdm_max_steps = src + .read_number_id(byond_string!("share_max_steps")) + .unwrap_or(1.0) as i32; + let equalize_enabled = + cfg!(feature = "fastmos") && src.read_number_id(byond_string!("equalize_enabled"))? != 0.0; process_turf(remaining_time, fdm_max_steps, equalize_enabled, src)?; Ok(ByondValue::null()) @@ -47,13 +50,15 @@ fn process_turf( fdm((&start_time, remaining), fdm_max_steps, equalize_enabled); let bench = start_time.elapsed().as_millis(); let (lpt, hpt) = (low_pressure_turfs.len(), high_pressure_turfs.len()); - let prev_cost = ssair.read_number("cost_turfs")?; + let prev_cost = ssair.read_number_id(byond_string!("cost_turfs"))?; ssair - .read_var("cost_turfs")? + .read_var_id(byond_string!("cost_turfs"))? .set_number(0.8 * prev_cost + 0.2 * (bench as f32)); - ssair.read_var("low_pressure_turfs")?.set_number(lpt as f32); ssair - .read_var("high_pressure_turfs")? + .read_var_id(byond_string!("low_pressure_turfs"))? + .set_number(lpt as f32); + ssair + .read_var_id(byond_string!("high_pressure_turfs"))? .set_number(hpt as f32); (low_pressure_turfs, high_pressure_turfs) }; @@ -61,9 +66,9 @@ fn process_turf( let start_time = Instant::now(); post_process(); let bench = start_time.elapsed().as_millis(); - let prev_cost = ssair.read_number("cost_post_process")?; + let prev_cost = ssair.read_number_id(byond_string!("cost_post_process"))?; ssair - .read_var("cost_post_process")? + .read_var_id(byond_string!("cost_post_process"))? .set_number(0.8 * prev_cost + 0.2 * (bench as f32)); } { @@ -315,13 +320,13 @@ fn fdm( if id != 0 { let enemy_tile = ByondValue::new_ref(0x01, id); if diff > 5.0 { - turf.call( - "consider_pressure_difference", + turf.call_id( + byond_string!("consider_pressure_difference"), &[enemy_tile, diff.into()], )?; } else if diff < -5.0 { - enemy_tile.call( - "consider_pressure_difference", + enemy_tile.call_id( + byond_string!("consider_pressure_difference"), &[turf.clone(), (-diff).into()], )?; } @@ -393,11 +398,8 @@ fn post_process() { if should_react { drop(sender.try_send(Box::new(move || { let turf = ByondValue::new_ref(0x01, id); - if cfg!(target_os = "linux") { - turf.read_var("air")?.call("vv_react", &[turf])?; - } else { - turf.read_var("air")?.call("react", &[turf])?; - } + turf.read_var_id(byond_string!("air"))? + .call_id(byond_string!("react"), &[turf])?; Ok(()) }))); } diff --git a/src/turfs/superconduct.rs b/src/turfs/superconduct.rs index 75bc5e4..ba834ad 100644 --- a/src/turfs/superconduct.rs +++ b/src/turfs/superconduct.rs @@ -171,7 +171,9 @@ pub fn supercond_update_ref(src: ByondValue) -> Result<()> { if therm_cond > 0.0 && therm_cap > 0.0 { let therm_info = ThermalInfo { id, - adjacent_to_space: src.call("should_conduct_to_space", &[])?.as_number()? > 0.0, + adjacent_to_space: src + .call_id(byond_string!("should_conduct_to_space"), &[])? + .as_number()? > 0.0, heat_capacity: therm_cap, thermal_conductivity: therm_cond, temperature: RwLock::new(src.read_number("initial_temperature").unwrap_or(TCMB)),