Archived

This topic is now archived and is closed to further replies.

TechnoGoth

saving and loading

Recommended Posts

When it comes to saving and loading game data, is better to read and write each variable value to the disk, or the much easier writing and reading of entire classes to the disk? I''m currently writing the characte class to the disk however there seems to be a problem with it since occasionally the save file becomes corrupted and causes the program to crash. ----------------------------------------------------- Writer, Programer, Cook, I''m a Jack of all Trades Current Design project Chaos Factor Design Document

Share this post


Link to post
Share on other sites
Look up data serializing on google. It''s a technique used by most games out there. You simply serialize different values into differently-sized blocks of data (say, 32 and 64 bytes).

Although a very clean (and simple) approach is modeling an ABC (Abstract Base Class) with nothing else than two pure virtual methods. One for saving and one for loading. Then, each class that needs to be saved and loaded implements the two methods in its own way.
These methods could write to a static RAM buffer while the program is running, then on program shutdown the data gets flushed into a file on the HDD. Then again when the program starts, the file is opened and the static RAM buffer restored, letting the classes that previously saved their states to load data and reinitialize themselves.

That is of course a very abstract idea and not a model of how things can work to the point. You''d have to figure out the middle-layers yourself.

Share this post


Link to post
Share on other sites