Introduction

I'm working towards releasing a game as a solo dev (Ionic Drive), and I want to build a habit of posting more. So this is the first post of hopefully many, as an introduction to my game and the engine underneath it (PlayPhys).

Future posts will dive into more technical detail about how I hit a smooth framerate with hundreds of thousands of collidable objects in a deterministic way, and I think they'll be very fun to both write and read.

A love for hard problems

Some of my earliest memories are playing games like Prince of Persia and Encarta MindMaze on a surprisingly diverse set of platforms - the iMac, Windows 95, and even some Linux distros (Red Hat, I think?).

Pretty quickly I was curious how people built this stuff. Both of my parents are quite technical - they programmed with punch cards at university, and my dad continued to be a programmer throughout his entire career. As you can imagine, many of the machines I remember playing games on were bits of tech my dad had around the house.

At 9, I was introduced to Visual Basic 6, and since then I've never looked at any other career seriously.

My first disastrous attempt at programming was making a GUI text editor. It turns out, text (and encoding) is hard. I never did quite crack it, but I did manage to make some form-based games.

For the next decade, I rotated rapidly through programming games in any language I was introduced to, everything from Turbo Pascal to TI-BASIC to C# 1.2. I hand-rolled my own sprite-sheet based animation sequencing to make fighting games, made entire RPGs out of not much more than Menu( and Goto statements, and so much more I can scarcely remember.

By the time I finished uni, I was in love with classic Game AI programming - a love that started with interpreting Sun Tzu's The Art of War to compete in (and win) our Game AI class's Planet Wars competition.

It was my pursuit of excellence, and a fair bit of luck, that landed me my first job in the industry - working on a web-native game engine for a small indie studio hoping to carve out a niche. There, I fell in love with a second area of games programming that I'll never be bored of - physics. I was tasked with implementing the physics engine, and using cannon.js as a base, I reimplemented it from scratch in TypeScript as "Howitzer.ts" (because it was bigger and more modern).

Maybe it wasn't the best use of project resources - but I'll be forever thankful for how much I was able to glean from doing so. Sometimes simply sitting down and rewriting something line by line can teach you so, so much.

Introducing PlayPhys

It's been nearly 15 years since then, and I have always had a small physics/game engine I've been working on the side.

I wanted to continue the work I did with Howitzer and see how much more physics work I could do. So I coined the highly creative name, "PlayPhys", and got to work.

The intent was to be a physics engine first, and a game engine second. Just enough rendering, tooling, etc. to let me play with the fun stuff. Maybe some day it would be advanced enough for me to go back to my other love and build game AI on top - but first I wanted to tinker.

Of course, like every engine programmer... I've never been happy. I've restarted the engine 5 times in various languages. Python[1], C++, C, C++ again, and now in Zig.

After getting a bit frustrated with modern C++ (see: the reflection syntax, the build/package ecosystem, issues with modules and contracts, etc.), Zig has been a breath of fresh air. I particularly love that it has no macros, and that everything is written in one language - including compile-time metaprogramming and the build system.

Zig has been so much fun, the fun has kept me engaged, and this time... I've made something that's really promising. There's always been a gap between my ambition and my ability to deliver - with real life always sapping my energy to the point where I don't want to come home and program more. The joy of Zig programming and a little more dedication helped close that gap. So did better self-management and scoping, support from my beloved wife, and some LLM support to push me over humps.

Now I've got an engine I want to do more with than just tinker and show my industry friends. I want to blog about some of its features - and build a game on top of it! I'll dive into details over the upcoming posts, but I'm particularly proud of:

  • A really ergonomic ECS core
  • A fantastic automatic scheduling system making full use of modern CPUs
  • Compile-time memory budgeting with TigerStyle (ish) memory management
  • A unique unified material system for both physics and rendering
  • Rendering only via hardware ray tracing (and Vulkan 1.4) streamlining my renderer compared to others which maintain backwards compatibility

As an example, here's the system that moves all 600,000 ice ring chunks along their orbits every tick. It's automatically sharded across all workers, and below you can see how this is one of the systems that benefits most from this.

