Help loading a map text file
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
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
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.
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.
That's rather slow.
Try something like:
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);}
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
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement