kazilib
What it is
kazilib is my own C++ library: the code every game and tool I write stands on, kept in one place instead of copied from project to project. It holds nothing about any one game. Whatever two projects need alike lives here, written once, tested once, and improved for all of them at the same time.
It started in January 2023 from stlx, the utility code Helbreath Empire had carried since 2017, and grew as each new project took something from it and gave something back.
What's inside
- Networking: my build of ENet 1.3.18 with packet and command pools, and the packet layer on top, where a whole packet is read in one line,
auto [a, b] = in->As<i8, u32>();. Broadcasters group a feature's packets into one family. The network runs on a thread of its own, and a WebSocket gateway lets browser players join the same servers. - Threads: worker threads, a parallel loop that spreads jobs over the cores (the calling thread works too, and each job's output comes back in order), and an A* pathfinder on a worker thread.
- Time: a microsecond clock that never wraps, each thread's frame delta, and rate gates.
- Graphics and input: an optional SFML 3 layer with the GLSL shaders the games share (Scale2x, xBR), Dear ImGui, coloured text from tags, and a chat line with typed commands that every project uses the same way.
- Video: screen recording through FFmpeg.
- The web: the same programs compiled to WebAssembly, SFML running on SDL3 and WebGL2, so the games on this site play in the browser.
- Testing: Testerino, the bridge my automated tests drive every program through: real clients and servers started, played and checked by routines.
- Building: one FASTBuild runner for every project, on all the cores and on the other PCs that answer, with a shared compile cache.
One library, two versions where they must differ
Helbreath Millennium is live and Helbreath Empire is the next generation, and sometimes they need different behaviour from a class with the same name. kazilib keeps both side by side, each in its own inline namespace, lib::ml and lib::emp. A project only sees its own, so lib::Path means the right thing in each. Everything that is the same is written once, in plain lib, and both use it. Over time, code moves from the two versions into the shared one.
Used by
- Helbreath Millennium and Helbreath Empire: both clients and servers, through hb_lib, the Helbreath library built on it.
- Tiled: the multiplayer tile-map prototype, its client and its server.
- Tileship: the turn-based strategy game.
- Tic Tac Toe: the online multiplayer game.
- Yip and Yips: the two space shooters.
- RTG, Cogollos and rythme.prototype: the older prototypes, brought to SFML 3 and the browser.
Proven by tests
The library has static tests of its own (grids, parallel loops, pathfinding, text tags), built and run on their own, each answering its number of failures. And since the Helbreath games run on it, every routine that plays them, thousands of checks of movement, packets and combat, is also a test of kazilib.
Technologies
- C++23
- ENet
- SFML 3
- Dear ImGui
- FFmpeg
- WebAssembly
- FASTBuild
From the blog
The frame never waits: from one thread to many in Helbreath's servers
From the original server's single message loop, through MySQL queries that froze every player, to queues and a thread for each kind of work, and how that made tables of millions of rows searchable in a live game. A lesson first learned at Helbreath Olympia.
From timestep to delta time: how Helbreath learned to walk smoothly
Helbreath's movement, from animation frames on a fixed clock to framerate-independent delta time, through Tiled, a prototype written to learn how it works, up to the step as a window of time that both games share today.
The Broadcaster: from one 56,000-line switch to a class every game shares
How Helbreath's packets find their code: from the original server's single switch and hand-typed party numbers to the Broadcaster, born in 2017 and shared today by Helbreath Millennium and Helbreath Empire.
A C++ beautiful syntax evolution with packet serialization
A Helbreath packet that once took three lines per field now takes one line per packet. Here is how I watched C++ get there: from pointer casts and hand-moved cursors to variadic templates, tuples, structured bindings and objects that serialize themselves.