Jump to content
  • Advertisement
Sign in to follow this  
iXenocider

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

This topic is 2225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.

Overview
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 C#, and XNA.

Problem
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!

Extra
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.

Thank you in advance. Edited by iXenocider

Share this post


Link to post
Share on other sites
Advertisement
*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 zlib)

*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

*Um.... How about using multiple files? One file per map.


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


*If there's a lot of repetition on the maps you could compress the map (for example with zlib)


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.


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


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
serialized classes are huge. avoid them when dealing with anything that has fields other than raw types.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!