---
title: "Projekt 4x ⁞ Arthur Erlich"
canonical: "https://me.arthurerlich.de/blog/article/projekt4x/"
---

blog·12.10.2026·Updated14.10.2026

# Projekt 4x

Projekt 4x is my 4X space strategy game in early development. A real-scale star-system simulation with a floating origin, GPU-drawn planets and a host-authoritative multiplayer clock, and the hard parts it took to get there.

* 4X
* Space
* Godot
* Multiplayer
* Simulation

## What is Projekt 4x?

Projekt 4x is a 4X space strategy game (e**X**plore, e**X**pand, e**X**ploit, e**X**terminate) that I am building with [Godot 4.7](https://godotengine.org). It is an early prototype. There is no combat yet, no colonization yet, and the ships do not fly yet. What is already in place: real star systems simulated at real scale, a camera that can zoom in 110,000x without jitter, and a host-authoritative multiplayer clock.

The goal, straight from the GDD: a campaign is a long-term project. Players play it across multiple sessions, 100+ hours in total. A big undertaking like building a ship takes \~10 to 30 in-game years. And the simulation _is_ the gameplay, not a backdrop for it. A space strategy game where the solar system is a flat, decorative background is a missed opportunity. If the distances and the orbits do not matter, why set the game in space at all?

## Why this is hard

Because I picked two scale values and refused to fake either of them:

* **Space:** 1 world unit = 100,000,000 km. Proxima Centauri sits at \~8,700 AU from the system barycenter. That is not a stylized number, it is the value in the data file.
* **Time:** 1 real second = 1 in-game day at normal speed, up to 60 in-game days per real second at ultra-fast. With a 365-day year, ultra-fast is roughly one game year every six real seconds.

And then thousands of moving bodies on top of that: a sector with 10,000 bodies should still run at 60 fps while the player pans and zooms. Godot was not built for this. Node positions are 32-bit floats, and everything that touches a position (camera, rendering, clicking, saving, multiplayer) has to agree on where a body is. That is where most of the problems below come from.

## The jitter problem: floating origin

The first big one. A 32-bit float has fewer exact steps the larger the number gets. At 13,000 world units, the distance to Proxima, the smallest step is about 0.001 units. At maximum zoom (110,000x) that step becomes a \~107 pixel jump on screen. Any body more than about 5 AU from the origin visibly shakes. Jupiter shakes.

I could have rebuilt the engine with double-precision floats. I researched it and built a prototype that tested both approaches at Proxima at max zoom. A custom engine build is a maintenance trap for a game project, so I went with a **floating origin** instead: every body keeps its true position in 64-bit floats, and only `true position − origin` ever gets written into a node. The camera and the origin travel together, so the number that touches a 32-bit float stays small. No jitter, no custom engine. The rule: never put a large position into a node, because a parent transform cannot undo the rounding error.

## Drawing planets: from nodes to MultiMesh

The first version did what you would expect in Godot: every body was a node that drew its own disc and solved its own orbit in `_process`. It worked. It also cost 72 ms per frame at 10,000 bodies, and the orbital lines were one draw call per orbit: 2.5 seconds per frame.

So the drawing moved out of the nodes entirely. Now it is **one MultiMesh for all body discs, one for all orbital lines, two draw calls total**. A Vulkan compute shader with real 64-bit doubles solves Kepler’s equation for every body every frame and writes the MultiMesh instance buffers directly. The `Body` node stays a data node: it keeps the orbit elements, the parts, the Summary rows and the save snapshot, but it draws nothing and has no `_process` anymore. The decision is written down in an architecture decision record, the design lives in the GDD’s planet-rendering document, and I prototyped it before committing.

The hard parts were the small things:

* GLSL has no double-precision `sin`/`cos`. The compute shader contains hand-written fp64 trigonometry.
* I cannot read positions back from the GPU. A readback stalls the pipeline or arrives two frames late. So the CPU computes its own exact 64-bit positions at 10 Hz for picking and clutter checks. GPU and CPU positions agree to 0.006 px or better.
* A MultiMesh that a compute shader writes needs a custom AABB, because the CPU-side bounding box does not see the GPU writes. And calling `multimesh_set_buffer()` from the CPU afterwards overwrites the GPU data. Both of those I learned the expensive way.
* There is no fallback. Intel GPUs, macOS/Metal and the Compatibility renderer have no fp64 compute, and on those devices the bodies simply do not draw. The game logs a hint and starts anyway. That is a bold call for a game I want to sell, and I made it on purpose: two rendering paths means two sets of bugs.

![Prototype: 10,001 bodies and orbital lines drawn on the GPU with fp64 compute, frame-time overlay at 10 ms](/_astro/GpuBodiesPrototype.Y1PR1XDd_ZRhOcT.webp) 

![Prototype: 10,001 bodies and orbital lines drawn on the GPU with fp64 compute, frame-time overlay at 10 ms](/_astro/GpuBodiesPrototype.Y1PR1XDd_1W9Cdt.webp) 

## When everything overlaps: the clutter grid

Real-scale space is crowded. Zoom out and thousands of discs overlap on screen. The rule: in every overlapping pair, the smaller body hides. Easy to explain, O(n²) to compute. The pair loop in GDScript needed \~2.5 seconds per scan at 10,000 bodies.

The fix is a uniform grid in screen space with \~64 px cells: each disc goes into every cell it covers, and bodies are only compared inside the same cell. The catch is that even with the grid, GDScript missed the target, so this one loop was rewritten in C#. Now a scan at 10,000 bodies costs \~12 ms. A gdUnit test still runs the old pair loop as a reference and compares the results, so the fast version can never quietly change the rules.

Picking had the same problem from the other side: every body carried an `Area2D` click area and the physics broadphase choked on the overlap pairs. The click areas are gone too. A CPU `BodyPicker` queries the clutter grid instead.

![Test sector with 1,000 bodies at zoom 16: orbital lines everywhere and the Summary window open](/_astro/ClutterGrid1000.DCZM47Wp_2cjXoW.webp) 

![Test sector with 1,000 bodies at zoom 16: orbital lines everywhere and the Summary window open](/_astro/ClutterGrid1000.DCZM47Wp_11W3oA.webp) 

![Earth clicked in the Sol sector: selection ring, leader line and Summary window](/_astro/EarthSummary.D4KVjDkc_Z1rRp4p.webp) 

![Earth clicked in the Sol sector: selection ring, leader line and Summary window](/_astro/EarthSummary.D4KVjDkc_2gdBJF.webp) 

## Real star systems as data

The sectors are JSON files, and the data is real: mass, luminosity, radius, orbital period, eccentricity, all from actual observations. I built a fetcher tool that pulls from the NASA Exoplanet Archive, JPL Horizons and the Small-Body Database and writes sector files from them.

One of the start sectors is Alpha Centauri, and it is not a toy: a barycenter with the tight A/B binary pair, and Proxima Centauri \~8,700 AU away with two planets, Proxima b and Proxima d. Because the data is real, the simulation inherits the real structure of the system for free. A new sector is just a new JSON file.

## Multiplayer: one clock to rule them all

The clock is host-authoritative. There is exactly one shared time speed. A peer that wants a different speed sends a request, the host validates it, and the change is broadcast to everyone. No per-player fast-forward, because “my time ran ahead of yours” is the classic desync you never fix.

Peers still run their own simulation with client-side prediction and reconcile against periodic host broadcasts of elapsed time and speed. Small drift smooths out over half a second to a second; large drift, a late join or a hitch, snaps instantly. Late joiners replay the full state, and the waiting room shows what that looks like: the host picks a save and every player downloads it with a progress bar. A bigger rework covers LAN discovery, Steam lobbies and joining by IPv6 or domain name.

![Waiting room prototype: four players, empire list and saved-game download progress](/_astro/WaitingRoom.B_5CSXtB_ZeFee3.webp) 

![Waiting room prototype: four players, empire list and saved-game download progress](/_astro/WaitingRoom.B_5CSXtB_1aMLGx.webp) 

## What’s next

The simulation core is stable enough to build the actual 4X layer on top of it. The current work is ship movement as real orbital mechanics: a Lambert solver (Izzo’s method) in C#, an intercept solver, gravity assists, Hohmann and bi-elliptic transfers. Then come the fleets, the navigation computers and the colonization.

![Debug playtest: a computed Lambert transfer arc from Earth to Mars across the Sol sector](/_astro/Projekt4xLambertTransfer.Pi5mz21e_Z2x0Fyw.webp) 

![Debug playtest: a computed Lambert transfer arc from Earth to Mars across the Sol sector](/_astro/Projekt4xLambertTransfer.Pi5mz21e_tUxXA.webp) 

Almost every feature has a wayfinder map issue, research tickets, “grilling” tickets where I argue with myself about every decision, a prototype branch and then the implementation tasks. The GDD is the source of truth: a design change goes into the GDD first, then into the code.

Enjoy your build!
