Stellar Throne Devlog #7: The Zig Simulation Goes Live
Today marks a major milestone: the Zig simulation backend for Stellar Throne is now live in production. The dual-engine design pairs Godot's UI client with Zig's high-performance backend.
The Challenge
We had a fully functional Zig engine with a 52x performance improvement validated, but couldn't deploy it due to serialization failures between the two engines.
Turn Processing Fix
An async race condition prevented the game from functioning properly. The code waited forever for an event that had already happened. The solution involved storing signal references before turn coordination and adding yield calls between phases.
Serialization Breakthrough
The core issue: Godot used snake_case properties while Zig used camelCase. Initial manual field mapping proved insufficient. The solution implemented bidirectional camelCase serialization across four data structures (SimEmpire, SimFleet, SimPlanet, SimStarSystem) with custom toJSON() and fromJSON() methods.
Type System & Data Integrity
GDScript files required refined type annotations. Two critical bugs emerged: fleets disappeared after turn processing (location field structural issues) and empire colors were lost (Color type handling across engines needed standardization to RGBA objects).
Results
- 659 lines of Zig serialization code
- 8 commits total
- Game now runs 52x faster
- Large galaxies resolve in milliseconds instead of seconds
- Integration tests passing across the board
Next Steps
Monitor for hidden serialization edge cases, expand test coverage, and begin profiling for further optimization.