Topic: Save and load system

Hi,
I'm a new user of this engine. I'm testing it only for a few days, and looks great. I like it so far:) I wonder however, how to make a save and load game system. Is there some script or something like that? I completely don't have idea how to do it.

Re: Save and load system

Hi there!
Great to have another new user smile

There's no save/load system in the engine right now. However, (as with everything else, it seems) it's something I've got on my todo list, and I've been working on a solution. I've not integrated it with Maratis itself yet, so it would have to be added as part of a game plugin at this point

Re: Save and load system

Thanks for the reply.

Re: Save and load system

Just let me know how urgent this is and what degree of integration you'd like and I'll see what I can do smile

By the way, my solution is currently that there will be a config file system with semi-DOM-esque accessing, and then a semi-singleton config file that can be used similarly to Unity's PlayerPrefs. The basic usage from code would be:

void SomeClass::save(std::string root)
{
    std::string key = root + "Something.";
    MSaveData::write(key + "SomeVal", &someVal);
}
void SomeClass::load(std::string root)
{
    std::string key = root + "Something.";
    MSaveData::keyExists(key + "SomeVal", &someVal);
}

I haven't decided how I can do save/load stuff in script, but I guess it would be something similar. Thoughts?

Also, so far, I've only got it reading and writing binary files (I can put the spec here if required). I was intending to add some form of human readable format to it too, I'm not sure what to use, the choices seem to be xml, yaml, json or a home rolled format. Any preferences?

Re: Save and load system

It's not too urgent at the moment, therefore, you don't need to rush:) I just thought, that the save/load system is necessary in the game that I'm planning to make.  But first, however, I need to learn some more things before I'll start to do something bigger:) I think, that would be good to add both quick save/load system during the game (F5/F9 for example) and also possibility to create these functions in main menu.

Re: Save and load system

Save/Load is very specific to each game. A quicksave (or, any save-) system would have to be implemented in the game. There's no real way to be able to save in a generic way, unless you wanted to save the entire world. This would be incredibly slow and guaranteed to miss custom object states. and such.

One issue with a quicksave system, compared with a standard menu save system is that Maratis currently doesn't have any threading code in it, it wouldn't be too hard to add a reasonable cross platform solution... but...

The issue with saving, is that writing to a central place (the MSaveData for example) is pretty quick, and can be done on the fly, however writing to file is slow, If you really wanted a quicksave system, hitting quicksave would cause the game to freeze for a short amount of time while it writes the savedata to disk. Ideally what you do is write to savedata on the fly, then kick off a separate thread to write to disk. This does mean a reasonable amount of work to make sure things can be made (reasonably) threadsafe.

Re: Save and load system

It was pointed out that my reply may not have been entirely clear. I'm sorry about that.

Usually, there are two steps to a save system, collecting the data to save, and then writing to file. The collecting shouldn't take too long (depends, of course how much data you have to save, but this should be fairly minimal) Writing to file, however takes considerably longer.

For a standard menu-based load/save system you could do both of these one after the other and would hardly notice... I mean, it takes a while to save, so what? However, for a quicksave system, one thing you do not want is for the game to pause for a second or two when you hit save. To achieve this, the best way would be to collect the data as normal, when you press F5 or whatever your chosen key is, which should go fairly un-noticed, then start a background thread to write the savedata to file. As it's not in the main game loop, it shouldn't affect the normal gameplay and everything should happen smoothly.

There's a lot of 'should's there. One issue is that, when working with threads, you don't have two threads changing the same data, which could lead to crazy stuff happening, or threads waiting for other threads to release data, which would lead to locks, causing more freezes than the initial problem.

Anyway. for this reason, quicksave is a little more complicated than a standard save system.

And, while I remember, I should mention loading. There are currently no loading screens (this, again, would probably need a background thread...) so you would get a significant pause when "quickloading" which might not be ideal, although if you showed a prompt, I guess it would be better. The main issue with loading is clearing the "world" and resetting it to the exact state you want it in before.