Skip to content

Commit

Permalink
bump callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Jul 22, 2023
1 parent d4de2c3 commit 4feb284
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 81 deletions.
76 changes: 33 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/auxcallback/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static mut CALLBACK_CHANNEL: Option<CallbackChannel> = 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(())
}
Expand Down
23 changes: 11 additions & 12 deletions src/gas/mixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,17 @@ impl Mixture {
pub fn vis_hash(&self, gas_visibility: &[Option<f32>]) -> 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
Expand All @@ -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) {
Expand Down
27 changes: 13 additions & 14 deletions src/turfs/katmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ fn adjust_eq_movement(
amount: f32,
graph: &DiGraphMap<NodeIndex, Cell<f32>>,
) {
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(
Expand Down Expand Up @@ -145,7 +144,7 @@ fn monstermos_fast_process(
eq_movement_graph: &DiGraphMap<NodeIndex, Cell<f32>>,
) {
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
};
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit 4feb284

Please sign in to comment.