rustwasm / book

The Rust and WebAssembly Book
https://rustwasm.github.io/docs/book/
MIT License
1.75k stars 211 forks source link

Reasoning and design given/discussed for moving to canvas and actual code changes are inconsistent. (4.4) #209

Open jdnewman85 opened 4 years ago

jdnewman85 commented 4 years ago

Where in the docs did you come across this? https://rustwasm.github.io/book/game-of-life/implementing.html#rendering-to-canvas-directly-from-memory Describe what about it does not make sense The following portion:

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."

Why does it not make sense? 1) The javascript doesn't know the width and height of the universe at this point. Getter functions for this are added in the following portion:

"To get the necessary information from the Rust implementation, we'll need to add some more getter functions for a universe's width, height, and pointer to its cells array. All of these are exposed to JavaScript as well. Make these additions to wasm-game-of-life/src/lib.rs:"

which comes afterwards in the book.

2) The render method doesn't get modified, but infact replaced with the 'cells()' method. The book states that we will modify the render method to return a pointer to the cells, then in the later portion mentions adding the 'cells()' method for this reason. It's not immediately obvious that this is the change to 'render()' outlined above.

How could we improve it? Rewrite and/or reorder to make sense. This should include mentions of: -Adding the appropriate getting methods, providing the javascript code with the width and height of the universe. -Removal/Replacement of the 'render()' method with the 'cells()' method.