Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Jul 3, 2023
1 parent 2e8ef1c commit e238484
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,16 @@ where
)
}

/// Gets the amount of gases that are active in byond.
/// # Panics
/// if `GAS_MIXTURES` hasn't been initialized, somehow.
pub fn amt_gases() -> usize {
GAS_MIXTURES.read().as_ref().unwrap().len() - NEXT_GAS_IDS.read().as_ref().unwrap().len()
}

/// Gets the amount of gases that are allocated, but not necessarily active in byond.
/// # Panics
/// if `GAS_MIXTURES` hasn't been initialized, somehow.
pub fn tot_gases() -> usize {
GAS_MIXTURES.read().as_ref().unwrap().len()
}
3 changes: 2 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn parse_moles(input: &str) -> IResult<&str, f32> {
float(input)
}

//parses the gas string, invalid patterns will be ignored
/// Parses gas strings, invalid patterns will be ignored
/// E.g: "o2=2500;plasma=5000;TEMP=370" will return vec![("o2", 2500_f32), ("plasma", 5000_f32), ("TEMP", 370_f32)]
pub fn parse_gas_string(input: &str) -> IResult<&str, Vec<(&str, f32)>> {
separated_list0(
tag(";"),
Expand Down
1 change: 1 addition & 0 deletions src/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl Reaction {
})?;
Ok(our_reaction)
}
/// Gets the reaction's identifier.
#[must_use]
pub fn get_id(&self) -> ReactionIdentifier {
self.id
Expand Down
33 changes: 14 additions & 19 deletions src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ struct TurfMixture {

#[allow(dead_code)]
impl TurfMixture {
/// Whether the turf is processed at all or not
pub fn enabled(&self) -> bool {
self.flags.intersects(SimulationFlags::SIMULATION_ANY)
}

/// Whether the turf's gas is immutable or not, see [`super::gas::Mixture`]
pub fn is_immutable(&self) -> bool {
GasArena::with_all_mixtures(|all_mixtures| {
all_mixtures
Expand All @@ -119,6 +121,7 @@ impl TurfMixture {
.is_immutable()
})
}
/// Returns the pressure of the turf's gas, see [`super::gas::Mixture`]
pub fn return_pressure(&self) -> f32 {
GasArena::with_all_mixtures(|all_mixtures| {
all_mixtures
Expand All @@ -128,6 +131,7 @@ impl TurfMixture {
.return_pressure()
})
}
/// Returns the temperature of the turf's gas, see [`super::gas::Mixture`]
pub fn return_temperature(&self) -> f32 {
GasArena::with_all_mixtures(|all_mixtures| {
all_mixtures
Expand All @@ -137,6 +141,7 @@ impl TurfMixture {
.get_temperature()
})
}
/// Returns the total moles of the turf's gas, see [`super::gas::Mixture`]
pub fn total_moles(&self) -> f32 {
GasArena::with_all_mixtures(|all_mixtures| {
all_mixtures
Expand All @@ -146,6 +151,7 @@ impl TurfMixture {
.total_moles()
})
}
/// Clears the turf's airs, see [`super::gas::Mixture`]
pub fn clear_air(&self) {
GasArena::with_all_mixtures(|all_mixtures| {
all_mixtures
Expand All @@ -155,6 +161,7 @@ impl TurfMixture {
.clear();
});
}
/// Copies from a given gas mixture to the turf's airs, see [`super::gas::Mixture`]
pub fn copy_from_mutable(&self, sample: &Mixture) {
GasArena::with_all_mixtures(|all_mixtures| {
all_mixtures
Expand All @@ -164,7 +171,9 @@ impl TurfMixture {
.copy_from_mutable(sample);
});
}
pub fn clear_vol(&self, amt: f32) {
/// Clears a number of moles from the turf's air
/// If the number of moles is greater than the turf's total moles, just clears the turf
pub fn clear_moles(&self, amt: f32) {
GasArena::with_all_mixtures(|all_mixtures| {
let moles = all_mixtures
.get(self.mix)
Expand All @@ -188,6 +197,7 @@ impl TurfMixture {
}
});
}
/// Gets a copy of the turf's airs, see [`super::gas::Mixture`]
pub fn get_gas_copy(&self) -> Mixture {
let mut ret: Mixture = Mixture::new();
GasArena::with_all_mixtures(|all_mixtures| {
Expand All @@ -200,6 +210,9 @@ impl TurfMixture {
});
ret
}
/// Invalidates the turf's visibility cache
/// This turf will most likely be visually updated the next processing cycle
/// If that is even running
pub fn invalidate_vis_cache(&self) {
self.vis_hash.store(0, std::sync::atomic::Ordering::Relaxed);
}
Expand Down Expand Up @@ -227,24 +240,6 @@ impl TurfGases {
self.graph.remove_node(index);
}
}
/*
pub fn invalidate(&mut self) {
*self.map.lock() = None;
}
*/
/*
pub fn turf_id_map(&self) -> TurfGraphMap {
self.map
.lock()
.get_or_insert_with(|| {
self.graph.
.enumerate()
.map(|(i, n)| (n.weight.id, NodeIndex::from(i)))
.collect()
})
.clone()
}
*/
pub fn update_adjacencies(&mut self, idx: TurfID, adjacent_list: List) -> Result<(), Runtime> {
if let Some(&this_index) = self.map.get(&idx) {
self.remove_adjacencies(this_index);
Expand Down

0 comments on commit e238484

Please sign in to comment.