Skip to content

Commit

Permalink
Merge pull request Putnam3145#8 from austation/au
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
jupyterkat authored Sep 10, 2021
2 parents 389c49f + 6e9f758 commit cfd40b1
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 278 deletions.
8 changes: 4 additions & 4 deletions src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl GasArena {
{
f(GAS_MIXTURES.read().as_ref().unwrap())
}
fn with_gas_mixture<T, F>(id: usize, f: F) -> Result<T, Runtime>
pub fn with_gas_mixture<T, F>(id: usize, f: F) -> Result<T, Runtime>
where
F: FnOnce(&Mixture) -> Result<T, Runtime>,
{
Expand All @@ -92,7 +92,7 @@ impl GasArena {
.read();
f(&mix)
}
fn with_gas_mixture_mut<T, F>(id: usize, f: F) -> Result<T, Runtime>
pub fn with_gas_mixture_mut<T, F>(id: usize, f: F) -> Result<T, Runtime>
where
F: FnOnce(&mut Mixture) -> Result<T, Runtime>,
{
Expand All @@ -104,7 +104,7 @@ impl GasArena {
.write();
f(&mut mix)
}
fn with_gas_mixtures<T, F>(src: usize, arg: usize, f: F) -> Result<T, Runtime>
pub fn with_gas_mixtures<T, F>(src: usize, arg: usize, f: F) -> Result<T, Runtime>
where
F: FnOnce(&Mixture, &Mixture) -> Result<T, Runtime>,
{
Expand All @@ -120,7 +120,7 @@ impl GasArena {
.read();
f(&src_gas, &arg_gas)
}
fn with_gas_mixtures_mut<T, F>(src: usize, arg: usize, f: F) -> Result<T, Runtime>
pub fn with_gas_mixtures_mut<T, F>(src: usize, arg: usize, f: F) -> Result<T, Runtime>
where
F: FnOnce(&mut Mixture, &mut Mixture) -> Result<T, Runtime>,
{
Expand Down
16 changes: 10 additions & 6 deletions src/gas/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,16 @@ impl GasType {
fire_products: if let Ok(products) = gas.get_list(byond_string!("fire_products")) {
Some(
(1..=products.len())
.map(|i| {
.filter_map(|i| {
let s = products.get(i).unwrap();
(
GasRef::Deferred(s.as_string().unwrap()),
products.get(s).unwrap().as_number().unwrap(),
)
s.as_string()
.and_then(|s_str| {
products
.get(s)
.and_then(|v| v.as_number())
.map(|amount| (GasRef::Deferred(s_str), amount))
})
.ok()
})
.collect(),
)
Expand Down Expand Up @@ -226,7 +230,7 @@ fn _destroy_gas_info_structs() {

#[hook("/proc/_auxtools_register_gas")]
fn _hook_register_gas(gas: Value) {
let gas_id = gas.get_string(byond_string!("id")).unwrap();
let gas_id = gas.get_string(byond_string!("id"))?;
let gas_cache = GasType::new(gas, TOTAL_NUM_GASES.load(Ordering::Relaxed))?;
unsafe { GAS_INFO_BY_STRING.as_ref() }
.unwrap()
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,13 @@ fn _equalize_all_hook() {
)
})?;
let gas_list: BTreeSet<usize> = (1..=value_list.len())
.map(|i| {
.filter_map(|i| {
value_list
.get(i)
.unwrap()
.unwrap_or_else(|_| Value::null())
.get_number(byond_string!("_extools_pointer_gasmixture"))
.unwrap()
.to_bits() as usize
.ok()
.map(|f| f.to_bits() as usize)
})
.collect(); // collect because get_number is way slower than the one-time allocation
GasArena::with_all_mixtures(move |all_mixtures| {
Expand Down
24 changes: 16 additions & 8 deletions src/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ impl Reaction {
///
/// If given anything but a `/datum/gas_reaction`, this will panic.
pub fn from_byond_reaction(reaction: &Value) -> Self {
let priority = reaction.get_number(byond_string!("priority")).unwrap();
let string_id_hash =
fxhash::hash64(reaction.get_string(byond_string!("id")).unwrap().as_bytes());
let priority = reaction
.get_number(byond_string!("priority"))
.unwrap_or_default();
let string_id_hash = fxhash::hash64(
reaction
.get_string(byond_string!("id"))
.unwrap_or_else(|_| "invalid".to_string())
.as_bytes(),
);
let id = ReactionIdentifier {
string_id_hash,
priority,
Expand All @@ -109,12 +115,14 @@ impl Reaction {
if let Ok(min_reqs) = reaction.get_list(byond_string!("min_requirements")) {
let mut min_gas_reqs: Vec<(GasIDX, f32)> = Vec::new();
for i in 0..total_num_gases() {
if let Ok(gas_req) =
min_reqs.get(Value::from_string(&*gas_idx_to_id(i).unwrap()).unwrap())
if let Ok(req_amount) = min_reqs
.get(
Value::from_string(&*gas_idx_to_id(i).unwrap())
.unwrap_or_else(|_| Value::null()),
)
.and_then(|v| v.as_number())
{
if let Ok(req_amount) = gas_req.as_number() {
min_gas_reqs.push((i, req_amount));
}
min_gas_reqs.push((i, req_amount));
}
}
let min_temp_req = min_reqs
Expand Down
60 changes: 45 additions & 15 deletions src/reaction/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ fn _plasma_fire(byond_air: &Value, holder: &Value) {
})?;
cached_results.set(byond_string!("fire"), Value::from(fire_amount))?;
if temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST {
Proc::find(byond_string!("/proc/fire_expose"))
.unwrap()
.call(&[holder, byond_air, &Value::from(temperature)])?;
if let Some(fire_expose) = Proc::find(byond_string!("/proc/fire_expose")) {
fire_expose.call(&[holder, byond_air, &Value::from(temperature)])?;
} else {
Proc::find(byond_string!("/proc/stack_trace"))
.ok_or_else(|| runtime!("Couldn't find stack_trace!"))?
.call(&[&Value::from_string(
"fire_expose not found! Auxmos hooked fires do not work without it!",
)?])?;
}
}
Ok(Value::from(1.0))
} else {
Expand Down Expand Up @@ -141,14 +147,26 @@ fn tritfire(byond_air: &Value, holder: &Value) {
Ok((burned_fuel, energy_released, new_temp))
})?;
if burned_fuel > TRITIUM_MINIMUM_RADIATION_FACTOR {
Proc::find(byond_string!("/proc/radiation_burn"))
.unwrap()
.call(&[holder, &Value::from(energy_released)])?;
if let Some(radiation_burn) = Proc::find(byond_string!("/proc/radiation_burn")) {
radiation_burn.call(&[holder, &Value::from(energy_released)])?;
} else {
let _ = Proc::find(byond_string!("/proc/stack_trace"))
.ok_or_else(|| runtime!("Couldn't find stack_trace!"))?
.call(&[&Value::from_string(
"radiation_burn not found! Auxmos hooked trit fires won't irradiated without it!"
)?]);
}
}
if temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST {
Proc::find(byond_string!("/proc/fire_expose"))
.unwrap()
.call(&[holder, byond_air, &Value::from(temperature)])?;
if let Some(fire_expose) = Proc::find(byond_string!("/proc/fire_expose")) {
fire_expose.call(&[holder, byond_air, &Value::from(temperature)])?;
} else {
Proc::find(byond_string!("/proc/stack_trace"))
.ok_or_else(|| runtime!("Couldn't find stack_trace!"))?
.call(&[&Value::from_string(
"fire_expose not found! Auxmos hooked fires do not work without it!",
)?])?;
}
}
Ok(Value::from(1.0))
}
Expand Down Expand Up @@ -242,13 +260,19 @@ fn fusion(byond_air: Value, holder: Value) {
Ok(())
})?;
if reaction_energy != 0.0 {
Proc::find(byond_string!("/proc/fusion_ball"))
.unwrap()
.call(&[
if let Some(fusion_ball) = Proc::find(byond_string!("/proc/fusion_ball")) {
fusion_ball.call(&[
holder,
&Value::from(reaction_energy),
&Value::from(instability),
])?;
} else {
Proc::find(byond_string!("/proc/stack_trace"))
.ok_or_else(|| runtime!("Couldn't find stack_trace!"))?
.call(&[&Value::from_string(
"fusion_ball not found! Auxmos hooked fusion does not work without it!",
)?])?;
}
Ok(Value::from(1.0))
} else {
Ok(Value::from(0.0))
Expand Down Expand Up @@ -488,9 +512,15 @@ fn _hook_generic_fire(byond_air: Value, holder: Value) {
})?;
cached_results.set(byond_string!("fire"), Value::from(fire_amount))?;
if temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST {
Proc::find(byond_string!("/proc/fire_expose"))
.unwrap()
.call(&[holder, byond_air, &Value::from(temperature)])?;
if let Some(fire_expose) = Proc::find(byond_string!("/proc/fire_expose")) {
fire_expose.call(&[holder, byond_air, &Value::from(temperature)])?;
} else {
Proc::find(byond_string!("/proc/stack_trace"))
.ok_or_else(|| runtime!("Couldn't find stack_trace!"))?
.call(&[&Value::from_string(
"fire_expose not found! Auxmos hooked fires do not work without it!",
)?])?;
}
}
Ok(Value::from(if fire_amount > 0.0 { 1.0 } else { 0.0 }))
} else {
Expand Down
16 changes: 10 additions & 6 deletions src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,15 @@ fn _hook_adjacent_turfs() {
.or_insert_with(|| ThermalInfo {
temperature: src
.get_number(byond_string!("initial_temperature"))
.unwrap(),
.unwrap_or(TCMB),
thermal_conductivity: src
.get_number(byond_string!("thermal_conductivity"))
.unwrap(),
heat_capacity: src.get_number(byond_string!("heat_capacity")).unwrap(),
.unwrap_or(0.0),
heat_capacity: src
.get_number(byond_string!("heat_capacity"))
.unwrap_or(0.0),
adjacency,
adjacent_to_space: args[0].as_number().unwrap() != 0.0,
adjacent_to_space: args[0].as_number().unwrap_or(0.0) != 0.0,
});
}
Ok(Value::null())
Expand Down Expand Up @@ -443,8 +445,10 @@ fn _hook_set_temperature() {
temperature: argument,
thermal_conductivity: src
.get_number(byond_string!("thermal_conductivity"))
.unwrap(),
heat_capacity: src.get_number(byond_string!("heat_capacity")).unwrap(),
.unwrap_or(0.0),
heat_capacity: src
.get_number(byond_string!("heat_capacity"))
.unwrap_or(0.0),
adjacency: 0,
adjacent_to_space: false,
});
Expand Down
Loading

0 comments on commit cfd40b1

Please sign in to comment.