diff --git a/.gitignore b/.gitignore index ea8c4bf..ccb5166 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.vscode \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3e5b386..85ba78c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,6 +12,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" name = "golrs" version = "0.1.0" dependencies = [ + "metrohash", "termion", ] @@ -21,6 +22,12 @@ version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +[[package]] +name = "metrohash" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ba553cb19e2acbc54baa16faef215126243fe45e53357a3b2e9f4ebc7b0506c" + [[package]] name = "numtoa" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 77b3566..04865f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ repository = "https://github.com/MajorBarnulf/golrs" [dependencies] termion = "1.5" +metrohash = "1.0" \ No newline at end of file diff --git a/patterns/simple.txt b/patterns/bar.txt similarity index 66% rename from patterns/simple.txt rename to patterns/bar.txt index 98f6f22..046ea95 100644 --- a/patterns/simple.txt +++ b/patterns/bar.txt @@ -1,3 +1,3 @@ # # - # \ No newline at end of file + # diff --git a/patterns/gen.ts b/patterns/gen.ts new file mode 100755 index 0000000..e96a460 --- /dev/null +++ b/patterns/gen.ts @@ -0,0 +1,21 @@ +#!/usr/bin/env -S deno run + +const { args } = Deno; + +const size = parseInt(args[0] ?? "5"); +const frequency = parseFloat(args[1] ?? "0.5"); + + +function* range(from: number, to: number) { + let current = from; + while (current < to) yield current++; +} + +let result = ""; +for (const _y of range(0, size)) { + for (const _x of range(0, size)) + result += Math.random() < frequency ? '#' : ' '; + result += '\n'; +} + +console.log(result); \ No newline at end of file diff --git a/src/world/hashed_world.rs b/src/world/hashed_world.rs index 3f43646..aba5fd0 100644 --- a/src/world/hashed_world.rs +++ b/src/world/hashed_world.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; +use metrohash::MetroBuildHasher; + use crate::{pos, Cell, Pos, World}; const CHUNK_SIZE: usize = 16; @@ -34,7 +36,7 @@ struct ChunkPos(Pos); #[derive(Debug, Clone, Default)] pub struct HashedWorld { - chunks: HashMap, + chunks: HashMap, } impl HashedWorld {