Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2047
Number of posts: 5331

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Saving a game... problems and more problems :( Posted by mwronski on 3 Nov 2004 at 11:59 AM
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?
Report
Re: Saving a game... problems and more problems :( Posted by gautam on 6 Nov 2004 at 1:02 AM
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?
:
Report
Re: Saving a game... problems and more problems :( Posted by mwronski on 6 Nov 2004 at 11:18 AM
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...



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.