Skip to content

Commit

Permalink
Updating wording and refactoring note to Exercises section
Browse files Browse the repository at this point in the history
  • Loading branch information
cube committed Jan 2, 2024
1 parent 366042a commit 63e5936
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/game-of-life/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ Generating (and allocating) a `String` in Rust and then having `wasm-bindgen`
convert it to a valid JavaScript string makes unnecessary copies of the
universe's cells. As the JavaScript code already knows the width and
height of the universe, and can read WebAssembly's linear memory that make up
the cells directly, we'll modify the `render` method to return a pointer to the
start of the cells array.
the cells directly, we'll create a new function in the `Universe` that returns a *pointer* to the start of the cells array.

Also, instead of rendering Unicode text, we'll switch to using the [Canvas
API]. We will use this design in the rest of the tutorial.
Expand Down Expand Up @@ -760,4 +759,15 @@ encourage you to go learn about hashlife on your own!
};
```

Refactoring Note: Because JavaScript is now getting the Universe via direct memory in wasm, we no longer need the `Display` trait we created earlier, nor the `render()` method, in `lib.rs`. Furthermore, the `Cell` enum can also be removed. However, if you decide to keep them for other use cases, the `Display` trait will need to be updated like so :

```rust
#[wasm_bindgen]
impl fmt::Display for Universe {
// ...
let symbol = if cell == 0 { '◻' } else { '◼' };
// ...
}
```

</details>

0 comments on commit 63e5936

Please sign in to comment.