On April 1st 2019, I released a game called Build Wars. You can play the original game or read the previous developer diary.

This year, I released an updated game, and you're reading the updated developer diary right now.

Let's rewrite the whole thing

One of the things I learned from the previous game was that javascript is mostly unsuitable for this kind of game development. Important data structures (like tuples, hash maps over tuples, octrees) are not natively supported, and javascript does not provide the required tools to implement them in a performant way.

Enter WebAssembly. You can compile different languages (like C++) into WebAssembly, and your browser can execute WebAssembly. The execution is still sandboxed, so it's as safe as javascript, but you can use the full flexibility of C++. Porting Build Wars looked like a fun exercise to learn WebAssembly.

Of course, learning one new and overwhelming technique at a time is for chumps. Instead of using a language I know (like C++), I used a language I didn't know: Rust. Rust is a modern systems programming language that's as fast as C++, but much safer. It doesn't need to stay compatible with concepts introduced in C in 1973, thus it can freely apply all the theoretical advances in language design made in the last half century.

Lessons from rust

Rust's major selling point is that the language can detect (and prevent) whole classes of errors when compiling. In C++, it's up to the programmer to prevent these errors. The second reason I picked rust is its excellent support for WebAssembly.

As expected, diving into two new concepts at the same time wasn't the easiest thing to do, but I wanted to learn both of them anyway. No point in porting it to C++/WebAssembly, then again to Rust/WebAssembly, right?

Luckily, Rust has an excellent book, which I read in full before starting the rewrite. Then I remembered a lesson from last year's transition from WebCraft into my own engine: do not write it from scratch, port it over gradually. Like last year, that approach worked well.

Rust itself is a pleasure to write in; it is amazingly well designed. But, as any Rust beginner will tell you, the learning curve takes a sharp turn the first time you encounter the borrow checker. So I read a lot, gained a better understanding of the concept of borrows, and in the end I prevailed.

The problems I had with javascript were gone. Having access to a low level language gave me the flexibility to do things the right way. The decision to port to rust paid off - I learned a lot, and the code is simpler and more readable. I've also measured 2x to 10x performance improvements for different modules.

In short: porting the engine was a success.

A better world for everyone

Now that the engine was fast and clean, I wanted to improve the map data. Last year, I managed to extract the terrain data using Tyria3D, but I failed to get the props - the 3d models for houses, bridges, trees, fences, cavern ceilings etc. As a workaround, I exported the collision data, then filled in blocks by hand - but as you can plainly see, that's ugly. This year, I wanted to do better. And back into Tyria3D I went.

After spending weeks on this, I had a much better terrain extractor, cleaner code, faster and automated exports - but still no prop data.

Hiatus

That was sometime summer or fall 2019. Then I stopped working on it. I don't remember the exact reason - frustration over my failure to extract props, other interesting projects, video games, general real life distractions? Probably a combination of all of those. I knew I wanted to get back to it, just not right now.

Then suddenly it was March again and the deadline loomed.

I had to make a tough decision: do I abandon everything else and grind through (like I did last year), or do I postpone the 2.0 release another year? With Corona hitting, the decision was easy. I decided against a stressful experience during these times. Instead I worked on improving the software I use to keep in touch with friends and family.

So Build Wars 1.1 is mostly the same as 1.0 - except with a new engine. The map is block for block identical, I didn't even bother to put up new stars.

Fingers crossed that I'll do better next year.