dungeon_crawler
diff prototype/src/level.cc @ 50:c40efa9cf844
torches sound
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 18 Sep 2012 04:45:46 +0300 |
parents | 303743485aba |
children | d57df51f6b50 |
line diff
1.1 --- a/prototype/src/level.cc Tue Sep 18 00:34:29 2012 +0300 1.2 +++ b/prototype/src/level.cc Tue Sep 18 04:45:46 2012 +0300 1.3 @@ -73,15 +73,6 @@ 1.4 GridCell *cell = new GridCell(deftile); 1.5 *grid_row = cell; 1.6 cell_list.push_back(*grid_row); 1.7 - 1.8 - // add any audio sources in this grid-cell to the level static audio manager 1.9 - std::list<Tile::AudioSourceDesc> asrc = cell->get_audio_sources(); 1.10 - for(auto sdesc : asrc) { 1.11 - AudioSource *s = new AudioSource; 1.12 - s->set_sample(sdesc.sample); 1.13 - s->set_position(sdesc.pos + get_cell_pos(i, y)); 1.14 - austatic.add_source(s); 1.15 - } 1.16 } 1.17 grid_row++; 1.18 } 1.19 @@ -92,6 +83,30 @@ 1.20 } 1.21 fclose(fp); 1.22 1.23 + for(int i=0; i<ysz; i++) { 1.24 + for(int j=0; j<xsz; j++) { 1.25 + GridCell *cell = get_cell(j, i); 1.26 + if(!cell) { 1.27 + continue; 1.28 + } 1.29 + 1.30 + // find the adjacency mask of this cell and store it 1.31 + unsigned int adjmask = get_cell_dirmask(j, i); 1.32 + cell->set_adj_mask(adjmask); 1.33 + 1.34 + // add any audio sources in this grid-cell to the level static audio manager 1.35 + std::list<Tile::AudioSourceDesc> asrc = cell->get_audio_sources(); 1.36 + for(auto sdesc : asrc) { 1.37 + if(sdesc.dirmask & adjmask) { 1.38 + AudioSource *s = new AudioSource; 1.39 + s->set_sample(sdesc.sample); 1.40 + s->set_position(sdesc.pos + get_cell_pos(i, y)); 1.41 + austatic.add_source(s); 1.42 + } 1.43 + } 1.44 + } 1.45 + } 1.46 + 1.47 return true; 1.48 } 1.49 1.50 @@ -100,6 +115,14 @@ 1.51 return false; 1.52 } 1.53 1.54 +GridCell *Level::get_cell(int x, int y) 1.55 +{ 1.56 + if(x < 0 || x >= xsz || y < 0 || y >= ysz) { 1.57 + return 0; 1.58 + } 1.59 + return cells[y * xsz + x]; 1.60 +} 1.61 + 1.62 const GridCell *Level::get_cell(int x, int y) const 1.63 { 1.64 if(x < 0 || x >= xsz || y < 0 || y >= ysz) { 1.65 @@ -272,6 +295,18 @@ 1.66 if(tile) { 1.67 add_tile(tile); 1.68 } 1.69 + 1.70 + adjmask = TILE_ALL; 1.71 +} 1.72 + 1.73 +void GridCell::set_adj_mask(unsigned int mask) 1.74 +{ 1.75 + adjmask = mask; 1.76 +} 1.77 + 1.78 +unsigned int GridCell::get_adj_mask() const 1.79 +{ 1.80 + return adjmask; 1.81 } 1.82 1.83 void GridCell::add_tile(Tile *tile)