Skip to content

Commit

Permalink
doc, switch some stacktrace uses to byondapi stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Oct 26, 2024
1 parent 08d98e8 commit 2610f88
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
5 changes: 2 additions & 3 deletions crates/auxcallback/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn process_callbacks() {
.for_each(|e| {
let error_string = format!("{e:?}").try_into().unwrap();
byondapi::global_call::call_global_id(
byond_string!("stack_trace"),
byond_string!("byondapi_stack_trace"),
&[error_string],
)
.unwrap();
Expand All @@ -46,14 +46,13 @@ fn process_callbacks() {

/// Goes through every single outstanding callback and calls them, until a given time limit is reached.
fn process_callbacks_for(duration: Duration) -> bool {
//let stack_trace = Proc::find("/proc/auxtools_stack_trace").unwrap();
let timer = Instant::now();
with_callback_receiver(|receiver| {
for callback in receiver.try_iter() {
if let Err(e) = callback() {
let error_string = format!("{e:?}").try_into().unwrap();
byondapi::global_call::call_global_id(
byond_string!("stack_trace"),
byond_string!("byondapi_stack_trace"),
&[error_string],
)
.unwrap();
Expand Down
6 changes: 4 additions & 2 deletions src/gas/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn destroy_gas_info_structs() {
gas_ids.clear();
});
}

/// For registering gases, do not touch this.
#[byondapi::bind("/proc/_auxtools_register_gas")]
fn hook_register_gas(gas: ByondValue) -> Result<ByondValue> {
let gas_id = gas.read_string_id(byond_string!("id"))?;
Expand Down Expand Up @@ -273,6 +273,7 @@ fn hook_register_gas(gas: ByondValue) -> Result<ByondValue> {
Ok(ByondValue::null())
}

/// Registers gases, and get reaction infos for auxmos, only call when ssair is initing.
#[byondapi::bind("/proc/auxtools_atmos_init")]
fn hook_init(gas_data: ByondValue) -> Result<ByondValue> {
let data = gas_data.read_var_id(byond_string!("datums"))?;
Expand Down Expand Up @@ -317,6 +318,7 @@ fn get_reaction_info() -> BTreeMap<ReactionPriority, Reaction> {
reaction_cache
}

/// For updating reaction informations for auxmos, only call this when it is changed.
#[byondapi::bind("/datum/controller/subsystem/air/proc/auxtools_update_reactions")]
fn update_reactions() -> Result<ByondValue> {
*REACTION_INFO.write() = Some(get_reaction_info());
Expand Down Expand Up @@ -419,7 +421,7 @@ pub fn update_gas_refs() {
}
});
}

/// For updating reagent gas fire products, do not use for now.
#[byondapi::bind("/proc/finalize_gas_refs")]
fn finalize_gas_refs() -> Result<ByondValue> {
update_gas_refs();
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn adjust_multi_hook() -> Result<ByondValue> {
}
}

///Args: (amount). Adds the given amount to each gas.
/// Args: (amount). Adds the given amount to each gas.
#[byondapi::bind("/datum/gas_mixture/proc/add")]
fn add_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
let vf = num_val.get_number().unwrap_or_default();
Expand All @@ -316,7 +316,7 @@ fn add_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
})
}

///Args: (amount). Subtracts the given amount from each gas.
/// Args: (amount). Subtracts the given amount from each gas.
#[byondapi::bind("/datum/gas_mixture/proc/subtract")]
fn subtract_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
let vf = num_val.get_number().unwrap_or_default();
Expand All @@ -326,7 +326,7 @@ fn subtract_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
})
}

///Args: (coefficient). Multiplies all gases by this amount.
/// Args: (coefficient). Multiplies all gases by this amount.
#[byondapi::bind("/datum/gas_mixture/proc/multiply")]
fn multiply_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
let vf = num_val.get_number().unwrap_or(1.0);
Expand All @@ -336,7 +336,7 @@ fn multiply_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
})
}

///Args: (coefficient). Divides all gases by this amount.
/// Args: (coefficient). Divides all gases by this amount.
#[byondapi::bind("/datum/gas_mixture/proc/divide")]
fn divide_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
let vf = num_val.get_number().unwrap_or(1.0).recip();
Expand All @@ -346,7 +346,7 @@ fn divide_hook(src: ByondValue, num_val: ByondValue) -> Result<ByondValue> {
})
}

