Sign in to follow this  
etsuja

Saving/Loading a persistant world

Recommended Posts

I'm working on a single player semi persistant world and want to make it sort of how oblivion was in the way that the stuff that the player changes stays changed. A problem I've run into is how to save and load everything from a map type area. I'm planning on having the world divided into large maps on disk. I don't want to have alot of these areas, just a few large ones and I just want to have the area the player is in on the map loaded. The map disk file is divided into sections sort of like a tile based game with the sections name, then how many objects/npc's/enemies.. etc are on that map section and have whatever is on it loaded/saved on the fly as the player comes to new sections of the map. The problem I have is that these sections in the map disk file have to be of variable size for the fluctuating number of objects and what have you on that map section and I'm not sure how I should go about loading and saving the sections of variable size from the map file. so a map section would look like this in the map file: Section name number objects number npc's number monsters object name object position object name object position npc name npc position npc name npc position monster name monster position monster name monster position Does anyone have any suggestions on how I could do this?

Share this post


Link to post
Share on other sites
For some reason I was thinking it would take too much memory to load the entire map file into memory and modifying it there but areas/maps will probly only take up about 1-10 megs of ram so I guess I'll just load em into memory and modify em there then save to disk when I'm done with it or periodically.

Share this post


Link to post
Share on other sites
The project I'm working on at the moment that supports something similar to what you're describing saves the original map completely unchanged, and then saves a separate per-user map delta that contains information that is different than the original map. The main reason for this is that my entire maps get pretty big, and even if they are partitioned up into smaller sections [which they are] redundantly storing the entire map would be prohibitively costly in terms of disk space. Instead I store a difference, since the vast majority of the information on the map does not change. The map files themselves can quite easily grow to be quite large, but the delta files are usually only about 5% of the size, and contain redundant data as that is contained in the actual original map. First the original file is loaded completely, then the delta file is loaded, and anything present in the delta file just overwrites anything currently present [and adds new stuff too]. Technically there exists some information that is read in the map file that is not ever used [and thus is wasted], but the advantage in terms of space saved seems well worth the added roughly 5% of loading time [your results may vary, but my delta files tend to hit an upper bound of about 7% of the original file size, with an average of much less].

Share this post


Link to post
Share on other sites
As I see it there are two things you are trying to do. First up you want to have a large world divided into map tiles that can be loaded as needed. Each tile or map section will require different quantities of data. To deal with this you can either have an indexing system for one big map file (so you know where to get the data from when loading a specific map section) or much more easily have a separate data file for each sector (this is what I've done in the game I'm working on). Splitting data between files might reduce performance a bit (due to all the file opening and closing) but not dramatically in my experience.

As a bit of advice spend some time planning out how the map will be split up and how you will handle movement and loading of new map sectors. Particularly do you want absolute coordinates (the player is at point x,y in the world) or relative coordinates (the player is at point x,y in tile tx,ty) to be used. Look at how Oblivion or Morrowind handle things (play with the editor) and/or google for 'continuous world dungeon siege' to get some more ideas. If you can cleanly and neatly sort out how your game handles the map sectors the rest is easier in the long run.

Secondly you want the persistent world. This can be solved by having static map sector files that 'describe' the world at the start of the game and then save files with all the deltas (all the elements in the game impacted by the player's actions ... flags triggered, objects moved, etc). Then it's a question of managing loading of the map sectors so that any impacted objects or NPCs are not (re)loaded from the map files, but set up according to the data in the save file. Simple boolean flagging of each game object would be enough to work this one out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this