Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have recently read about how to create procedural worlds... but how do I save one?

In games like Terraria or Minecraft users can freely modify the landscape, but that world can't be recreated from the start seed. What techniques are used to save procedural but modifiable worlds?

share|improve this question

4 Answers 4

Save the seed which you used to generate the world, and the modifications either as atomic "commands" or the results of those.

Then when loading the saved game, you do the following:

  1. Procedurally generate the part of the world you're currently visiting.
  2. Apply the saved commands, or overwrite the generated elements with the saved ones.

Update: And of course, there's the option of saving your generated world just like a normal world, if the resources are available (as seen in Minecraft). In this case, you should save only the parts of the world that have already been visited (otherwise the procedural generation would be pretty much pointless), tile by tile. This eats up more HDD and / or database resources, but will require less CPU power when loading a game.

share|improve this answer
2  
In addition to the modifications, he probably also needs to save the seed that was used to build the procedural world ;-) –  bummzack Oct 5 '12 at 9:32
    
@bummzack Yes of course, I forgot to mention that, because it's obvious :-) I'll edit my answer. –  Marton Oct 5 '12 at 10:42
9  
I'm not entirely sure that regenerating the world from the seed is the best idea. World generation usually involves complex algorithms and hence takes time : we generate random worlds not to save space generally but to benefit from the randomness. I would therefore consider that saving the entire world in a binary format would be more efficient. –  Jonathan Connell Oct 5 '12 at 12:02
2  
So you're saying to save a procedurally generated world, you generate it, then save it? This is not a very complete answer. –  Byte56 Oct 5 '12 at 14:44
2  
@Random832 Minecraft does save the world in a binary format, rather than regenerating it from the seed and replaying the modifications. To get around the problem of saving the entire world, Minecraft only saves the chunks that have been generated so far. As you further explore the world, your save game becomes larger. –  Joseph Mansfield Oct 5 '12 at 16:35

Saving a procedurally generated world is the same as saving any tile map data.

You would likely want to save the world in binary format, assuming the world is built out of different types of tiles, you will have to:

  1. Decide on the total number of different tile types.(depending on that you will need more or less bits to represent each tile)
  2. Define the width and height of the visited(modified) world.
  3. Represent the world tile by tile from the top-most left tile (including sky) row by row to the bottom-most right tile.
  4. If you wish to save up on space, use DEFLATE or a similar algorithm to compress this 2d-array(represented as 1-d) http://en.wikipedia.org/wiki/DEFLATE
  5. Use appropriate file I/O for your API to store the data on disk.

You can use the same method to save a voxel based map too.

Storing a vertices based map model is more complex.

Would you like me to elaborate on that subject?

share|improve this answer
    
If you want to, you may be able to save it in a png file by color coding each tile. This will allow you to overview the result quickly without using a specialized viewer. –  Zehelvion Sep 16 at 13:04

About Minecraft, the world uses voxels so it's quite easy to save, more informations here :

http://www.minecraftwiki.net/wiki/Region_file_format

http://www.minecraftwiki.net/wiki/Level_Format

As already said, save a seed used to generate the world, and adapt your save format to what your world is made of (cubes, atoms, etc...).

share|improve this answer

Whatever data structure you're using to store the world in memory can be used as a template for writing and reading from disk. The procedural portion of your game will fill these data structures the first time, if no data is available from disk. Then, when you're ready to unload an area from memory, write it to disk as it has been generated or modified.

Whenever you're ready to load a new area into memory, first check to see if it's been generated before and saved to disk. If it has, load it from disk instead of from your procedural generation algorithms.

Typically this would be done with chunks of terrain. You can either save each chunk to it's own file, or create a more complex on disk structure that contains data in a single file with a look-up table. There are other questions about good ways to save your data to disk.

share|improve this answer
    
+1 because it's also a completely valid answer. –  Marton Oct 5 '12 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.