Archived

This topic is now archived and is closed to further replies.

Levels & disk files

This topic is 6568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If you put your pointers in a structure like that, they'll only be written as pointers. When you re-load the game, what they point to is likely not going to be there anymore. If you already have counters for the number of items in those arrays, you can just leave the pointers as they are and save your tile/enemy data after you save this structure (since you know the number, just write that much data to the file). When you reload, read in your level structure, reallocate the pointers based on the number of tiles/enemies you need, then copy the data back into that memory from the file. If your tile/enemy pointers point to linear arrays, you can just use fread/fwrite to do all the data transfer.

Good luck

Starfall

Share this post


Link to post
Share on other sites
I am making a level editor and level file format for my game, and I had a few questions about saving the structures to disk. Since one file is going to hold multiple levels, I thought it would make it easier to have a structure sort of like this for one level:
code:

struct Level
{
char levelNum, tileSet;
int length, numEnemies, numPowerups;
Tile* tiles;
Enemy* enemies;
Powerup* powerups;
}


Of course, the pointers would be allocated as arrays when the level file is read in, using the length, numEnemies, and numPowerups variables. Would this still save to file correctly if I just wrote a Level object to file, or would I have to cycle through all the members? Also, for the enemies and stuff during the game, would it be better (faster) to use dynamically allocated arrays, or linked lists?

------------------
http://qoy.tripod.com

Share this post


Link to post
Share on other sites