I use text files with the following format.
Code:
width of map
height of map
number of layers
tiles arranged by IDs as how they would appear in the map
For example, one of my map files looks like this.
Code:
14
10
1
1 1 1 1 1 1 1 1 1 1 2 2 2 2
1 0 0 0 0 0 0 0 0 1 2 2 2 2
1 0 0 0 0 0 0 0 0 1 2 2 2 2
1 0 0 0 0 0 0 0 0 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1 2 2 2 2
1 0 0 0 0 0 0 0 0 1 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2
You might think it's hard to parse such information, but it's incredibly easy if you're using C++ stream classes. Just use cin and the >> operator. It's also very easy to check if there's a parsing error, just use the ! operator.
So reading the first 3 lines is trivial:
Code:
std::ifstream file( filename );
if( file.is_open() == false )
return false;
unsigned int width, height, depth;
if( !(file >> width ) ) return false;
if( !(file >> height) ) return false;
if( !(file >> depth ) ) return false;
Now that you know the width, height and depth of the map, reading the tile IDs is also simple:
Code:
for( unsigned int z=0; z<depth; ++z )
for( unsigned int y=0; y<height; ++y )
for( unsigned int x=0; x<width; ++x )
if( !(file >> temp[x][y][z].id) )
return false;
I prefer text files to binary files because it's human-readable, and you don't have to program a fancy tile editor. If you have Notepad, you can edit the tile values easily.
Hope that helps.