Skip to content

Commit

Permalink
update byondapi
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Nov 16, 2023
1 parent 015ffed commit fa49dcf
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 70 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ crate-type = ["cdylib"]
auxcallback = { path = "./crates/auxcallback" }
byondapi = { git = "https://github.com/jupyterkat/byondapi-rs", package = "byondapi" }
byondapi-binds = { path = "./crates/byondapi-binds" }
itertools = "0.11.0"
itertools = "0.12.0"
rayon = "1.8.0"
float-ord = "0.3.2"
flume = "0.11.0"
Expand All @@ -55,7 +55,7 @@ atomic_float = "0.1.0"
petgraph = "0.6.4"
bitflags = "2.4.1"
nom = "7.1.3"
coarsetime = "0.1.29"
coarsetime = "0.1.33"
mimalloc = { version = "0.1.39", default-features = false }
eyre = "0.6.8"

Expand Down
2 changes: 1 addition & 1 deletion crates/auxcallback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ crate-type = ["lib"]

[dependencies]
flume = "0.11.0"
coarsetime = "0.1.29"
coarsetime = "0.1.33"
byondapi = { git = "https://github.com/jupyterkat/byondapi-rs", package = "byondapi" }
eyre = "0.6.8"
8 changes: 4 additions & 4 deletions crates/auxcallback/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::TryFrom;
use std::convert::TryInto;

use byondapi::{prelude::*, typecheck_trait::ByondTypeCheck};