pub const OrbitalMotionSystem = struct {
    pub const threading: pp.ecs.Threading = .multi;
    pub const Query = pp.ecs.Query(.{ pp.ecs.SharedWrite(Transform), pp.ecs.Read(Orbital), pp.ecs.Optional(Tumble) });
    pub const Context = pp.ecs.SystemContext(.{
        .resources = .{ pp.ecs.Use(pp.ecs.WorldClock), pp.ecs.Use(RingFlow) },
    });

    pub fn update(rows: Query, _: f32, ctx: Context) !void {
        const t = ctx.resources.read(pp.ecs.WorldClock).elapsed_s;
        const rate: f64 = ctx.resources.read(RingFlow).arc_rate_mps;
        var it = rows.iterator();
        while (it.next()) |row| {
            row.transform.position = position(row.orbital.*, t, rate);

            // The optional is present or absent for a whole archetype.
            // This predicate never alternates within a shard.
            if (row.tumble) |m| row.transform.rotation = rotation(m.*, t);
        }
    }
};
A Tracy capture of one frame, showing nearly full utilisation of the CPU.
One 2.42 ms frame in Tracy: the scheduler spreads the ECS systems across 16 threads
Using Hotspot to visualise a 10-second perf recording, showing all 16 CPU cores filled from start to finish.
A 10-second perf capture visualised in Hotspot. All CPU cores are being utilised.

Motivating myself with a product focus

When the engine started really coming together, I decided to push myself. Rather than just making a toy engine for my own edification, I made the decision to focus on building an actual game first, with the engine only fleshed out just enough to support it.

It might have taken me 15 odd years to fully internalise it, but having an actual product decide what I build helps me focus and deliver.

So with that in mind, I've been actively building Ionic Drive on top of PlayPhys since early this year. Ionic Drive is designed to utilise the unique features of my engine - flying around in space through a densely packed planetary ice ring, watching and having dramatic collisions which are based on as much actual science as I can fit into it, and trying to complete a course as fast as possible.

The Ionic Drive title logo over a diagonal ice ring.

After rebuilding the basic engine core in Zig, I didn't add a single feature speculatively. Ionic Drive uses every single part of the engine. Fortunately, almost everything I expected to need, I needed - but even I get some things wrong (like what broadphase design would make sense for Ionic Drive - actually this has been quite interesting to get right). It's always better to build things for a real purpose, no matter how experienced you are in the domain.

The player ship flying past a large refracting chunk of ice.
Ray tracing is quite nice with large chunks of translucent ice.

The goal was simple: use a small physics-based game to drive the development of my physics/game engine. All I wanted was to release it on Steam, perform the entire game development loop end-to-end as a solo dev, and pat myself on the back (even if I never earned enough to cover the Steam Direct fee).

The run complete screen with a time of 2:31.36.
There's something quite satisfying about succeeding in an Ionic Drive run.

In fact, I had a demo ready for the most recent Steam Next Fest (October) - but I uploaded the build too late for it to be approved in time. A little frustrating, but after resetting my expectations and changing my goals, I'm going to push Ionic Drive even further before the next edition in February.

As I finished writing this, Valve announced they're cancelling the February Next Fest. Oh well, I'll just release when I'm ready.

Blogging more

Missing the October Next Fest gave me some breathing room and time, so I'm going to raise my ambitions. I'm going to continue to refine Ionic Drive and PlayPhys, and deliver a better game on top of a better engine. But I'm also going to go ahead and start marketing it.

I've set aside an hour a week to work on blog posts, with topics ranging from memory allocation strategies, dynamically scheduling ECS systems, CPU threading in game engines, through to higher-level topics like this post. I don't expect that I will publish a blog post a week, as they usually take much more than an hour to write, but having that dedicated time should lead to a more regular cadence.

I've set up a community space for Ionic Drive (and PlayPhys) on Zulip, and I hope to speak to you all more directly there.

In the meantime, please wishlist Ionic Drive on Steam, and if you want to ask me anything, ask in the discussion thread.

  1. I wanted to do some crazy multi-process architecture with IPC. Why? Who knows! ↩