Skip to content

Cavu Games Part 2. The Engine

Part 2 of 3 on Cavu Games. The Engine

Chris Pardy
Dec 1, 20265 min read

his is part 2 in a 3 part writeup for how Cavu Games (cavu.games) is designed. This part covers the Rust and Lua powered engine works. Part 1 covered the Intent to Launch flow. Part 3 will cover local development.

Game Engine as App View

When you visit cavu.games many (maybe all) of the games are played via the Cavu Games Engine. The Engine itself is a 2d and 3d rendering engine where game state is represented as an entity tree - more on that later. Games themselves are defined as a set of Lua scripts and WASM modules as well as other assets such as 2d sprites and 3d models.

In AtProto parlance each game is a record with the different assets being blobs. The games themselves can be stored on the publisher on a game developer's PDS. Space support is rolling out initially for game secrets that should stay server side, but eventually to allow gated access to games.

If a set of game scripts and assets is a record, then the game engine running on play.cavu.games is an app view.

Through the wonders of WASM we're able to run an isomorphic engine on both the play.cavu.games server and in your browser. That allows us to build games that are server authoritative without needing a round trip for every in-game action.

Behind the scenes I use a duplexed Websocket, technically a xrpc subscription that I've mis-used, in order to send client intents to the server and get game state diffs back down. Sending state diffs allows some hidden state on the server while also easily reconciling on the client.

This layout also allows me to easily port the engine to non-browser platforms and get distribution and play for free. I'm testing and Android version of the client now and iOS and others will likely be fast to follow. These ports are native wrappers around our Rust client, they still interact with the play.cavu.games server via duplexed websockets.

Stateless and Side Effect Free

Our game engine organizes it's state into entities which are organized in a hierarchy. Each entity has state and a Lua or WASM handler. When events are triggered on the entity the handler can read the current state and emit declarative effects.

Because the game engine owns the entity tree and state we're able to do things like hot swap Lua scripts on a running game.

What are Declarative Effects?

What does it mean when we say that Lua scripts and WASM modules are side-effect free and using declarative effects? There are lots of things such as updating state, changing out sprites, or starting music that our game scripts need to be able to do. Rather than exposing functions that do these actions directly our script run effectively records the desired effects of the script, and then runs them all in the engine code.

This approach of using declarative effects allows the system to run largely untrusted code. We can run the code, auditing it's effects and block or drop them as needed.

Reading and Writing Records

Any AtProto native game engine is going to need to read and write records. In part 1 I discussed the approach to authentication that allows games to have limited read and write access. We can turn these allowed calls into clear effects for both the Lua and WASM scripts. This makes it easy to load an rpg.actor sprite, write stat and item grants, and store save game records.

2d, 3d, Music, Credits, and Gamepads

All games that are built on the Cavu Games engine ship with a generic menu. That gives us a consistent place to put engine related functionality, such as volume/mute selectors from music and sfx. This also provides a home for things every game needs like credits.

Because we're sharing an engine we're also able to add support for things like Gamepads natively. That means that every game will get gamepad support not just ones that build for it. Gamepads are still pretty experimental in cavu games but it highlights the power of building a custom engine for this purpose.

What's Next?

Webtiles

mu.social just added webtil.es to their feed. I've been following the webtiles updates for a while now with the idea of building something with them. One possibility would be a way to have games create webtiles in your repository. This would package a lite version of the cavu games engine with a limited set of assets. Especially for games that allow user-generated-content or encourage collection and curation, sharing a webtile would be a way to add interactivity to what was otherwise just a link.

Cavu Arcade

What if Atmosphere Conf 2027 included a Cavu games arcade cabinet. It's a very silly idea but one that may actually happen after all most of the technical parts are already in place.

  • Intent to Launch (from part 1) provides the mechanism where you could sign-in on your phone and play on an arcade cabinent.
  • A custom version of the play.cavu.games engine that is designed for low-cost hardware, arcade controls, and things like LED sign boards.

Your Games and Your Servers

Currently I'm the only one making games and the only one hosting a game engine, but that's not a limitation of any of the systems. I'm going to be opening this up to anyone who wants to build games, as well as anyone who wants to run a game server. That would mean choices of app views, and lots of games as records. If you're interested in building games reach out to me and We'll support you building games.

In the next part we'll discuss the local development and testing approach, as well as my vision for the Cavu Games forge.

Did you enjoy this article?

Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.

Across the AtmosphereDiscussions