I was playing Minecraft the other day and went very, very far from my spawn point and eventually returned home. When I retraced my way back, I couldn’t wrap my head around how the game not only generates the environment but remembers the placement of everything as I return to the same places I had already been. With that in mind, wouldn’t the game be required to remember… an absurd amount of information as the user explores their world? How are the file sizes of these worlds not crazily big?
In: 12
When the chunk is generated, it is added to the save file. I have a Minecraft world that has a 10 GB file because I have gone very far.
Games like Minecraft generates the world on demand based on a seed value
It’s a pseudo randomizer that makes a unique world, but following certain rules so that you get chunks of blocks (like a lake) side by side instead of totally random blocks that would make no sense.
The seed value is a pseudo random code or string that you can plug into the randomizer to get a random world. Normally this is generated by the game, but you can manually enter one if you want.
The world doesn’t exist until you get close enough to that area, then the game generates it for you.
Storing that information in Minecraft is actually relatively straight forward.
You have to consider that part of the genius of Minecraft is that everything is a block. So you have to consider what is the smallest amount of information that I need to create and store a minecraft world?
You don’t need to store all the pixels of the entire object that is a block, because they are all very similar or identical, so a block can be represented by a single keyboard character in memory.
Most likely every block in the world has a location value in a 3D grid of X,Y,Z with 0,0,0 being the starting block
Each block also contains a value which is the type of block it is, and it’s status.
So a dirt block might have a value of A, a rock block B, etc etc
So the file will be
0,0,0 – A
0,0,1 -B
and so on
That’s a lot of text, but text is very easy to compress.
On top of that the game has to store the location of sprites like baddies and animals, and the player characters.
When the save file is loaded into memory the game loads the assets like the blocks and draws them based on their locations in the save file.
Games like that contain the *instructions* of how to build an infinite world. And then the world gets generated as the player explores it.
A brand new world might only be a few MB in size because you haven’t explored it.
If you explored billions of square blocks in a world, then the world file would be much bigger because then all that space would need to be saved as you interacted with it.
Honestly no man’s sky’s worlds are nowhere near as diverse as other games like minecraft. Most planets are just one biome and there’s not a whole lot of mineable area. It’s just a bunch of set pieces and semi random animal / plant configurations. Most of the specifically detailed content is player created. I run into basically identical stuff on different planets all the time.
In Minecraft, the world is only generated in parts as players approach that individual part for the first time. The result will always be the same for that same location given the same seed and program version, but there’s no need to generate it before it’s approached.