mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-05-06 04:06:34 +00:00
following tutorial
This commit is contained in:
@@ -7,6 +7,12 @@ edition = "2018"
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3"
|
||||
features = [
|
||||
"console",
|
||||
]
|
||||
|
||||
[features]
|
||||
default = ["console_error_panic_hook"]
|
||||
|
||||
|
||||
19
src/lib.rs
19
src/lib.rs
@@ -3,6 +3,15 @@ mod utils;
|
||||
use std::fmt;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
extern crate web_sys;
|
||||
|
||||
// A macro to provide `println!(..)`-style syntax for `console.log` logging.
|
||||
macro_rules! log {
|
||||
( $( $t:tt )* ) => {
|
||||
web_sys::console::log_1(&format!( $( $t )* ).into());
|
||||
}
|
||||
}
|
||||
|
||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||
// allocator.
|
||||
#[cfg(feature = "wee_alloc")]
|
||||
@@ -63,6 +72,14 @@ impl Universe {
|
||||
let cell = self.cells[idx];
|
||||
let live_neighbors = self.live_neighbor_count(row, col);
|
||||
|
||||
log!(
|
||||
"cell[{}, {}] is initially {:?} and has {} live neighbors",
|
||||
row,
|
||||
col,
|
||||
cell,
|
||||
live_neighbors
|
||||
);
|
||||
|
||||
let next_cell = match (cell, live_neighbors) {
|
||||
// Rule 1: Any live cell with fewer than two live neighbours
|
||||
// dies, as if caused by underpopulation.
|
||||
@@ -88,6 +105,8 @@ impl Universe {
|
||||
}
|
||||
|
||||
pub fn new() -> Universe {
|
||||
utils::set_panic_hook();
|
||||
|
||||
let width = 64;
|
||||
let height = 64;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ canvas.width = (CELL_SIZE + 1) * width + 1;
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
const renderLoop = () => {
|
||||
debugger;
|
||||
universe.tick();
|
||||
|
||||
drawGrid();
|
||||
|
||||
Reference in New Issue
Block a user