Skip to content

Commit

Permalink
update that
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Dec 8, 2023
1 parent a134e84 commit fdbc175
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
7 changes: 2 additions & 5 deletions crates/auxcallback/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ pub fn clean_callbacks() {
}

fn with_callback_receiver<T>(f: impl Fn(&flume::Receiver<DeferredFunc>) -> T) -> T {
f(&CALLBACK_CHANNEL.get_or_init(|| flume::unbounded()).1)
f(&CALLBACK_CHANNEL.get_or_init(flume::unbounded).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<DeferredFunc> {
CALLBACK_CHANNEL
.get_or_init(|| flume::bounded(1_000_000))
.0
.clone()
CALLBACK_CHANNEL.get_or_init(flume::unbounded).0.clone()
}

/// Goes through every single outstanding callback and calls them.
Expand Down
7 changes: 5 additions & 2 deletions src/gas/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ fn hook_init(gas_data: ByondValue) {
}

fn get_reaction_info() -> BTreeMap<ReactionPriority, Reaction> {
let gas_reactions =
byondapi::global_call::call_global_id(byond_string!("get_reactions"), &[]).unwrap();
let gas_reactions = ByondValue::new_global_ref()
.read_var_id(byond_string!("SSair"))
.unwrap()
.read_var_id(byond_string!("gas_reactions"))
.unwrap();
let mut reaction_cache: BTreeMap<ReactionPriority, Reaction> = Default::default();
let sender = byond_callback_sender();
for (reaction, _) in gas_reactions.iter().unwrap() {
Expand Down
43 changes: 24 additions & 19 deletions src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ fn hook_infos(src: ByondValue) {
Ok(ByondValue::null())
}

// gas_overlays: list( GAS_ID = list( VIS_FACTORS = OVERLAYS )) got it? I don't
/// Updates the visual overlays for the given turf.
/// Will use a cached overlay list if one exists.
/// # Errors
Expand All @@ -537,25 +536,31 @@ fn update_visuals(src: ByondValue) -> Result<ByondValue> {
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_id(byond_string!("get_overlays"), &[])?;
// gas_overlays: list( GAS_ID = list( VIS_FACTORS = OVERLAYS )) got it? I don't
let gas_overlays = ByondValue::new_global_ref()
.read_var_id(byond_string!("GLOB"))?
.read_var_id(byond_string!("gas_data"))?
.read_var_id(byond_string!("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) {
if moles > amt {
let this_overlay_list =
gas_overlays.read_list_index(gas::gas_idx_to_id(idx))?;
if let Ok(this_gas_overlay) = this_overlay_list
.read_list_index(gas::mixture::visibility_step(moles) as f32)
{
overlay_types.push(this_gas_overlay);
}
}
}
Ok(())
})
let overlay_types = GasArena::with_gas_mixture(ptr, |mix| {
Ok(mix
.enumerate()
.filter_map(|(idx, moles)| Some((idx, moles, gas::types::gas_visibility(idx)?)))
.filter(|(_, moles, amt)| moles > amt)
// getting the list(VIS_FACTORS = OVERLAYS) with GAS_ID
.filter_map(|(idx, moles, _)| {
Some((
gas_overlays.read_list_index(gas::gas_idx_to_id(idx)).ok()?,
moles,
))
})
// getting the OVERLAYS with VIS_FACTOR
.filter_map(|(this_overlay_list, moles)| {
this_overlay_list
.read_list_index(gas::mixture::visibility_step(moles) as f32)
.ok()
})
.collect::<Vec<_>>())
})?;

Ok(src.call_id(
Expand Down
6 changes: 5 additions & 1 deletion src/turfs/katmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ 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_id(byond_string!("get_hpds"), &[])?;
let mut hpd = ByondValue::new_global_ref()
.read_var_id(byond_string!("SSair"))
.unwrap()
.read_var_id(byond_string!("high_pressure_delta"))
.unwrap();

for &cur_index in progression_order.iter().rev() {
let cur_orig = info.entry(cur_index).or_default();
Expand Down

0 comments on commit fdbc175

Please sign in to comment.