This is the story of implementing what I've learned into a gridless, interactive, world-building sandbox game called Minor Deity.
Minor Deity on Steam: https://store.steampowered.com/app/3876240/Minor_Deity/
Minor Deity Discord Server: https://discord.gg/2NEb4HxwhF
This huge map contains almost 10 million underlying tiny squares and 160 thousand larger hexes with dynamic weather. Tens of thousands of animated units move across an expansive network of roads, bridges and rivers. Millions of trees, rocks, foliage and other objects cover the terrain. A save game for such a huge, densely populated world can easily approach 1GB in size. How do we write all of that onto disk quickly enough that the player barely notices?
As is so often the case, the secret lies in memory management. As we’ve seen in previous videos, huge game worlds come with many challenges, most of them centered around making sure everything happens fast enough to preserve the flow of the game. This becomes even more important when players can edit the world, including its terrain, in real-time. Giving players this much freedom requires storing an enormous amount of information, even if we are frugal with the data types, for example using half-precision values. Of course, players should be able to save the game and continue the journey later, and autosave is also an important quality-of-life feature. As with everything else, we don’t want saving to interrupt the flow of play.
Luckily, the way we set up our data structures in large native memory containers to allow for burst-compiled parallel jobs, is also very beneficial for writing to disk. Take the tens of thousands of units as an example. If we stored each unit as its own object somewhere in memory, we’d have to chase after thousands of pointers to tiny, scattered blocks of memory. So instead, we store all their positions, health values, animations and other data in a handful of large NativeLists. Each list occupies one big contiguous block of memory, and modern storage devices are extremely good at writing large sequential blocks of data.
00:00 Introduction
00:30 Memory Management
01:00 Save and Autosave
01:24 Units Example
01:54 Implementation
04:01 Outro