Jump to content
  • Advertisement

Archived

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

VisualLR

Problem saving/loading map file

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

for a while now Ive been struggling to save my maps to a file, but Ive ran into a couple of problems that I havent been able to figure out... My map file format is as follows: MAP HEADER ---------- TileSet Filename 1 TileSet Filename 2 . . ---------- MAP DATA the problem I have is with the TileSet filenames.. I can save ''em to the file, no problem, but to be able to read them from the file I needed to have the lengths of each filename, so I "solved" this by putting in an array in the map header that stores the lengths of each filename... the problem is, when I load the header, all the values in the array are 0, but everything else in the header is fine... here''s how it looks more or less: typedef struct { int Width; int Height; int Layers; int TileSets; int *Lengths; } MapHeader; (I also tried using a static array, but the same thing happened). So, when I do: MapHeader hdr; file->Read(&hdr, sizeof(MapHeader)); Width, Height, Layers, Tilesets and all those variables load correctly, but the Lengths array is all zero''d out... any ideas on what to do? (I''ve tried changing the file format several times, but if you have a suggestion on improving the file firmat I''d like to hear it as well). Thanks! Luis Sempe
visual@guate.net
http://www.spheregames.com


Share this post


Link to post
Share on other sites
Advertisement
You can't read pointers directly from file! My suggestion:


struct MapHeader
{
int Width;
int Height;
int Layers;
int TileSets;
int numOfFiles;
};

struct TileFile
{
int length;
char *name; // can't be used to read from file directly
};

void someFunction()
{
MapHeader mh;

...
file->Read (&mh, sizeof(mh));

TileFile *tf = new TileFile[mh.numOfFiles];
for (int j = 0; j < mh.numOfFiles; j++)
{
file->Read (&tf[j].length, sizeof(tf[j].length));
tf[j].name = new char[tf[j].length+1];
file->Read (tf[j].name, tf[j].length);
tf[j].name[tf[j].length] = 0;
}
...
// remember to delete[]
}


Might have some error here... you got the point?

Edited by - DerekSaw on May 19, 2000 1:42:04 AM

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!