6 min read

The Tweaks engine

We’re doing something at 2weeks that’s relatively uncommon for new game studios: we’re building our own game engine.
The Tweaks engine
It's hard to take a screenshot of an engine. Here's the init script for Homestretch Bet!

We’re doing something at 2weeks that’s relatively uncommon for new game studios: we’re building our own game engine. We call it Tweaks.

Conventional game engines

There are lots of good reasons not to build your own engine. The most basic one is that there are already a number of great engines available to use. They have big ecosystems, lots of developers are already familiar with them, and you can save yourself a lot of time, effort, and focus.

There’s been a lot of convergence here over time. Unreal has gained a ton of market share with PC and console developers (especially this generation), and Unity has a firm hold on the mobile market. I’ve been heartened to see Godot, a great open-source engine, start to gain traction with indie developers.

Shoutout to other cool alternative engines like LÖVE, used by the recent indie hit Balatro.

None of these options are optimized for our needs. We’re building games on the open web for you and your friends. This means we need an engine that is designed for the web.

To be clear, all of these engines can export web builds (or kinda can in Unreal’s case - Epic dropped official support midway through the lifecycle of Unreal 4), but there are a lot of constraints and limitations.

Epic Citadel was the original WebGL demo for Unreal Engine (now no longer available online)

These engines are just not designed for the web - they’re built around a set of conventions established for installed applications. For example, on most platforms, it’s generally fine for a game to have a big initial install ‘cause it’ll get cached on your device and will load quickly each future time you run the game. On the web, though, you might be redownloading the game files frequently, and anything more than a few megabytes can really hamper the experience.

If you’re really careful with how you use certain engine features, you can still make great web games, and people do. But it requires constant vigilance to not let a dependency creep in that breaks the web experience. Really, it’s a testament to great engineering that these engines can produce games that run on the web at all (and particularly a testament to the brilliance of Emscripten, the compiler toolchain that all of these engines use for their web builds).

Conventional web engines

Just because we need an engine optimized for the web, that doesn’t mean we have to build our own. There are great engines that are tailor-made for the web. Two of the most popular are babylon.js and three.js, both of which have a really impressive array of rendering features and integrate with websites much more seamlessly than conventional game engines. If you’ve seen some impressive 3D stuff on the web, there’s a good chance it was built with one of these engines.

For Minecraft's 10th anniversary, Mojang ported Minecraft Classic to Babylon.js

For us, using a web engine creates a reverse problem. The reason we’re releasing experiments on the open web is to get real feedback from players about what’s compelling and where we should reinvest. When we find an exciting new concept, we want to expand it into a full game and then distribute it everywhere.

Web experiences are not easily portable to native platforms. You can wrap a web experience in a native app using software like Electron, but this is a very heavyweight solution because you’re essentially shipping a whole mini-browser.

The mismatch between the web browser tech stack and a conventional OS makes portability hard in both directions.

Tweaks

We’re taking a hybrid approach with Tweaks.

Like Unity and Godot, Tweaks is a native engine that can be cross-compiled to the web via Emscripten. This is great for iteration: sidestepping browser deployment and running a native app during development is fast and lets us leverage great native debuggers like Visual Studio and profilers like Superluminal.

Tweaks supports glTF for 3D models - hooray for open standards! I always thought this mosquito in amber was the coolest of the glTF sample models.

Like babylon.js, every engine module in Tweaks is tailor-made to fit web paradigms. It’s optimized for fast downloads, low memory footprints, and browser permissions restrictions. Everything translates one-to-one from the native app to the web so that we can spend less time on compatibility testing and more time making great games.

Once when we’ve found something great, we can be cross-platform quickly, shipping native apps on PC, console, and mobile alongside our web releases.

Tweaks and 2weeks

The technical benefits are only part of why we’re building our own engine.

The rest is about independence.

We're building for the open web because we think it's the best place to deliver experimental games to people. There’s a technical side to this too (it’s awesome how low-friction it is to get into a game in a browser) but the bigger dimension is that we can have a direct relationship with our players.

Traditional game platforms are overcrowded, restrictive, and take a big chunk of any revenue you earn.

Likewise, both major commercial engines now take their own slice of revenue, leaving even less for developers. Also, when you’re dependent on someone else’s engine, they can change the terms on you at any point.

The current environment is extremely dynamic for game developers, and we want more control over how we navigate it.

That’s why we’re building Tweaks and delivering to the web. We’re building our own ship and sailing for open waters.

Postscript: building the engine

Unlike any of these more mature engines, Tweaks is very early, and we are continuing to stand up core engine features as we build new experiments.

This factors heavily into how we prioritize the experiments. We can’t yet tackle ideas that require lots of engine tech we haven’t yet built, but we like ideas that require one or two new engine capabilities (especially if they’ll be useful to lots of future projects).

The past few weeks, we’ve been learning from the release of Homestretch Bet and shipping some improvements while planning our next experiment. The next one supports multiplayer, which means Tweaks needs to support multiplayer too! Part of the planning has been standing up new engine features the next experiment will need.

Networked multiplayer is a great example of a mismatch between traditional platforms and the web. Networked games conventionally use a network protocol called UDP for fast, low-latency communication. Web browsers don’t provide direct access to UDP for a variety of reasons, but you can establish UDP transport via a technology called WebRTC. Traditional platform OSes don’t provide WebRTC support, which is a quite complicated stack of protocols (and besides, UDP’s right there).

To deal with the mismatch, we built WebRTC support into Tweaks! (thanks to help from a great open source library called libdatachannel)

One cool side effect is that our engine now supports crossplay. Right now our only use case is a simple test app that does peer-to-peer chat, but very soon it will be powering multiplayer experiences for you and your friends.

Crossplay!