r/cprogramming • u/fleaspoon • 5d ago
I just released my first game, made from scratch in C. Here's how I built my own build system.
Seven years ago I decided to learn how to make a game from scratch in C and last week I finally released it.
When I started the project I wanted to write as much as possible myself from scratch. In the end that included the game engine, a Vulkan renderer, the level editor, asset pipeline and the build system. The codebase is in C style but I use the C++ compiler so I can use operator overloading for math. I don't use the standard library, exceptions or OOP.
Initially I was using CMake but I found it quite painful to work with. Whenever I wanted to update the setup of my build I had to go back to a different language and deal with something that often felt like a hack and kept breaking.
Because of this I decided to build my own tool. The build system ended up being a small program written in the same style as the rest of the game, using the same header only base library. In essence it just calls clang directly and the setup of the project is a simple fat struct.
On each run every source file gets hashed and it gets compared against the hashes from the previous build. Each source file has a saved entry in a cache that also includes the exact compiler command, so changing a flag will rebuild everything influenced by it.
Also clang generates a dependency file for every source file that lists the headers it includes. If any of those headers change, that source gets recompiled. Everything compiles in parallel and the linker only runs when something has actually been rebuilt.
This approach doesn't require having a separate configuration language or generated project files like CMake. Building only requires clang and since the build tool is just simple code, it can be debugged like the game itself. Thanks to all this adding shader compilation, bundling and code signing was quite simple. I tried doing that with CMake but I just couldn't figure out how to make it work properly.
The game I built with these tools is called Satelital. It's a 2D space puzzle game about exploring alien worlds and figuring out how their rules work. There are no explicit explanations of the puzzle rules. Instead, you gradually build up your understanding of how the world works and use that knowledge to solve new puzzles.
If you're interested in the technical side of building a game engine from scratch, I also wrote an article about it on my blog:
https://spectralorbit.com/blog/satelital_game_engine
And the game is available on Steam with a free demo:
https://store.steampowered.com/app/3256790/Satelital/
6
u/podule-games 5d ago
Looks cool, nice to see another game made in C. I wishlisted.
3
u/tastygames_official 5d ago
I'm also making a game in C (C90, to be exact, using SDL3. Overloading is a performance-killer and there's nothing wrong with having multiple functions like add_vec2(), add_vec3() and so on). I also find CMake super easy. Once you got it set up once, you can essentially re-use for every project and swap out the paths. I use GCC, so so can't speak to the clang integration.
But in the end - it's all about what works for you. I personally don't like to re-invent the wheel, so until I come up against real issues that truly have not been solved or a custom solution, THEN I go for custom tooling. And then it's usually just a bash script ;-)
Gonna have to check out your game now...
1
u/iLaysChipz 5d ago
I'm curious about your build system. Do you have the source hosted anywhere?