Sign in to follow this  
iXenocider

[C#] Game Saving Problems, Files are too large

Recommended Posts

Hello fellow GameDevs, I have been having a pretty big problem recently. I am trying to find the best way to save data for my map files.

[size=5][u][b]Overview[/b][/u][/size]
Let me give you a brief example of how it works. The world consists of an array (20 x 20) of maps, and in each map, there is an array (20 x 20) of blocks. For further information, I am using [b]C#[/b], and [b]XNA[/b].

[size=5][b][u]Problem[/u][/b][/size]
I use serialization to save the whole world but when I do, the file size is at least 170 Mb. Maybe I am doing it wrong, but I do not know why it is such a large file. If you guys could help me by giving me a better way to save data that would be awesome!

[u][size=5][b]Extra[/b][/size][/u]
I did make it so it only generates the maps that you go into, and the file size is relatively small. But once the player starts playing the game and starts exploring, the file size will eventually be way too large.

[i][b]Thank you in advance.[/b][/i] Edited by iXenocider

Share this post


Link to post
Share on other sites
*Um.... How about using multiple files? One file per map.

*If there's a lot of repetition on the maps you could compress the map (for example with [url="http://zlib.net/"]zlib[/url])

*What do you mean by "it only generates the map"? Can't you save only the necessary data and rebuild the map?

Share this post


Link to post
Share on other sites
[quote name='szecs' timestamp='1339615413' post='4948890']
*Um.... How about using multiple files? One file per map.
[/quote]

That would not help with anything, the total file size would be exactly the same.

[quote name='szecs' timestamp='1339615413' post='4948890']
*If there's a lot of repetition on the maps you could compress the map (for example with [url="http://zlib.net/"]zlib[/url])
[/quote]

I can try that thanks, but it takes time to compress and decompress. I don't want them to be waiting for 3 minutes just to save or load their game.

[quote name='szecs' timestamp='1339615413' post='4948890']
*What do you mean by "it only generates the map"? Can't you save only the necessary data and rebuild the map?
[/quote]

It only generates the maps that they walk into. I can try and think of a way to save only necessary data.

Share this post


Link to post
Share on other sites
You should also save the level separately from the save game. Each level is one file, and the save file only saves the stuff that populates the levels and that can change between different saves.

As far as I know, Zlib is quite fast.

For the "generating" I thought you mean procedural generation, or something like that. Edited by szecs

Share this post


Link to post
Share on other sites
From the sounds of it, you're serializing the maps as entire objects. Instead, use a StreamWriter to save only the data as integers, floats, bytes, etc.. Serializing an entire object results in far larger files than simply serializing the objects' data.

You will have to handle objects stored in more than one location yourself. The easiest solution is to store one copy of each object somewhere and then simply index that data.

Share this post


Link to post
Share on other sites
If your areas are randomly generated... Depending on how you generate them - couldn't you just store the initial seed and any persistent changes as a result of game play?

Share this post


Link to post
Share on other sites
I think you need to provide some more information in order to get meaningful replies.

What kind of objects are you saving? What exactly does a single "block" consist of? How are maps being stored in memory? How exactly are you serializing?

Share this post


Link to post
Share on other sites
I think I might know what the problem is. does each block store the texture file because if so your saving the texture for each block thus the large file size. Try making a block data class which has a path to the texture. And the make a constructor for the block class which can input a data class.

Share this post


Link to post
Share on other sites
I haven't read all the posts but you should try to create your own save/load algorithm instead of serialization. It may take a while to develop depending on how many different groups/fields you have but it should save space, especially if the classes your are serializing have textures in them. For example for a tile based system you could generate something like this and save it to a file.

"t|x,y|s't|x,y|s't|x,y|s't|x,y|s"

"" = end/start of save/load
t = type of tile
x = x location
y = y location
s = solid or not
' = splitter for next set of data
etc... etc...

If the tile classes have textures saved to them, as Thekill473 says, then there is your real problem.

Share this post


Link to post
Share on other sites
[quote name='iXenocider' timestamp='1339616452' post='4948898']
[quote name='szecs' timestamp='1339615413' post='4948890']
*Um.... How about using multiple files? One file per map.
[/quote]

That would not help with anything, the total file size would be exactly the same.

[quote name='szecs' timestamp='1339615413' post='4948890']
*If there's a lot of repetition on the maps you could compress the map (for example with [url="http://zlib.net/"]zlib[/url])
[/quote]

I can try that thanks, but it takes time to compress and decompress. I don't want them to be waiting for 3 minutes just to save or load their game.
[/quote]

Combining those two will solve each others' problems, actually.

You break the massive world object down into subobjects, and compress those (or encode them in an efficient manner of your own devising, which is really the same thing.)

Your world is smaller, as everything is compressed. And since you don't have to decompress it all at once, you don't have huge lag spikes - only the portion being loaded has to be decompressed.

It has other benefits too - your RAM usage will be a lot lower, your disk reads will be a lot smaller (though, admittedly, they'll happen less predictably), and so on.

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