Load/Save system

Posted By: ratz

Load/Save system - 11/23/15 14:09

You want Save and Load your GameState ?

Code:
function load_me()
{
 game_load("test.sav",0);  
}

function save_me()
{
 game_save("test.sav",0,SV_ALL-SV_INFO-SV_STRINGS-SV_BMAPS-SV_PANELS);
}



i hope this helps
Posted By: Anonymous

Re: Load/Save system - 11/23/15 16:29

@ratz that's not a function, it's just a single manual command. It doesn't add functionality at all.

Is this meant as a joke or a mock , perhaps?

Mal
Posted By: EpsiloN

Re: Load/Save system - 11/24/15 07:43

A much better contribution would be a manual save/load system. I made one for my game, but its not suitable for a contribution, because it is messy and defined for my game only...
Posted By: Florastamine

Re: Load/Save system - 11/24/15 08:25

To be honest, I wouldn't rely on the built-in game_save() and game_load(). I remembered some time ago when I was still working with A7 when I made a fairly large game with lots of structs and variables, but had to scrap that game simply because game_load() just crashes the whole engine whenever loading a saved game (the saving/loading stuff was vital - the game was actually a world editor), and I couldn't implement custom saving/loading routines, because of deadline, and because it's a tedious task. So for my current game I wrote a custom module for that, where variables (player pos, ang, weapon id, bullets, game state,... everything) are grouped into structs and instanced as singletons, and whenever I need to save the game, just serialize everything from the singleton to an archive struct, and from the archive struct to the disk, and apply a simple encryption layer over it. Everything else (levels, skycubes...) are easy, just level_load() and ent_createlayer(). And when loading is needed, the save games' data are de-serialized back from disk to the archive, and from the archive I simply fetch the data I want and pass it back to the singleton.
Posted By: EpsiloN

Re: Load/Save system - 11/24/15 10:14

Well, its getting off-topic, but here's how my save/load system worked:
Every object in the game had a type (not an ID!, a type) and based on that type the game knew what it does and how...

With that information, I run through all the existing objects and write to a file in the form "model name, object type, position, orientation, 5 general purpose parameters(which depend on the object type)"

When I want to load, I run a function that reads in term the model, type, pos, etc. and ent_creates it and sets the parameters...

Guess what? laugh Level with 200 objects becomes kbytes... I think it was around 15kb.
Loads fast enough, saves fast enough and it can be modified by hand in Notepad, because it looks good (its not encoded or anything).

Downside - its specific to my game's level system and not very backwards-compatable. If I modify a future version, ex. add a parameter, the old versions wont work with it.
But even if I add a new object in the game, it will work for any model and type... If the type is not found, a static general object is assumed...

I needed a lot of time to develop this system, but simply because I was young and inexperienced. If I had to do it now, I'd make it more generalized, using function pointers and other things, to make it reusable. Also, save/load the number of parameters and achieve backwards compatibility...
Posted By: sivan

Re: Load/Save system - 11/24/15 13:36

EpsiloN described exactly how I solved save/load in MapBuilder laugh
simple but works. I kept a small amount of parameters as reserves for future additions that worked in most cases, other times it is good to add a version ID then you can make branches... by the way, in my editor I preferred text files to easily debug them, but for a game a binary stuff is probably better/safer/faster...
Posted By: Florastamine

Re: Load/Save system - 11/24/15 14:05

Originally Posted By: sivan
by the way, in my editor I preferred text files to easily debug them, but for a game a binary stuff is probably better/safer/faster...


Actually in my game I defined a macro switch (ENABLE_ENCRYPTION) that is turned on in published builds, so files can be written out encrypted. In development builds, this macro is commented out so nothing gets encrypted (for easier viewing/modifying).
Posted By: EpsiloN

Re: Load/Save system - 11/24/15 14:30

I meant I don't use encryption, because I intended maximum mod-ability. If you want custom models for all objects, just create a mdl file and edit the level in Notepad... laugh

But, if I wasn't aiming for this, I would have definitely used some encryption or something to obscure the original definitions... Hackers are everywhere grin

Originally Posted By: sivan
I kept a small amount of parameters as reserves for future additions that worked in most cases, other times it is good to add a version ID then you can make branches...

And I thought about all this after I finished the whole game grin
My best solution so far is to add a definition at the start of the file that tells how long an object definition is (how many parameters except the defaults(model,pos,angle)) and if you want to save space, you could add this "parameters" definition for each object separately, so that you can minimize the parameters for objects that don't have that many...
© 2024 lite-C Forums