Conway's game of life, also just known as Life, is a cellular automation game created in 1970 by John
Conway, a British mathematician.
This game has a few rules that we need to be aware of prior to beginning creating the game.
The first rule is any live cell with fewer than two live neighbors dies as if by under population.
Any live cell with two or three live neighbors lives on to the next generation.
Any live cell with more than three live neighbors dies as if by overpopulation.
And then lastly, any dead cell with exactly three live neighbors becomes a live cell as if by reproduction.
So we can condense these into the following three rules Any live cell with two or three live neighbors
survives.
Any dead cell with three live neighbors becomes a live cell.
And then all other live cells die in the next generation.
Similarly, all other dead cells stay dead.
So those are the basic rules for the game of life.
And so now let's talk about how.
Webassembly and rust and you know, everything just kind of interacts and some of some of the things
that we need to take into consideration when using rust to create webassembly.
So for our game, we are going to create a fixed size, periodic universe where cells on the edges have
neighbors that wrap around to the other side of the universe because neighbors wrap around the edges
of the universe.
Gliders can keep running forever.
And one of the first things what I want to clear up is what Chasm Bind Gin is.
So you can see it here and you can also see it here.
And our template, it is a common understanding of how to work with compound structures across this
boundary.
So it involves boxing rust structures and wrapping the pointer and a JavaScript class for usability
or indexing into a table of JavaScript objects from rust.
So ASM Bind Gin is a very convenient is very convenient, but it does not remove the need to consider
our data representation and what values and structures are passed across this boundary.
Instead, think of it as a tool for implementing the interface design that we choose.
So there are two things that we should always be thinking about to optimize.
So we want to minimize copying into and out of the webassembly linear memory because unnecessary copies
impose unnecessary overhead.
And then secondly, we want to minimize serializing and d serializing similar to copies.
Serializing and serializing also imposes overhead and often imposes copying as well.
If we can pass opaque handles to a data structure instead of serializing it on one side, copying it
into some known location in the webassembly linear memory and serializing it on the other side, we
can often reduce a lot of overhead.
So why isn't buying gin helps us to find and work with opaque handles to JavaScript objects or boxed
rust structures.
So in essence, by using ASM Bind Gin, in this instance we are exposing the greet function to our.
JavaScript.
And then, as a general rule of thumb, a good at JavaScript web assembly interface design is often
one where large, long lived data structures are implemented as rust types that live in the webassembly
linear memory and are exposed to JavaScript as opaque handles, a.k.a. using the ASM bind gen.
JavaScript calls exported webassembly functions that take these opaque handles, transform their data,
perform the heavy computations, query the data, and ultimately return a small copy able result.
By only returning the small result of the computation, we avoid copying and or serializing everything
back and forth between the JavaScript garbage collected heap and the webassembly linear memory.
So that is just something to take into consideration.
It's a very important aspect that I really want you to understand.
So if you're still a little iffy on it, please rewatch this lecture again.
And then if you have any questions, please ask them in the Q&A section.
Because knowing when to use this ASM engine is really going to help you organize your code.
Help you think?
You know, far ahead in your project.
And it will help speed up your overall the overall performance of your project.
So now that we have that in the back of our mind, while we're creating our project, let's begin creating
our game.