Mkay,
Im reading in my map from a text file, (working on a simple 3d game using OpenGL, looks similar to Wolfenstein at this point), I'm having problems, reading in the Ceiling height, for some reason, thats the only thing giving me trouble.
Code that reads in the Map,
/* Grab Tesla Map data */
bool c_Map::grab_tmf()
{
string temp;
//Open up Texture List file
ifstream tmf_file(tmf_loc.c_str());
//if file isn't open, return false
if(!tmf_file.is_open()) { return false; }
//Temporary
top:
//Get Width and Length of Map
getline( tmf_file, temp);
if( temp == "" ) { goto top; } //Make sure to skip blank space
sscanf(temp.c_str(), "%d %d", &data.width, &data.length); //Grab width and height of the map (represented 2d grid)
data.n_cell = data.width * data.length; //Grab how many sectors there are
//Run through all of the sectors
for(int y = 0; y < data.length; ++y) {
for(int x = 0; x < data.width; ++x) {
//Reset label if there is a space (temporary
reset:
//Get Cell type
getline( tmf_file, temp);
if( temp == "" ) { goto reset; } //Make sure to skip blank space
//ignor_char = temp.find('#'); //Grab ignorage char
//if(ignor_char == string::npos) { goto reset; } //Skip lines with Ignorage char
//sector height
sscanf(temp.c_str(), "%d", &data.cell[x][y].type);
/* PROBLEM STEMS FROM HERE
//Grab floor/ceiling height
getline( tmf_file, temp);
sscanf(temp.c_str(), "%d %d", &data.cell[x][y].f_height, &data.cell[x][y].c_height);
//Grab Wall Texture references
getline( tmf_file, temp);
sscanf(temp.c_str(), "%d %d %d %d", &data.cell[x][y].w_tex[0], &data.cell[x][y].w_tex[1],
&data.cell[x][y].w_tex[2], &data.cell[x][y].w_tex[3]);
//Grab floor/ceiling texture references
getline( tmf_file, temp);
sscanf(temp.c_str(), "%d %d", &data.cell[x][y].f_tex, &data.cell[x][y].c_tex);
//Set player position
if(data.cell[x][y].type == S_PLAYERSPAWN)
{
//get player spawn point
set_playerPosition(-x*CELL_SIZE, data.cell[x][y].f_height-1.0f, -y*CELL_SIZE);
//set player at spawn point
player.set_position(data.player_pos);
}
cout << data.cell[x][y].f_height << ", " << data.cell[x][y].c_height << endl;
}}//nested for loop
tmf_file.close();
return true;
}//EoF
;
or more specifically,
;
//Grab floor/ceiling height
getline( tmf_file, temp);
sscanf(temp.c_str(), "%d %d", &data.cell[x][y].f_height, &data.cell[x][y].c_height);
Map file looks like this,
8 4
1
0 2
1 1 1 1
3 4
1
0 2
1 1 1 1
3 4
1
0 2
1 1 1 1
3 4
1
0 2
1 1 1 1
3 4
1
0 2
1 1 1 1
3 4
...etc.
Its read in a 2d array,
the first 2 numbers is the width/height in tiles (or cells) of the map,
the rest are just the Cell definition.
1 //what kind of tile it is (Wall, or openspace)
0 2 //Floor and Ceiling Height, seems to be some problem here
1 1 1 1 //the Wall texture index from the maps' texture list (another file)
3 4 //Floor Ceiling texture index
When i debug my game, when it gets to reading in the floor/ceiling heights, it reads the floor correctly, but the ceiling height ends up being "2.803e-045#DEN"
Every time.
Any idea what I'm doing wrong?
(besides my questionable map design)