Expand Down Expand Up @@ -41,7 +41,7 @@ fn process_callbacks() {
with_callback_receiver(|receiver| {
for callback in receiver.try_iter() {
if let Err(e) = callback() {
let error_string = ByondValue::try_from(::std::format!("{e:?}")).unwrap();
let error_string = format!("{e:?}").try_into().unwrap();
byondapi::global_call::call_global("stack_trace", &[error_string]).unwrap();
}
}
Expand All @@ -55,7 +55,7 @@ fn process_callbacks_for(duration: Duration) -> bool {
with_callback_receiver(|receiver| {
for callback in receiver.try_iter() {
if let Err(e) = callback() {
let error_string = ByondValue::try_from(::std::format!("{e:?}")).unwrap();
let error_string = format!("{e:?}").try_into().unwrap();
byondapi::global_call::call_global("stack_trace", &[error_string]).unwrap();
}
if timer.elapsed() >= duration {
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn process_callbacks_for_millis(millis: u64) -> bool {
pub fn callback_processing_hook(time_remaining: ByondValue) -> Result<ByondValue> {
if time_remaining.is_num() {
let limit = time_remaining.get_number().unwrap() as u64;
Ok(ByondValue::from(process_callbacks_for_millis(limit)))
Ok(process_callbacks_for_millis(limit).into())
} else {
process_callbacks();
Ok(ByondValue::null())
Expand Down
9 changes: 3 additions & 6 deletions src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,8 @@ impl GasArena {
let next_idx = gas_mixtures.len();
gas_mixtures.push(RwLock::new(Mixture::from_vol(init_volume)));

mix.write_var(
"_extools_pointer_gasmixture",
&ByondValue::from(next_idx as f32),
)
.unwrap();
mix.write_var("_extools_pointer_gasmixture", &(next_idx as f32).into())
.unwrap();

let mut ids_lock = NEXT_GAS_IDS.write();
let cur_last = gas_mixtures.len();
Expand Down Expand Up @@ -225,7 +222,7 @@ impl GasArena {
.unwrap()
.write()
.clear_with_vol(init_volume);
mix.write_var("_extools_pointer_gasmixture", &ByondValue::from(idx as f32))
mix.write_var("_extools_pointer_gasmixture", &(idx as f32).into())
.unwrap();
}
Ok(ByondValue::null())
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ fn temperature_share_hook() {
#[byondapi_binds::bind("/datum/gas_mixture/proc/get_gases")]
fn get_gases_hook(src: ByondValue) {
with_mix(&src, |mix| {
let mut gases_list: ByondValueList = ByondValue::new_list()?.try_into().unwrap();
let mut gases_list = ByondValue::new_list()?;
mix.for_each_gas(|idx, gas| {
if gas > GAS_MIN_MOLES {
gases_list.push(&gas_idx_to_id(idx))?;
gases_list.push_list(gas_idx_to_id(idx))?;
}
Ok(())
})?;
Ok(ByondValue::try_from(gases_list)?)

Ok(gases_list)
})
}

Expand Down
7 changes: 3 additions & 4 deletions src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,7 @@ fn update_visuals(src: ByondValue) -> Result<ByondValue> {
match src.read_var("air") {
Err(_) => Ok(ByondValue::null()),
Ok(air) => {
let overlay_types = ByondValue::new_list()?;
let mut overlay_types: ByondValueList = overlay_types.try_into()?;
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;
GasArena::with_gas_mixture(ptr, |mix| {
Expand All @@ -552,15 +551,15 @@ fn update_visuals(src: ByondValue) -> Result<ByondValue> {
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)?;
overlay_types.push(this_gas_overlay);
}
}
}
Ok(())
})
})?;

Ok(src.call("set_visuals", &[ByondValue::try_from(overlay_types)?])?)
Ok(src.call("set_visuals", &[overlay_types.as_slice().try_into()?])?)
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/turfs/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ fn groups_hook(mut src: ByondValue, remaining: ByondValue) {
})?;
src.write_var(
"cost_groups",
&ByondValue::from(0.8 * prev_cost + 0.2 * (bench as f32)),
)?;
src.write_var(
"num_group_turfs_processed",
&ByondValue::from(num_eq as f32),
&(0.8 * prev_cost + 0.2 * (bench as f32)).into(),
)?;
src.write_var("num_group_turfs_processed", &(num_eq as f32).into())?;
Ok(is_cancelled.into())
}

Expand Down
28 changes: 11 additions & 17 deletions src/turfs/katmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ fn explosively_depressurize(
let _average_moles = total_moles / (progression_order.len() - space_turf_len) as f32;

let hpd = byondapi::global_call::call_global("get_hpds", &[])?;
let mut hpd_list: ByondValueList = (&hpd).try_into()?;
let mut hpd_list = hpd.get_list()?;

for &cur_index in progression_order.iter().rev() {
let cur_orig = info.entry(cur_index).or_default();
Expand All @@ -461,7 +461,8 @@ fn explosively_depressurize(
}
let mut byond_turf = ByondValue::new_ref(TURF_TYPE, cur_mixture.id);
if byondapi::map::byond_locatein(&byond_turf, &hpd)?.is_null() {
hpd_list.push(&byond_turf)?;
hpd_list.push(byond_turf);
hpd.write_list(&hpd_list)?;
}
let adj_index = cur_info.curr_transfer_dir.unwrap();

Expand All @@ -479,10 +480,8 @@ fn explosively_depressurize(

let mut byond_turf_adj = ByondValue::new_ref(TURF_TYPE, cur_mixture.id);

byond_turf.write_var(
"pressure_difference",
&ByondValue::from(cur_info.curr_transfer_amount),
)?;
byond_turf
.write_var("pressure_difference", &cur_info.curr_transfer_amount.into())?;
byond_turf.write_var(
"pressure_direction",
&byondapi::global_call::call_global(
Expand All @@ -492,10 +491,8 @@ fn explosively_depressurize(
)?;

if adj_info.curr_transfer_dir.is_none() {
byond_turf_adj.write_var(
"pressure_difference",
&ByondValue::from(adj_info.curr_transfer_amount),
)?;
byond_turf_adj
.write_var("pressure_difference", &adj_info.curr_transfer_amount.into())?;
byond_turf_adj.write_var(
"pressure_direction",
&byondapi::global_call::call_global(
Expand All @@ -505,7 +502,7 @@ fn explosively_depressurize(
)?;
}

floor_rip_turfs.push((byond_turf, ByondValue::from(sum)));
floor_rip_turfs.push((byond_turf, sum.into()));
}
Ok(floor_rip_turfs)
})?;
Expand Down Expand Up @@ -713,10 +710,7 @@ fn send_pressure_differences(
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",
&[ByondValue::new_str(format!("{e:?}"))?],
)?;
byondapi::global_call::call_global("stack_trace", &[format!("{e:?}").try_into()?])?;
}
Ok(())
})));
Expand Down Expand Up @@ -748,9 +742,9 @@ fn equalize_hook(mut src: ByondValue, remaining: ByondValue) {
let prev_cost = src.read_number("cost_equalize")?;
src.write_var(
"cost_equalize",
&ByondValue::from(0.8 * prev_cost + 0.2 * (bench as f32)),
&(0.8 * prev_cost + 0.2 * (bench as f32)).into(),
)?;
src.write_var("num_equalize_processed", &ByondValue::from(num_eq as f32))?;
src.write_var("num_equalize_processed", &(num_eq as f32).into())?;
Ok(is_cancelled.into())
}

Expand Down
4 changes: 2 additions & 2 deletions src/turfs/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ fn fdm(
if diff > 5.0 {
turf.call(
"consider_pressure_difference",
&[enemy_tile, ByondValue::from(diff)],
&[enemy_tile, diff.into()],
)?;
} else if diff < -5.0 {
enemy_tile.call(
"consider_pressure_difference",
&[turf.clone(), ByondValue::from(-diff)],
&[turf.clone(), (-diff).into()],
)?;
}
}
Expand Down

0 comments on commit fa49dcf

Please sign in to comment.