Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ospencer/wasm4-gr
Bindings to WASM-4, the fantasy game console for building games with WebAssembly
https://github.com/ospencer/wasm4-gr
game-development grain wasm wasm-4 wasm4 webassembly
Last synced: 28 days ago
JSON representation
Bindings to WASM-4, the fantasy game console for building games with WebAssembly
- Host: GitHub
- URL: https://github.com/ospencer/wasm4-gr
- Owner: ospencer
- Created: 2023-05-21T19:35:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-06T06:36:23.000Z (9 months ago)
- Last Synced: 2024-10-16T08:13:09.836Z (3 months ago)
- Topics: game-development, grain, wasm, wasm-4, wasm4, webassembly
- Language: Makefile
- Homepage: https://ospencer.github.io/wasm4-gr/
- Size: 31.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wasm4-gr
This project contains Grain bindings to [WASM-4](https://wasm4.org/), a low-level fantasy game console for building small games with WebAssembly. You can find docs for the library [here](https://ospencer.github.io/wasm4-gr/), but for a general overview of WASM-4, check our their [docs](https://wasm4.org/docs/).
## Building your project
The only value that needs to be provided by your module is a function called `update`, taking no arguments and returning no values. This function is called on each frame of the game engine.
WASM-4 modules (called cartridges) must be <64k and meet some other specific requirements, so a number of compiler flags are required to produce compatible cartridges. To compile the `hello-world.gr` example in the `examples` directory, run
```sh
make hello
```or to invoke the compiler directly, run
```sh
grain compile --release --elide-type-info --import-memory --use-start-section --memory-base 8192 --initial-memory-pages 1 --maximum-memory-pages 1 --wasi-polyfill src/wasm4-wasi-polyfill.gr -I src examples/hello-world.gr
```To depend on `wasm4-gr` in a directory outside of your project, add the `src` directory to your include path with `-I path/to/wasm4-gr/src`. You'll also need to provide the path to the WASI polyfill provided by this library with the `--wasi-polyfill` flag.
## The examples
The `hello-world.gr` file contains the basic game that is shown in the WASM-4 tutorial, and the `music.gr` file contains a game that utilities WASM-4's sound system to play a simple tune.
## Tips to fit within 64k
This limitation is part of the fun. Grain's extensive `Number` type brings in quite a bit of support code, so avoiding it (and standard libraries that depend on it) is the best way to keep the cartridge size small. This includes the math operations provided by `Pervasives`, like `+` and `==`, but conveniently, the WASM-4 API uses the `Uint8` and `Uint16` types. The `hello-world.gr` example is only 7k, and even with a number of sprites and a good chunk of music data, the `music.gr` example is 21k.
Good luck and have fun!