How to save and load a game?
How to save and load a game?
I would want to implement saving and loading features into my game but am not sure of how to go about implementing them.
I was thinking of creating a class which contains variables to contain all of the game's information like the player's position, whether enemies are dead or alive, number of hits the player has taken etc... and store them in a text file. Then the data in the file is loaded and used to initialise the game the next time it is loaded.
Is this the way to do it? Or are there better methods ?
I was thinking of creating a class which contains variables to contain all of the game's information like the player's position, whether enemies are dead or alive, number of hits the player has taken etc... and store them in a text file. Then the data in the file is loaded and used to initialise the game the next time it is loaded.
Is this the way to do it? Or are there better methods ?
I believe you can serialise the scene (check the API for the method in scenemanager) and you can save that to a file so that you can then re-create the same scene again. Of course you'd also need other data saved as well, as you mentioned, like player health, ammo, etc. Basically any data you have in the game that you'll want again will need to be saved, which could be quite a lot.
I'm not sure how particle systems would react to this.. I know if you pause the scene and then continue the particle systems mess up (or at least they used to, not sure if that's been fixed, i think i saw something about a patch to help with that, it's a pretty trivial fix i think).
I'm not sure how particle systems would react to this.. I know if you pause the scene and then continue the particle systems mess up (or at least they used to, not sure if that's been fixed, i think i saw something about a patch to help with that, it's a pretty trivial fix i think).
-
- Posts: 95
- Joined: Thu Mar 01, 2007 6:39 am
As i said, check the API:
smgr->saveScene(..)
smgr->loadScene(...)
I've never used these functions myself so i don't know anymore than what it says in the API but try those functions out and see what effect it has. As for custom scene nodes i'm not sure how it would handle those, you may have to do your own saving of those nodes and their data but that wouldn't be too hard as you'd just have to save all their important variables so they can be reloaded.
Try creating your scene, saving it and then clearing the scene and reloading it, see what stuff ends up getting saved and reloaded properly.
smgr->saveScene(..)
smgr->loadScene(...)
I've never used these functions myself so i don't know anymore than what it says in the API but try those functions out and see what effect it has. As for custom scene nodes i'm not sure how it would handle those, you may have to do your own saving of those nodes and their data but that wouldn't be too hard as you'd just have to save all their important variables so they can be reloaded.
Try creating your scene, saving it and then clearing the scene and reloading it, see what stuff ends up getting saved and reloaded properly.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
I honestly wouldn't use Irrlicht's serialisation. As JP says, you'll also have to save out a lot more information anyway.
Rather, I'd decide what's actually relevent, e.g. the position, orientation and state of the relevant actors, and general game information like progress, number of ho's pimped, and so on. Save out that and just that information, using any scheme you want. If you're writing an MMORPG (God help you) then you will probably want to use a relational DB. For most games though, you can just dump a text or binary flat file with that info. Invent some simple flags and tags to identify various sections, e.g. [PLAYER], [ENEMY], [HO'S PIMPED] etc. Personally I'd use a text file during development, to ease debugging, then switch to a binary format for release. In the binary version, you can use a much simpler scheme where you might make rigid assumptions about the order in which things appear in the file, and use simple counts to indicate how many objects of type X you're saving/loading.
When loading, read in your data, using your tag scheme to identify the appopriate sections and types of data, then create your game objects from those data, and your Irrlicht objects from your game objects.
Just saving out Irrlicht objects would only get you half way there; you'd then have to associate your game data to the relevant Irrlicht objects, and you'd also be tying yourself to Irrlicht, which (much as I like it) is a Bad Idea.
Rather, I'd decide what's actually relevent, e.g. the position, orientation and state of the relevant actors, and general game information like progress, number of ho's pimped, and so on. Save out that and just that information, using any scheme you want. If you're writing an MMORPG (God help you) then you will probably want to use a relational DB. For most games though, you can just dump a text or binary flat file with that info. Invent some simple flags and tags to identify various sections, e.g. [PLAYER], [ENEMY], [HO'S PIMPED] etc. Personally I'd use a text file during development, to ease debugging, then switch to a binary format for release. In the binary version, you can use a much simpler scheme where you might make rigid assumptions about the order in which things appear in the file, and use simple counts to indicate how many objects of type X you're saving/loading.
When loading, read in your data, using your tag scheme to identify the appopriate sections and types of data, then create your game objects from those data, and your Irrlicht objects from your game objects.
Just saving out Irrlicht objects would only get you half way there; you'd then have to associate your game data to the relevant Irrlicht objects, and you'd also be tying yourself to Irrlicht, which (much as I like it) is a Bad Idea.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 95
- Joined: Thu Mar 01, 2007 6:39 am
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
I wouldn't save a 'node' (in the sense of an Irrlicht node), I'd save out your game information, i.e. the position, orientation and state of all the actors in the game. If you get the position and orientation from the Irrlicht scene nodes that represent them, then fair enough, you'll need the other information as well. If you save out an Irrlicht scene, then you'll have to save out all the game state info as well, and then find some way of associating the two of them once you've loaded the scene again.
What I'm suggesting is that you treat Irrlicht as being a component of your game, rather than your game as being a component of Irrlicht.
I can't tell you how to save something out as XML, because I wouldn't do it as XML. I'd use good old fprintf() / fscanf(). Only you can decide what's significant enough in your game to save and load.
What I'm suggesting is that you treat Irrlicht as being a component of your game, rather than your game as being a component of Irrlicht.
I can't tell you how to save something out as XML, because I wouldn't do it as XML. I'd use good old fprintf() / fscanf(). Only you can decide what's significant enough in your game to save and load.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 95
- Joined: Thu Mar 01, 2007 6:39 am
I think there is a mySQL DevPackage you'll have to install and use for this...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
What's Irrlicht got to do with MySQL, or vice versa? You connect to a MySQL database the same way you would in any application, Irrlicht or otherwise. That's an "Other than Irrlicht" issue, or just Google for it.humbrol wrote:Umbra- How do you connect to mysql via irrlicht.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Fair enough, and good luck with it. However, as he hasn't posted anything in over 6 weeks, it might be more productive to start a new topic and describe exactly what your problems are (beyond "not working"). I'm sure someone here can help.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 60
- Joined: Tue Nov 13, 2007 7:03 pm
- Location: Bucharest - Romania
- Contact:
Another posibility is to create a ByteArray class and implement methods like WriteByte, WriteInt, WriteFloat, WriteString, etc and ReadByte, ReadInt, ReadFloat, ReadString. And then a SaveManager class who has a ByteArray prroperty and saves/loads to/from a file anything you want.
It's tricky, but also you can do this in another thread and it can be done with streaming
It's tricky, but also you can do this in another thread and it can be done with streaming