Skip to content

Commit 81d862b

Browse files
committed
huh
1 parent fc42e96 commit 81d862b

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

Cargo.lock

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ log = "0.4"
1818

1919
# You only need serde if you want app persistence:
2020
serde = { version = "1", features = ["derive"] }
21+
instant = { version = "0.1.12", features = ["wasm-bindgen", "inaccurate"] }
22+
rand = "0.8.5"
23+
getrandom = { version = "0.2.12", features = ["js"] }
2124

2225
# native:
2326
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

map.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::mem;
2+
3+
#[repr(u8)] // NOTE: we would want this to be a single byte apparently!
4+
pub enum ConnwayCellState {
5+
Alive = 1,
6+
Dead = 0,
7+
}
8+

src/connway/connway_map.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::mem;
2+
3+
#[repr(u8)] // NOTE: we would want this to be a single byte apparently!
4+
pub enum ConnwayCell {
5+
Alive = 1,
6+
Dead = 0,
7+
}
8+
9+
pub struct Universe {
10+
pub width: u32,
11+
pub height: u32,
12+
cells: Vec<ConnwayCell>,
13+
pub cell_size: f32,
14+
pub speed: u128,
15+
last_frame_time: Instant,
16+
}
17+
impl Universe {
18+
fn get_index(&self, row: u32, col: u32) -> usize {
19+
(row * self.width + col) as usize
20+
}
21+
fn live_neighbor_count(&self, row: u32, col: u32) -> u8 {
22+
let mut count: u8 = 0;
23+
for delta_row in [self.height - 1, 0, 1].iter().cloned() {
24+
for delta_col in [self.width - 1, 0, 1].iter().cloned() {
25+
if delta_row == 0 && delta_col == 0 {
26+
continue;
27+
}
28+
29+
let neighbor_row = (row + delta_row) % self.height;
30+
let neighbor_col = (col + delta_col) % self.width;
31+
32+
33+
}
34+
}
35+
count
36+
}
37+
}

src/connway/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod connway_map;

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(clippy::all, rust_2018_idioms)]
22

33
mod app;
4+
mod connway;
45
pub use app::TemplateApp;

0 commit comments

Comments
 (0)