Tung's Word Box

Posts

Learning Zig's Build System using raylib

Posted on 2024-11-06; Tags: gamedev, programming, zig

I picked up some Zig recently and figured I'd take the chance to learn its build system using raylib. raylib already has pretty good community-maintained idiomatic Zig bindings, but we want to learn, so we're going to do it the "hard" way instead.

raylib has a build.zig, which means that it can be used directly with Zig's package manager. Its C headers can also be translated into a Zig module that can be @imported, thanks to Zig's built-in C translator.

Note: We will not be using @cImport, since it seems like it'll be removed in future versions of Zig.

(Read more)

Announcing Coric's Quest

Posted on 2024-08-24; Tags: gamedev, rust, webassembly

Coric's Quest screenshot

So here's the game I've been working on the the last six months: Coric's Quest! It's a free and open source RPG that fits about two hours of game play into a single 9 MB file. There are native builds for Windows and Linux, and a WebAssembly build that can be played in a web browser.

You can play it right now at itch.io and on its homepage. The source code can be found on GitHub. There's also a project page here on this site.

Making a CHIP-8 Interpreter: chip8run

Posted on 2023-02-07; Tags: c, chip-8, emulator, programming, webassembly

I wanted to try my hand at making interactive graphical applications with C, WebAssemnbly and the Sokol header-only libraries when I stumbled across the CHIP-8. Creating a CHIP-8 interpreter ("emulator") was as good an excuse as any to scratch my itch, and a little while later I ended up with chip8run, which you can try online right now.

(Read more)

My Workflow for following Crafting Interpreters

Posted on 2022-12-24, Updated 2022-12-26; Tags: c, linux, make, programming, testing

I recently worked my way through Robert Nystrom's Crafting Interpreters, which guides you through the process of making an interpreter for a scripting language. The book is made up of three parts: a short part describing Lox (the scripting language made for the book), a tree-walk interpreter written in Java and a bytecode virtual machine interpreter written in C. This post is about how I approached the last part.

The book doesn't recommend any specific setup or workflow, so you're free to go with whatever you like. The rest of this post describes what I went with; all of the code can be found here: https://github.com/tung/clox

(Read more)

Rust and WebAssembly without a Bundler

Posted on 2022-08-04, Updated 2022-08-06; Tags: javascript, programming, rust, webassembly, webdev

If you're just getting into compiling your Rust code into WebAssembly and want to load it in a web browser, you might be taken aback by the multitude of ways of doing so. This seems to be due to the differing pace of web browsers implementing web platform features over the years. A lot of entry-level guides to using Rust and WebAssembly make use of a JavaScript bundler for convenience, but this obscures the relationship between Rust, WebAssembly, JavaScript and HTML, so instead we're going to try doing this all by hand. Specifically, we're going to compile some Rust code into WebAssembly and do a run-down of the ways to load it directly in a web page using just JavaScript. If you want to follow along at home, make sure you have Rust installed and the wasm32-unknown-unknown target:

rustup target add wasm32-unknown-unknown

We're going to look at these loading methods through the perspective of compatibility with three desktop web browsers: Chrome, Firefox and Safari. I'll be consulting the extremely-helpful Can I use website for this info.

Ready? Okay, let's go!

(Read more)