Jump to content
  • Advertisement


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


Levels & disk files

This topic is 6879 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


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:

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?


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!