Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SQL save game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Senith89   Members   -  Reputation: 103

Like
0Likes
Like

Posted 29 March 2013 - 09:28 AM

Hi all,

 

I am currently using a sqlite database file that I load up, access and modify during the process of the game running, which I realize is just not going to work for me overall. I've currently got to the point where I'm doing modifications to the database that's just not going to allow me to refresh this for a new-game, or really support the idea of being able to change the in-game database for updates etc, whilst still allowing the saved games to not be destoryed. wacko.png

 

The idea I've thought of to get around this issue is to still load the database up from a file, but instead to copy the contents of this (or attach? I'm not sure) into an "in-memory" database which the game will use during execution. Then, when I need to save the game, I was thinking of doing a comparion between the in-memory database and the stored one on-disk, fashioning a shiny new "saved game" database which just stores the changes between the two. In this way, upon loading up a saved game, it would load up the "template" database from the disk as normal (into the "in-memory" database) and then basically "patch-in" the changes from the saved game into this too.

 

My question though, is what would be the easiest/best way to actually detect the differences between two databases like this so that I am able to create a save-file with only the changes? (and be able to load it again in the same way).

 

Just to note: I'm not the world's greatest expert with SQL, so please be patient in explaining anything etc. Also, I'm completely willing to any suggestions if you think I've gone crazy and this just isn't possible or a good idea to begin with!

 

Thanks in advance for any support on this! smile.png


Edited by Senith89, 29 March 2013 - 09:31 AM.


Sponsor:

#2 HappyCoder   Members   -  Reputation: 2846

Like
0Likes
Like

Posted 29 March 2013 - 11:16 AM

My recommendation is to do what is the easiest. That save file comparison seems complicated and would likely be buggy. Is there any reason you are using SQL?

What has worked really well for me in doing save files is JSON. It will let you expand your save files between updates with no problem and you can simply use a separate file per save game. When saving the game you simply rebuild the entire file from the game state rather then trying to determine what is different. Doing a complete rebuild may sound inefficient but it should be fast enough for any reasonably sized game.

There are libraries for JSON in almost any language.

If you are set on SQL, or it is too entrenched in your project for you to want to scrape it out then I would recommend adding a column in each table. The column would be an integer specifying the save file id. Then you could read and modify the tables with that added parameter to only effect the save file of interest. And you in memory database is a good suggestion.

Another thing you could do is have a database checker that runs when you game starts. What you would do there is have the checker determine what format the tables are in. If they are outdated then have it convert the database format. That way once your game has be started it can assume the database is in the correct format.

#3 Josh Vega   Crossbones+   -  Reputation: 1203

Like
0Likes
Like

Posted 29 March 2013 - 11:56 PM

I understand where you are going with your question, but I think its a bit over-done. Unless your are developing a Civilization like strategy game or a game with thousands of automatic entities, its just not going to be efficient. In general, save games should only be called when loading or saving games. Once the data from the save game file is copied to the "standard" game memory, the save game file is closed. During saving, if you want to overwrite an existing save game, you simply clear the contents of the save game file and copy all the data from memory to the file.

 

What I just described above is essentially what you described and has been used to years. In your design though you talk about using a template database and "patch" database. Its a good concept, but having to load two files and copy data twice is going to take much long compared to a single file.

 

I recommend you re-think your save game concept. Your idea isn't bad, its just that SQL is designed for large datasets, not small game saves. Possible replacements that are easily integratable are JSON (as mentioned by HappyCoder) and XML. My prefered method is using XML but compressing and encoding it with a passphrase in binary. With my current system, I'm able to load 1000 separate game entities (equal to approx 500KB) into a structure in memory in about 10-15 seconds or so.


Edited by Josh Vega, 30 March 2013 - 12:05 AM.

Some favourite quotes:
Spoiler

#4 ApochPiQ   Moderators   -  Reputation: 16080

Like
0Likes
Like

Posted 31 March 2013 - 02:46 PM

SQL is the wrong tool for savegame data. You want a state dump, not a relational database. Don't try to shoehorn state data into a relational model, it's pointless.

 

Just write a gamestate serialization system like everyone else ;-)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS