dungeon_crawler

diff prototype/src/level.cc @ 23:fa8f89d06f6f

progress with light rendering
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Aug 2012 00:10:10 +0300
parents 22562582c82d
children 862461b686f4
line diff
     1.1 --- a/prototype/src/level.cc	Tue Aug 21 06:34:14 2012 +0300
     1.2 +++ b/prototype/src/level.cc	Thu Aug 23 00:10:10 2012 +0300
     1.3 @@ -99,6 +99,24 @@
     1.4  	return Vector3(posx, 0, posy);
     1.5  }
     1.6  
     1.7 +unsigned int Level::get_cell_dirmask(int x, int y) const
     1.8 +{
     1.9 +	unsigned int dmask = TILE_ALL;
    1.10 +	if(y > 0 && get_cell(x, y - 1)) {
    1.11 +		dmask &= ~TILE_NORTH;
    1.12 +	}
    1.13 +	if(y < ysz - 1 && get_cell(x, y + 1)) {
    1.14 +		dmask &= ~TILE_SOUTH;
    1.15 +	}
    1.16 +	if(x > 0 && get_cell(x - 1, y)) {
    1.17 +		dmask &= ~TILE_WEST;
    1.18 +	}
    1.19 +	if(x < xsz - 1 && get_cell(x + 1, y)) {
    1.20 +		dmask &= ~TILE_EAST;
    1.21 +	}
    1.22 +	return dmask;
    1.23 +}
    1.24 +
    1.25  void Level::draw() const
    1.26  {
    1.27  	glMatrixMode(GL_MODELVIEW);
    1.28 @@ -114,19 +132,7 @@
    1.29  				glTranslatef(pos.x, pos.y, pos.z);
    1.30  				glScalef(cell_size, cell_size, cell_size);
    1.31  
    1.32 -				unsigned int dmask = TILE_ALL;
    1.33 -				if(i > 0 && get_cell(j, i - 1)) {
    1.34 -					dmask &= ~TILE_NORTH;
    1.35 -				}
    1.36 -				if(i < ysz - 1 && get_cell(j, i + 1)) {
    1.37 -					dmask &= ~TILE_SOUTH;
    1.38 -				}
    1.39 -				if(j > 0 && get_cell(j - 1, i)) {
    1.40 -					dmask &= ~TILE_WEST;
    1.41 -				}
    1.42 -				if(j < xsz - 1 && get_cell(j + 1, i)) {
    1.43 -					dmask &= ~TILE_EAST;
    1.44 -				}
    1.45 +				unsigned int dmask = get_cell_dirmask(j, i);
    1.46  
    1.47  				cell->draw(dmask);
    1.48  				glPopMatrix();
    1.49 @@ -135,6 +141,29 @@
    1.50  	}
    1.51  }
    1.52  
    1.53 +void Level::draw_lights() const
    1.54 +{
    1.55 +	glMatrixMode(GL_MODELVIEW);
    1.56 +
    1.57 +	for(int i=0; i<ysz; i++) {
    1.58 +		for(int j=0; j<xsz; j++) {
    1.59 +			const GridCell *cell = get_cell(j, i);
    1.60 +			if(cell) {
    1.61 +				Vector3 pos = get_cell_pos(j, i);
    1.62 +
    1.63 +				glPushMatrix();
    1.64 +				glTranslatef(pos.x, pos.y, pos.z);
    1.65 +				glScalef(cell_size, cell_size, cell_size);
    1.66 +
    1.67 +				unsigned int dmask = get_cell_dirmask(j, i);
    1.68 +				cell->draw_lights(dmask);
    1.69 +
    1.70 +				glPopMatrix();
    1.71 +			}
    1.72 +		}
    1.73 +	}
    1.74 +}
    1.75 +
    1.76  void Level::draw_grid() const
    1.77  {
    1.78  	float xlen = xsz * cell_size;
    1.79 @@ -179,7 +208,14 @@
    1.80  
    1.81  void GridCell::draw(unsigned int draw_mask) const
    1.82  {
    1.83 -	for(size_t i=0; i<tiles.size(); i++) {
    1.84 -		tiles[i]->draw(draw_mask);
    1.85 +	for(auto tile : tiles) {
    1.86 +		tile->draw(draw_mask);
    1.87  	}
    1.88  }
    1.89 +
    1.90 +void GridCell::draw_lights(unsigned int draw_mask) const
    1.91 +{
    1.92 +	for(auto tile : tiles) {
    1.93 +		tile->draw_lights(draw_mask);
    1.94 +	}
    1.95 +}