Skip to content

Commit

Permalink
Added an auxgm manual; fixed dupe gases (!)
Browse files Browse the repository at this point in the history
also cargo fmt whoops.
  • Loading branch information
Putnam3145 committed May 13, 2022
1 parent 201d971 commit 4968ad1
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "auxmos"
version = "1.1.0"
version = "1.1.1"
authors = ["Putnam <putnam3145@gmail.com>"]
edition = "2021"

Expand Down
29 changes: 29 additions & 0 deletions docs/AUXGM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Auxgm is auxtools's way of consolidating gas info and allowing gases to be added at runtime. Its name is primarily a send-up of XGM, and... it mostly means the same thing, but it's subtly different.

# Requirements

Auxtools expects a global proc `/proc/_auxtools_register_gas(datum/gas/gas)` and a global variable called `gas_data`, with a list called `datums`. When `gas_data` is initialized, it should go through each individual gas datum and initialize them one-by-one, at the *very least* by adding an initialized gas variable to the `datums` list, but preferably using `_auxtools_register_gas`. Duplicated entries will overwrite the previous entry (as of 1.1.1).

Individual gas datums require the following entries:

`id`: string
`name`: string
`specific_heat`: number

...And that's it. The rest is optional.

If you're using Auxmos's built-in tile-based atmos, auxgm also requires an `overlays` list, which is initialized alongside `datums`. This can be completely empty if you want and Auxmos will run happily. Citadel initializes it like so:

```dm
if(gas.moles_visible)
visibility[g] = gas.moles_visible
overlays[g] = new /list(FACTOR_GAS_VISIBLE_MAX)
for(var/i in 1 to FACTOR_GAS_VISIBLE_MAX)
overlays[g][i] = new /obj/effect/overlay/gas(gas.gas_overlay, i * 255 / FACTOR_GAS_VISIBLE_MAX)
else
visibility[g] = 0
overlays[g] = 0```

Everything except the overlays lines are unnecessary. However, overlays does need to be organized as seen here, as auxgm handles gas overlays.

If you're *not* using tile-based atmos, you're done; Auxmos's update_visuals is only called from a callback in auxgm's tile processing code and thus can be ignored.
48 changes: 31 additions & 17 deletions src/gas/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,37 @@ 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"))?;
let gas_cache = GasType::new(gas, TOTAL_NUM_GASES.load(Ordering::Acquire))?;
let cached_id = gas_id.clone();
let cached_idx = gas_cache.idx;
unsafe { GAS_INFO_BY_STRING.as_ref() }
.unwrap()
.insert(gas_id.into_boxed_str(), gas_cache.clone());
GAS_SPECIFIC_HEATS
.write()
.as_mut()
.unwrap()
.push(gas_cache.specific_heat);
GAS_INFO_BY_IDX.write().as_mut().unwrap().push(gas_cache);
CACHED_IDX_TO_STRINGS.with(|gas_ids| {
let mut map = gas_ids.borrow_mut();
map.insert(cached_idx, cached_id.into_boxed_str())
});
TOTAL_NUM_GASES.fetch_add(1, Ordering::Release); // this is the only thing that stores it other than shutdown
match {
unsafe { GAS_INFO_BY_STRING.as_ref() }
.unwrap()
.get_mut(&gas_id as &str)
} {
Some(mut old_gas) => {
let gas_cache = GasType::new(gas, old_gas.idx)?;
*old_gas = gas_cache.clone();
GAS_SPECIFIC_HEATS.write().as_mut().unwrap()[old_gas.idx] = gas_cache.specific_heat;
GAS_INFO_BY_IDX.write().as_mut().unwrap()[old_gas.idx] = gas_cache;
}
None => {
let gas_cache = GasType::new(gas, TOTAL_NUM_GASES.load(Ordering::Acquire))?;
let cached_id = gas_id.clone();
let cached_idx = gas_cache.idx;
unsafe { GAS_INFO_BY_STRING.as_ref() }
.unwrap()
.insert(gas_id.into_boxed_str(), gas_cache.clone());
GAS_SPECIFIC_HEATS
.write()
.as_mut()
.unwrap()
.push(gas_cache.specific_heat);
GAS_INFO_BY_IDX.write().as_mut().unwrap().push(gas_cache);
CACHED_IDX_TO_STRINGS.with(|gas_ids| {
let mut map = gas_ids.borrow_mut();
map.insert(cached_idx, cached_id.into_boxed_str())
});
TOTAL_NUM_GASES.fetch_add(1, Ordering::Release); // this is the only thing that stores it other than shutdown
}
}
Ok(Value::null())
}

Expand Down
4 changes: 3 additions & 1 deletion src/turfs/monstermos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ fn process_planet_turfs(
Ok(Value::null())
}

#[deprecated(note = "Katmos should be used intead of Monstermos or Putnamos, as that one is actively maintained.")]
#[deprecated(
note = "Katmos should be used intead of Monstermos or Putnamos, as that one is actively maintained."
)]
pub(crate) fn equalize(
equalize_turf_limit: usize,
equalize_hard_turf_limit: usize,
Expand Down
4 changes: 3 additions & 1 deletion src/turfs/putnamos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ fn explosively_depressurize(

// Just floodfills to lower-pressure turfs until it can't find any more.

#[deprecated(note = "Katmos should be used intead of Monstermos or Putnamos, as that one is actively maintained.")]
#[deprecated(
note = "Katmos should be used intead of Monstermos or Putnamos, as that one is actively maintained."
)]
pub fn equalize(
equalize_turf_limit: usize,
equalize_hard_turf_limit: usize,
Expand Down

0 comments on commit 4968ad1

Please sign in to comment.