Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

Help loading a map text file

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

I am trying to figure out the best way to load my map info from a text file. I tryed just looking for a string in the text and startloading the data after that tell it hit anothere string to stop the load. That did not work all I could get to work was one char. I could make it in seprate files but that would bad file managment. Does any one have ideas how I can store all level data in one text file and load it in my game? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Becasue I dont know how. And becasue right Now I dont have a map editor so I have to put everything in manuely. So I dont know if I can do that with a bin file

Share this post


Link to post
Share on other sites
well right now I am just trying to read the text from the file then load it into and array.

std::ifstream MapFile(".\\level1.txt");

for (int layer = 0; layer < 3; layer++)
{
for(int row = 0; row < Mapy; row++)
{
for(int column = 0; column < Mapx; column++)
{
MapFile >>map[layer][row][column];

}
}
}


But I am guessing that I would just do it backwards to put it into the text.

But the problem is that it loads all the text into the raid and I just want to read to a point.

Share this post


Link to post
Share on other sites
That's rather slow.
Try something like:

void save_structures_list()
{
FILE *f = NULL;
f=fopen("whatever_map_file","wb");
if(!f)return;//blah, whatever
fwrite(&map,1,map_size,f);
fclose(f);
}

Share this post


Link to post
Share on other sites
Could you explain what each line does?

this is what I think it does

FILE *f = NULL;
f=fopen("whatever_map_file","wb");
//loads a text file not sure what "wb"is for


if(!f)return;//blah, whatever
//retrun error if could not open

fwrite(&map,1,map_size,f);
//this rites to the file but not sure exactley what is going on
fclose(f);
//clode the file

Thanks for the help

Share this post


Link to post
Share on other sites
wb means "write binnary"
So we open the file with the intention to write binary data.

fwrite(&map,1,map_size,f);
writes from the address map (assuming map is an array) 1 is the size of a tile (assuming it's 1 byte/tile) and map_size is how many tiles you have in the map.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!