Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Saving a game... problems and more problems :(

I have recently made a game in OpenGL. I want to program a Quicksave and Quickload feature. The problem is this: My game consists of classes and the main class contains a cyclic linked list of the world environment and enemies. I have no clue on how to write this info to a data file.
eg:

class CWorld
{
CEntity *worldObjs; // cyclic linked list
//...
};

I attach nodes to the base CEntity class through my linked list. Unfortunately the command:
fwrite(world, sizeof(CWorld),1, fp);
does not work when I try to load it:
fread(world, sizeof(CWorld),1, fp);

Must I loop through each object of the linked list and save each one individally? This is tedious and I think there must be a better way. Besides, each object has its own pointers etc. which means I may have to loop through each pointer of each object in the list; I do NOT want to resort to this. Plz help?

Comments

  • gautamgautam Posts: 642Member
    Well I dont think there are much options here. Now there is no way to load data unless you have it in the file. This may not be the best way but you need to really figure out a file format you want to save info in. For eg :- while saving you dont want the static objects anyway. Basically you want the enemies/NPC/movable objects- positions,life, health and other info. Then you need a player info - like his health, ammo, weapons, inventory items currently. So you could have a different file format and have a vector of enemies curretly in the world with their attributes, player attributes, the world ID. You will have to constantly be updating all this info. For eg:- if a new enemy has been spawned, increase a ref counter, update this info. And once the player wants to do quicksave you just save all this info.

    Hope this helps;

    : I have recently made a game in OpenGL. I want to program a Quicksave and Quickload feature. The problem is this: My game consists of classes and the main class contains a cyclic linked list of the world environment and enemies. I have no clue on how to write this info to a data file.
    : eg:
    :
    : class CWorld
    : {
    : CEntity *worldObjs; // cyclic linked list
    : //...
    : };
    :
    : I attach nodes to the base CEntity class through my linked list. Unfortunately the command:
    : fwrite(world, sizeof(CWorld),1, fp);
    : does not work when I try to load it:
    : fread(world, sizeof(CWorld),1, fp);
    :
    : Must I loop through each object of the linked list and save each one individally? This is tedious and I think there must be a better way. Besides, each object has its own pointers etc. which means I may have to loop through each pointer of each object in the list; I do NOT want to resort to this. Plz help?
    :
  • mwronskimwronski Posts: 62Member
    Well I guess that may be the best option but it is extremely unflexable. I mean, if I add a new variable in the game I must constantly update it into the SaveGame function as well. I wish I could just save everything and not worry about it again...
Sign In or Register to comment.