Slashdot Mirror


Object-Oriented 'Save Game' Techniques?

GreyArtist asks: "I took a course in C++ a year ago in which the instructor claimed that global (file-scope or inter-file-scope) variables were antiquated and not to be used under any circumstances. I immediately thought of a counter argument that involved the method I use for saving game data. The games (and many of the other programs) I write use not only global variables, but consecutive global variables declared in their own separate module. To save the game (or user settings) to file, I simply save a single large segment of data that contains all the necessary information. How do other coders do it? Would they create a 'MyObject.savemyself()' method for every object in their game? Do they save all the game code along with the data? Either way, it seems like a horrid case of code (or data) bloat. What do you die-hard object-oriented fanatics have to say about this, and what method they would you use for saving games?"

6 of 229 comments (clear)

  1. Single instance by Bluelive · · Score: 5, Insightful

    This only makes sense if you have a single instance. (ie. Singleton) class. Sounds like your a C user lost in OO land

  2. Re:easy by AndroidCat · · Score: 3, Insightful
    Dear Miss Manners:
    My home economics teacher says that one must never place one's elbows on the table. However, I have read that one elbow, in between courses, is all right. Which is correct?

    Gentle Reader:
    For the purpose of answering examinations in your home economics class, your teacher is correct. Catching on to this principle of education may be of even greater importance to you now than learning correct current table manners, vital as Miss Manners believes that is.

    There are rules, written or not, and they have no pity.
    --
    One line blog. I hear that they're called Twitters now.
  3. Configuration Object by sporty · · Score: 3, Insightful

    Just use a configuration object. I would argue NOT to use a singleton. Come the day you need to migrate away from the singleton pattern, you will have a bit of work. Why migrate away? What if you wished to work with two configuration files at once? I know, it's not normal for all applications, but I've had an instance where one was the old config and one was the new. Short version, config object, no singleton.

    -s

    --

    -
    ping -f 255.255.255.255 # if only

  4. Are you serious? by ttsalo · · Score: 4, Insightful

    You save settings/games by essentially dumping data straight from memory to disk? How large projects have you implmented this way? How do you figure out the right parts to write/read? How you ensure that the program memory (data segment, stack and heap) will all be in a consistent state after a load?

    --
    If the road to hell is paved with good intentions, where does the road paved with evil intentions lead to?
  5. Antiquated by gregRowe · · Score: 3, Insightful

    The second you hear that word in the context of writing software stop listening to the person who spoke it. Just because a technique is old does not make it inferior.

    --
    There\'s no place like ~
  6. Re:whatever works for you by arkanes · · Score: 3, Insightful

    This is the largest load of crap I've heard in a long time, especially directed to someone who's a student. The whole point of being a student is that you learn something, not that you just do whatever until you run into all the problems. Sure, what he has works. But he wants to know if there's a better way. He's been introduced to something that he doesn't understand, and doesn't see how it can make his programs better. So he's asking for some examples. This makes him an intelligent person (unless he's just got an axe to grind against OO and is trying to troll, but I'm assuming good faith and even if he is, this is a lousy example to pick), as opposed to being a reactionary turd who'll refuse to better himself.