‹ Back to projects

Convida

An implementation of Conway’s Game of Life based on this tutorial.

Quick Start

To start the server, enter:

Terminal window
git clone https://github.com/lbeckman314/convida
cd convida/www
npm install
npm run start

Screenshot of Convida

Development

Dependencies

wasm-pack

rust

Then, within the convida directory, enter:

Terminal window
wasm-pack build

to build the Rust code in src/lib.rs to the pkg directory.

Source Descriptions

File/DirectoryDescription
Cargo.lockdependencies.
Cargo.tomldependencies.
README.mdthis README file.
benchesused in optimizing runtime.
convida-alt.pngalternative logo image.
convida.pnglogo image.
convida.xcfGIMP logo file.
cross-compile.shbeta cross compiling script.
perf.dataused in optimizing runtime.
pkgdestination directory for compiled rust code.
screenshot.pngscreenshot image.
srcmain source files.
targetRust’s target directory.
testsused in testing ticks and created cell patterns.
wwwdirectory for web client.

Alternatives

Improvements on the Tutorial

  • Introduce an <input type="range"> widget to control how many ticks occur per animation frame.
  • Add a button that resets the universe to a random initial state when clicked. Another button that resets the universe to all dead cells.
  • On Ctrl + Click, insert a glider centered on the target cell. On Shift + Click, insert a pulsar.
  • At this point, the next lowest hanging fruit for speeding up Universe::tick is removing the allocation and free. Implement double buffering of cells, where the Universe maintains two vectors, never frees either of them, and never allocates new buffers in tick.

TODO

  • Implement the alternative, delta-based design from the “Implementing Life” chapter, where the Rust code returns a list of cells that changed states to JavaScript. Does this make rendering to <canvas> faster? Can you implement this design without allocating a new list of deltas on every tick?
  • As our profiling has shown us, 2D <canvas> rendering is not particularly fast. Replace the 2D canvas renderer with a WebGL renderer. How much faster is the WebGL version? How large can you make the universe before WebGL rendering is a bottleneck?
  • We only ever instantiate a single Universe, so rather than providing a constructor, we can export operations that manipulate a single static mut global instance. If this global instance also uses the double buffering technique discussed in earlier chapters, we can make those buffers also be static mut globals. This removes all dynamic allocation from our Game of Life implementation, and we can make it a #![no_std] crate that doesn’t include an allocator. How much size was removed from the .wasm by completely removing the allocator dependency?