diff --git a/Cargo.lock b/Cargo.lock index 4ff4f93..0195105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,17 +64,17 @@ dependencies = [ "detour", "inventory 0.2.3", "quote", - "syn 2.0.23", + "syn 2.0.27", ] [[package]] name = "auxcleanup-impl" version = "0.1.0" dependencies = [ - "inventory 0.3.6", + "inventory 0.3.10", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.27", ] [[package]] @@ -88,7 +88,7 @@ dependencies = [ "auxtools", "bitflags 2.3.3", "coarsetime", - "dashmap 5.4.0", + "dashmap 5.5.0", "float-ord", "flume", "fxhash", @@ -97,7 +97,6 @@ dependencies = [ "lazy_static", "mimalloc", "nom", - "nonmax", "parking_lot", "petgraph", "rayon", @@ -282,12 +281,12 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.4.0" +version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.12.3", + "hashbrown 0.14.0", "lock_api", "once_cell", "parking_lot_core", @@ -312,15 +311,15 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "equivalent" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "fixedbitset" @@ -393,13 +392,13 @@ dependencies = [ [[package]] name = "ghost" -version = "0.1.10" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88395157cdd343ee9f17aeef0e407a04495fd63c62662699f0f4ec0647260d22" +checksum = "ba330b70a5341d3bc730b8e205aaee97ddab5d9c448c4f51a7c2d924266fa8f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.27", ] [[package]] @@ -416,9 +415,9 @@ checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -459,12 +458,9 @@ dependencies = [ [[package]] name = "inventory" -version = "0.3.6" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0539b5de9241582ce6bd6b0ba7399313560151e58c9aaf8b74b711b1bdce644" -dependencies = [ - "ghost", -] +checksum = "59c01ab27b36b668b4719ad000ced6ba3c3338f6793486449f2bd7ea96457f35" [[package]] name = "itertools" @@ -611,12 +607,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nonmax" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99756f5493e135528f0cd660ac67b4c3a542bb65a3565efe92bb2c2317eb3669" - [[package]] name = "num_cpus" version = "1.16.0" @@ -683,7 +673,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.27", ] [[package]] @@ -694,18 +684,18 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" dependencies = [ "proc-macro2", ] @@ -755,9 +745,9 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "slice-pool" @@ -767,9 +757,9 @@ checksum = "733fc6e5f1bd3a8136f842c9bdea4e5f17c910c2fcc98c90c3aa7604ef5e2e7a" [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "spin" @@ -793,9 +783,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.23" +version = "2.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" dependencies = [ "proc-macro2", "quote", @@ -834,9 +824,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "version_check" @@ -871,7 +861,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.27", "wasm-bindgen-shared", ] @@ -893,7 +883,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.27", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index ec60051..455ccd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ 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"] +default = ["auxcleanup_gas_deletion", "turf_processing", "katmos"] auxcleanup_gas_deletion = ["auxcleanup"] zas_hooks = [] turf_processing = [] @@ -40,11 +40,10 @@ float-ord = "0.3.2" flume = "0.10.14" parking_lot = "0.12.1" fxhash = "0.2.1" -nonmax = "0.5.3" ahash = "0.8.3" lazy_static = "1.4.0" indexmap = { version = "2.0.0", features = ["rayon"] } -dashmap = { version = "5.4.0", features = ["rayon"] } +dashmap = { version = "5.5.0", features = ["rayon"] } atomic_float = "0.1.0" petgraph = "0.6.3" bitflags = "2.3.3" diff --git a/crates/auxcallback/src/lib.rs b/crates/auxcallback/src/lib.rs index f5fad0e..14691dc 100644 --- a/crates/auxcallback/src/lib.rs +++ b/crates/auxcallback/src/lib.rs @@ -15,7 +15,7 @@ static mut CALLBACK_CHANNEL: Option = None; #[init(partial)] fn start_callbacks() -> Result<(), String> { unsafe { - CALLBACK_CHANNEL = Some(flume::bounded(100_000)); + CALLBACK_CHANNEL = Some(flume::bounded(1_000_000)); } Ok(()) } diff --git a/src/gas/mixture.rs b/src/gas/mixture.rs index 9a6d89e..c0e4517 100644 --- a/src/gas/mixture.rs +++ b/src/gas/mixture.rs @@ -604,15 +604,17 @@ impl Mixture { pub fn vis_hash(&self, gas_visibility: &[Option]) -> u64 { use std::hash::Hasher; let mut hasher: ahash::AHasher = ahash::AHasher::default(); - for (i, gas_amt) in self.enumerate() { - if unsafe { gas_visibility.get_unchecked(i) } - .filter(|&amt| gas_amt > amt) - .is_some() - { + + self.enumerate() + .filter(|&(i, gas_amt)| { + unsafe { gas_visibility.get_unchecked(i) } + .filter(|&amt| gas_amt > amt) + .is_some() + }) + .for_each(|(i, gas_amt)| { hasher.write_usize(i); hasher.write_usize(visibility_step(gas_amt) as usize) - } - } + }); hasher.finish() } /// Compares the current vis hash to the provided one; returns true if they are @@ -622,11 +624,8 @@ impl Mixture { hash_holder: &AtomicU64, ) -> bool { let cur_hash = self.vis_hash(gas_visibility); - hash_holder - .fetch_update(Relaxed, Relaxed, |item| { - (item != cur_hash).then_some(cur_hash) - }) - .is_ok() + let old_hash = hash_holder.swap(cur_hash, Relaxed); + old_hash == 0 || old_hash != cur_hash } // Removes all redundant zeroes from the gas mixture. pub fn garbage_collect(&mut self) { diff --git a/src/turfs/katmos.rs b/src/turfs/katmos.rs index 74ed9d9..0195651 100644 --- a/src/turfs/katmos.rs +++ b/src/turfs/katmos.rs @@ -77,14 +77,13 @@ fn adjust_eq_movement( amount: f32, graph: &DiGraphMap>, ) { - if graph.contains_edge(this_turf, that_turf) { - let cell = graph.edge_weight(this_turf, that_turf).unwrap(); - cell.set(cell.get() + amount); - } - if graph.contains_edge(that_turf, this_turf) { - let cell = graph.edge_weight(that_turf, this_turf).unwrap(); - cell.set(cell.get() - amount) - } + graph + .edge_weight(this_turf, that_turf) + .map(|cell| cell.set(cell.get() + amount)); + + graph + .edge_weight(that_turf, this_turf) + .map(|cell| cell.set(cell.get() - amount)); } fn finalize_eq( @@ -145,7 +144,7 @@ fn monstermos_fast_process( eq_movement_graph: &DiGraphMap>, ) { let mut cur_info = { - let mut cur_info = info.get_mut(&cur_index).unwrap(); + let cur_info = info.get_mut(&cur_index).unwrap(); cur_info.fast_done = true; *cur_info }; @@ -164,7 +163,7 @@ fn monstermos_fast_process( } let moles_to_move = cur_info.mole_delta / eligible_adjacents.len() as f32; eligible_adjacents.into_iter().for_each(|adj_index| { - if let Some(mut adj_info) = info.get_mut(&adj_index) { + if let Some(adj_info) = info.get_mut(&adj_index) { adjust_eq_movement(cur_index, adj_index, moles_to_move, eq_movement_graph); cur_info.mole_delta -= moles_to_move; adj_info.mole_delta += moles_to_move; @@ -198,7 +197,7 @@ fn give_to_takers( if giver_info.mole_delta <= 0.0 { break; } - if let Some(mut adj_info) = info.get_mut(&adj_idx) { + if let Some(adj_info) = info.get_mut(&adj_idx) { if queue.insert(adj_idx) { adj_info.curr_transfer_dir = Some(cur_index); adj_info.curr_transfer_amount = 0.0; @@ -233,7 +232,7 @@ fn give_to_takers( *opt.unwrap() }; if turf_info.curr_transfer_amount != 0.0 && turf_info.curr_transfer_dir.is_some() { - if let Some(mut adj_info) = info.get_mut(&turf_info.curr_transfer_dir.unwrap()) { + if let Some(adj_info) = info.get_mut(&turf_info.curr_transfer_dir.unwrap()) { adjust_eq_movement( cur_index, turf_info.curr_transfer_dir.unwrap(), @@ -273,7 +272,7 @@ fn take_from_givers( if taker_info.mole_delta >= 0.0 { break; } - if let Some(mut adj_info) = info.get_mut(&adj_index) { + if let Some(adj_info) = info.get_mut(&adj_index) { if queue.insert(adj_index) { adj_info.curr_transfer_dir = Some(cur_index); adj_info.curr_transfer_amount = 0.0; @@ -306,7 +305,7 @@ fn take_from_givers( *opt.unwrap() }; if turf_info.curr_transfer_amount != 0.0 && turf_info.curr_transfer_dir.is_some() { - if let Some(mut adj_info) = info.get_mut(&turf_info.curr_transfer_dir.unwrap()) { + if let Some(adj_info) = info.get_mut(&turf_info.curr_transfer_dir.unwrap()) { adjust_eq_movement( cur_index, turf_info.curr_transfer_dir.unwrap(), diff --git a/src/turfs/processing.rs b/src/turfs/processing.rs index 366583d..7d83715 100644 --- a/src/turfs/processing.rs +++ b/src/turfs/processing.rs @@ -270,11 +270,11 @@ fn fdm( let mut low_pressure_turfs: BTreeSet = Default::default(); let mut high_pressure_turfs: BTreeSet = Default::default(); let mut cur_count = 1; - loop { - if cur_count > fdm_max_steps || start_time.elapsed() >= remaining_time { - break; - } - with_turf_gases_read(|arena| { + with_turf_gases_read(|arena| { + loop { + if cur_count > fdm_max_steps || start_time.elapsed() >= remaining_time { + break; + } GasArena::with_all_mixtures(|all_mixtures| { let turfs_to_save = arena .map @@ -379,9 +379,10 @@ fn fdm( }); } }); - }); - cur_count += 1; - } + + cur_count += 1; + } + }); (low_pressure_turfs, high_pressure_turfs) }