Skip to content

Commit

Permalink
my improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeWaka committed Jul 5, 2024
1 parent 2e238b0 commit 094eb20
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
File renamed without changes.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ num-integer = { version = "0.1.46", optional = true }
dmi = { version = "0.3.5", optional = true }
tracy_full = { version = "1.8.0", optional = true }
ammonia = { version = "4.0.0", optional = true }
fast_poisson = { version = "0.5.2", optional = true }
fast_poisson = { version = "0.5.2", optional = true, features = ["single_precision"]} # Higher versions have problems with x86 due to 'kiddo'.

[features]
default = [
"acreplace",
"batchnoise",
"fast_poisson_sample",
"poissonnoise",
"cellularnoise",
"dmi",
"file",
Expand All @@ -91,7 +91,6 @@ default = [
all = [
"acreplace",
"batchnoise",
"fast_poisson_sample",
"cellularnoise",
"dmi",
"file",
Expand All @@ -109,6 +108,7 @@ all = [
"hash",
"iconforge",
"pathfinder",
"poissonnoise",
"redis_pubsub",
"redis_reliablequeue",
"unzip",
Expand All @@ -120,7 +120,7 @@ acreplace = ["aho-corasick"]
batchnoise = ["dbpnoise"]
cellularnoise = ["rand", "rayon"]
dmi = ["png", "image", "dep:dmi"]
fast_poisson_sample = ["fast_poisson"]
poissonnoise = ["fast_poisson"]
file = []
git = ["gix", "chrono"]
http = ["reqwest", "serde", "serde_json", "once_cell", "jobs"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Additional features are:
* hash: Faster replacement for `md5`, support for SHA-1, SHA-256, and SHA-512. Requires OpenSSL on Linux.
* iconforge: A much faster replacement for the spritesheet generation system used by [/tg/station].
* pathfinder: An a* pathfinder used for finding the shortest path in a static node map. Not to be used for a non-static map.
* poissonnoise: A way to generate a 2D poisson disk distribution ('blue noise'), which is relatively uniform.
* redis_pubsub: Library for sending and receiving messages through Redis.
* redis_reliablequeue: Library for using a reliable queue pattern through Redis.
* unzip: Function to download a .zip from a URL and unzip it to a directory.
Expand Down
14 changes: 8 additions & 6 deletions dmsrc/noise.dm
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#define rustg_noise_get_at_coordinates(seed, x, y) RUSTG_CALL(RUST_G, "noise_get_at_coordinates")(seed, x, y)

/**
* Generates a 2D poisson disk distribution ('blue noise'), which is relatively uniform.
*
* params:
* seed: str
* x: int, width of the noisemap
* y: int, height of the noisemap
* radius: int, distance between points on the noisemap
* `seed`: str
* `width`: int, width of the noisemap (see world.maxx)
* `length`: int, height of the noisemap (see world.maxy)
* `radius`: int, distance between points on the noisemap
*
* returns:
* string: a X*Y length string of 1s and 0s representing a 2D poisson sample collapsed into a 1D string
* a width*length length string of 1s and 0s representing a 2D poisson sample collapsed into a 1D string
*/
#define rustg_noise_poisson_sample(seed, x, y, r) RUSTG_CALL(RUST_G, "generate_poisson_sample")(seed, x, y, r)
#define rustg_noise_poisson_map(seed, width, length, radius) RUSTG_CALL(RUST_G, "noise_poisson_map")(seed, width, length, radius)
41 changes: 18 additions & 23 deletions src/noise_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,33 @@ fn get_at_coordinates(seed_as_str: &str, x_as_str: &str, y_as_str: &str) -> Resu
})
}

byond_fn!(fn generate_poisson_sample(seed, x, y, r) {
get_poisson_sample(seed, x, y, r).ok()
byond_fn!(fn noise_poisson_map(seed, width, length, radius) {
get_poisson_map(seed, width, length, radius).ok()
});

fn get_poisson_sample(
fn get_poisson_map(
seed_as_str: &str,
x_as_str: &str,
y_as_str: &str,
width_as_str: &str,
length_as_str: &str,
radius_as_str: &str,
) -> Result<String> {
let x = x_as_str.parse::<f64>()?;
let y = y_as_str.parse::<f64>()?;
let r = radius_as_str.parse::<f64>()?;
let width = width_as_str.parse::<f32>()?;
let length = length_as_str.parse::<f32>()?;
let radius = radius_as_str.parse::<f32>()?;
let seed = seed_as_str.parse::<u64>()?;

let points = Poisson2D::new()
.with_dimensions([x, y], r)
let points: Vec<[f32; 2]> = Poisson2D::new()
.with_dimensions([width, length], radius)
.with_seed(seed)
.iter();
let mut pointmap = vec![vec![0usize; y as usize]; x as usize];
let mut output = String::new();
.to_vec();

// we're just gonna truncate these to the nearest point
for p in points {
let point_x = p[0] as usize;
let point_y = p[1] as usize;
pointmap[point_x][point_y] = 1;
}

for row in pointmap {
for cell in row {
if cell > 0 {
let mut output = String::new();
for y in 0..length as usize {
for x in 0..width as usize {
if points
.iter()
.any(|&point| point[0] as usize == x && point[1] as usize == y)
{
let _ = write!(output, "1");
} else {
let _ = write!(output, "0");
Expand Down

0 comments on commit 094eb20

Please sign in to comment.