Thread: creating a game save (how do i do it?)

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    creating a game save (how do i do it?)

    I've been working on this nifty little game with my buddy allegro, and I've come to the point wherein I need to save some data. All I know about this is that I imagine it entails writing the necessary variables to a .txt file or something. I can't seem to find any syntax on that, can someone point me in the right direction?
    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It's the same as any other file save/load thing.

    Did you ever do the phonebook exercise homework? Well that's pretty much it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Allways learning cs_student's Avatar
    Join Date
    Aug 2008
    Location
    ~/
    Posts
    39
    This is for SDL but it still might help you.
    Game Saves

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    All you need to do is save enough data so that you can properly reconstruct the game world back to the way it was at the save point.

    I would highly recommend you make your class objects streamable as this will greatly facilitate your efforts. However you can just create a save function that will write out the pertinent data.

    Since you cannot write pointers (you can but itis ugly during reconstruction) and/or variable length strings easily you will have to account for these. What I normally do is write enough data so that I know what type of object im working with and enough state data to re-create it just as it was during the save.

    I would not attempt to write out a load function that messed with pointers and offsets from class base addresses b/c you can gain the same functionality by being smart with your data.

    A simple interface might be:

    Code:
    class ISerializeable
    {
       virtual ~ISerializable() { }
       virtual void LoadFromFile(std::string filename) = 0;
       virtual void LoadFromOffset(unsigned __int64 fileoffset) = 0;
       virtual void SaveToFile(std::string filename) = 0;
       virtual void SaveAtOffset(unsigned __int64 fileoffset) = 0;
    };
    
    class IGameObject
    {
    ...
    ...
    };
    
    class GameObject:public IGameObject, public ISerializable
    {
       public:
         virtual void LoadFromFile(std::string filename);
         virtual void LoadFromOffset(unsigned __int64 fileoffset);
         virtual void SaveToFile(std::string filename);
         virtual void SaveAtOffset(unsigned __int64 fileoffset);
    };
    Your GameObject class then would implement the functions provided by the ISerializable interface.

    You would then be able to iterate your list of game objects and call the appropriate Save/Load function for each. This should create the game world correctly.
    Last edited by VirtualAce; 08-02-2008 at 02:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Save vs Save As.... OPENFILENAME flags
    By csonx_p in forum Windows Programming
    Replies: 16
    Last Post: 06-01-2008, 02:42 PM
  2. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  3. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  4. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  5. Someone help me with this game??
    By stehigs321 in forum Game Programming
    Replies: 15
    Last Post: 10-30-2003, 09:42 PM

Tags for this Thread