Moondog, day 23 (12 Nov): our own ground, a double-precision server, and a world that wraps

About 110 commits, nearly all on large worlds. By the end of the day the terrain was ours: our own tiles, our own pathfinding, our own renderer, and the server running in 64-bit.

Yesterday I cut the navigation mesh into cells. Today the measurements came in, and the seams were fine but wander paths were failing all over. The cause: every time a cell switched on or off, Godot rebuilt the whole map in the background, and paths came back empty for about 25 seconds. Keeping every cell on fixed that but brought back the cost.

So I wrote our own. GridNav keeps the ground as heights every 2 m per 256 m tile and runs A* only in a window around a path's two ends, so a path costs what its length costs, about 0.15 ms. There's no bake and no cache. I tested it on the roughest tile on the map, where 45% of the 2 m steps are steeper than 45°. At 45° creatures got stranded. At 60°, the same angle players can climb, 92% of the ground joined up, so 60° it is. Dungeons got their own layered grid built from the baked walkable floors. That took Godot's navigation off the server completely.

Tiles instead of Terrain3D

The steps went in this order:

  1. A tile file format, and a converter from the old Terrain3D regions (832 tiles, heights identical).
  2. The server loads the tiles and proves their heights and collision match Terrain3D's, bit for bit, before switching over.
  3. Tall-grass cover for stealth comes from the tiles' grass.
  4. The portal serves tiles, and the client draws the ground with our own renderer. Tiles are built on worker threads, and terrain past 2 km is drawn as light tiles.

The first run in game had two good faults. The ground came out black because a PackedColorArray isn't accepted for a vec4[] uniform, so every texture tint stayed at zero. And on a first run the player's tile was still downloading: prediction let them fall, and by the time the tile arrived the body was under it. A heightmap only stops things from above. Now the player is held still until the ground under them is ready.

Editing the land in game

GMs can now sculpt, paint and place grass in the client, with per-tile locks, holes and live refresh for everyone nearby. There's also @fly. Then terrain events: crater, sinkhole, landslide and earthquake, each permanent or healing over a set time, with sounds.

The sound test turned up a real bug. A quake set off over a crater took the crater's bowl for "the ground it found", so when the quake healed it put the bowl back. Now each event only takes back its own change, and anything else that touched the same ground is kept as an offset.

64-bit, and Terrain3D retired

At 350 km, 32-bit floats aren't enough. I built Godot from source in double precision and moved the server to it on .NET 10: positions are 64-bit everywhere, from sessions and creatures to ships, carts, pets and terrain edits. I measured the client too, sliding a camera past small boxes at increasing distances and reading every frame back from the GPU. Drawing holds to 100 km. At 170 km a box jitters by up to 6 px, because the camera's 32-bit position moves in 1.6 cm steps.

Terrain3D's native add-on can't load in a double-precision engine, and the tiles were already the only real copy of the terrain, so I retired it. That removed the add-on, its resources, its converter and four check scripts.

The generator and the wrap

worldgen.py now makes land from a fixed seed: a northern continent and six isles, with ragged coasts, mountain ranges, climate patches and lakes. The world wraps at 350 km. I set the full width now so the seam never moves as more land is added, and checked a crossing at 175 km. The client downloads only the tiles near the player.

Smaller things:

  • Ships keep their ground loaded. An anchored ship's cable reads the seabed every step, but those tiles were dropped after two minutes and read again on the main thread. I found it with a temporary log of who was asking.
  • Wind blows harder at sea. Clear weather gave 1 m/s, which left the frigate making 1 to 2 knots.
  • Static entities load faster. Arriving at the vardo took a 3.2 s frame, 2.6 s of it re-loading the same tree scene from disk 1,807 times because each one was freed as soon as it was used. Loaded scenes are kept now.