///Args: (mixture, flag, amount). Takes `amount` from src that have the given `flag` and puts them into the given `mixture`. Returns: 0 if gas didn't have any with that flag, 1 if it did.
/// Args: (mixture, flag, amount). Takes `amount` from src that have the given `flag` and puts them into the given `mixture`. Returns: 0 if gas didn't have any with that flag, 1 if it did.
#[byondapi::bind("/datum/gas_mixture/proc/__remove_by_flag")]
fn remove_by_flag_hook(
src: ByondValue,
Expand All @@ -372,7 +372,7 @@ fn remove_by_flag_hook(
Ok(true.into())
})
}
///Args: (flag). As get_gases(), but only returns gases with the given flag.
/// Args: (flag). As get_gases(), but only returns gases with the given flag.
#[byondapi::bind("/datum/gas_mixture/proc/get_by_flag")]
fn get_by_flag_hook(src: ByondValue, flag_val: ByondValue) -> Result<ByondValue> {
let flag = flag_val.get_number().map_or(0, |n: f32| n as u32);
Expand Down Expand Up @@ -637,7 +637,7 @@ fn hook_amt_gas_mixes() -> Result<ByondValue> {
fn hook_max_gas_mixes() -> Result<ByondValue> {
Ok((tot_gases() as f32).into())
}

/// Returns: true. Parses gas strings like "o2=2500;plasma=5000;TEMP=370" and turns src mixes into the parsed gas mixture, invalid patterns will be ignored
#[byondapi::bind("/datum/gas_mixture/proc/__auxtools_parse_gas_string")]
fn parse_gas_string(src: ByondValue, string: ByondValue) -> Result<ByondValue> {
let actual_string = string.get_string()?;
Expand Down
3 changes: 2 additions & 1 deletion src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ where
f(PLANETARY_ATMOS.upgradable_read())
}

/// Returns: null. Updates turf air infos, whether the turf is closed, is space or a regular turf, or even a planet turf is decided here.
#[byondapi::bind("/turf/proc/update_air_ref")]
fn hook_register_turf(src: ByondValue, flag: ByondValue) -> Result<ByondValue> {
let id = src.get_ref()?;
Expand Down Expand Up @@ -498,7 +499,7 @@ fn determine_turf_flag(src: &ByondValue) -> i32 {
}
}
*/

/// Updates adjacency infos for turfs, only use this in immediateupdateturfs.
#[byondapi::bind("/turf/proc/__update_auxtools_turf_adjacency_info")]
fn hook_infos(src: ByondValue) -> Result<ByondValue> {
let id = src.get_ref()?;
Expand Down
2 changes: 1 addition & 1 deletion src/turfs/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn with_groups<T>(f: impl Fn(Option<BTreeSet<TurfID>>) -> T) -> T {
pub fn send_to_groups(sent: BTreeSet<TurfID>) {
GROUPS_CHANNEL.try_lock().map(|mut opt| opt.replace(sent));
}

/// Returns: If this cycle is interrupted by overtiming or not. Starts a processing excited groups cycle, does nothing if process_turfs isn't ran.
#[byondapi::bind("/datum/controller/subsystem/air/proc/process_excited_groups_auxtools")]
fn groups_hook(mut src: ByondValue, remaining: ByondValue) -> Result<ByondValue> {
let group_pressure_goal = src
Expand Down
1 change: 1 addition & 0 deletions src/turfs/katmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ fn send_pressure_differences(
}
}

/// Returns: If this cycle is interrupted by overtiming or not. Starts a katmos equalize cycle, does nothing if process_turfs isn't ran.
#[byondapi::bind("/datum/controller/subsystem/air/proc/process_turf_equalize_auxtools")]
fn equalize_hook(mut src: ByondValue, remaining: ByondValue) -> Result<ByondValue> {
let equalize_hard_turf_limit = src
Expand Down
4 changes: 3 additions & 1 deletion src/turfs/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ use parking_lot::RwLock;
use std::collections::{BTreeMap, BTreeSet};
use tinyvec::TinyVec;

/// Returns: If a processing thread is running or not.
#[byondapi::bind("/datum/controller/subsystem/air/proc/thread_running")]
fn thread_running_hook() -> Result<ByondValue> {
Ok(TASKS.try_write().is_none().into())
}

/// Returns: If this cycle is interrupted by overtiming or not. Calls all outstanding callbacks created by other processes, usually ones that can't run on other threads and only the main thread.
#[byondapi::bind("/datum/controller/subsystem/air/proc/finish_turf_processing_auxtools")]
fn finish_process_turfs(time_remaining: ByondValue) -> Result<ByondValue> {
Ok(process_callbacks_for_millis(time_remaining.get_number()? as u64).into())
}

/// Returns: If this cycle is interrupted by overtiming or not. Starts a processing turfs cycle.
#[byondapi::bind("/datum/controller/subsystem/air/proc/process_turfs_auxtools")]
fn process_turf_hook(src: ByondValue, remaining: ByondValue) -> Result<ByondValue> {
let remaining_time = Duration::from_millis(remaining.get_number().unwrap_or(50.0) as u64);
Expand Down

0 comments on commit 2610f88

Please sign in to comment.