# HG changeset patch # User John Tsiombikas # Date 1347932746 -10800 # Node ID c40efa9cf8441d9bd7c1e688121aa058b13976c7 # Parent 303743485aba9fc6f99e020aaa057664e7b19249 torches sound diff -r 303743485aba -r c40efa9cf844 prototype/data/test.level --- a/prototype/data/test.level Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/data/test.level Tue Sep 18 04:45:46 2012 +0300 @@ -29,7 +29,7 @@ ################################################################ ################################################################ ################################################################ -################################################################ +################################ ############################### ################################ ############# ################# ################################################################ ################################################################ diff -r 303743485aba -r c40efa9cf844 prototype/doc/notes --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prototype/doc/notes Tue Sep 18 04:45:46 2012 +0300 @@ -0,0 +1,3 @@ +- The approach of preallocating OpenAL sources for each sound source is plainly + wrong. There's a limit to the number of OpenAL source objects, and that limit + is probably 255 on the implementation I'm using now. diff -r 303743485aba -r c40efa9cf844 prototype/src/audio/audio.cc --- a/prototype/src/audio/audio.cc Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/audio/audio.cc Tue Sep 18 04:45:46 2012 +0300 @@ -33,3 +33,23 @@ alcCloseDevice(dev); } } + +void set_audio_listener(const Matrix4x4 &xform) +{ + float pos[3], orient[6]; + + pos[0] = xform[0][3]; + pos[1] = xform[1][3]; + pos[2] = xform[2][3]; + + orient[0] = xform[0][2]; + orient[1] = xform[1][2]; + orient[2] = xform[2][2]; + + orient[3] = xform[0][1]; + orient[4] = xform[1][1]; + orient[5] = xform[2][1]; + + alListenerfv(AL_POSITION, pos); + alListenerfv(AL_ORIENTATION, orient); +} diff -r 303743485aba -r c40efa9cf844 prototype/src/audio/audio.h --- a/prototype/src/audio/audio.h Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/audio/audio.h Tue Sep 18 04:45:46 2012 +0300 @@ -1,7 +1,11 @@ #ifndef AUDIO_H_ #define AUDIO_H_ +#include "vmath/vmath.h" + bool init_audio(); void destroy_audio(); -#endif /* AUDIO_H_ */ +void set_audio_listener(const Matrix4x4 &xform); + +#endif // AUDIO_H_ diff -r 303743485aba -r c40efa9cf844 prototype/src/level.cc --- a/prototype/src/level.cc Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/level.cc Tue Sep 18 04:45:46 2012 +0300 @@ -73,15 +73,6 @@ GridCell *cell = new GridCell(deftile); *grid_row = cell; cell_list.push_back(*grid_row); - - // add any audio sources in this grid-cell to the level static audio manager - std::list asrc = cell->get_audio_sources(); - for(auto sdesc : asrc) { - AudioSource *s = new AudioSource; - s->set_sample(sdesc.sample); - s->set_position(sdesc.pos + get_cell_pos(i, y)); - austatic.add_source(s); - } } grid_row++; } @@ -92,6 +83,30 @@ } fclose(fp); + for(int i=0; iset_adj_mask(adjmask); + + // add any audio sources in this grid-cell to the level static audio manager + std::list asrc = cell->get_audio_sources(); + for(auto sdesc : asrc) { + if(sdesc.dirmask & adjmask) { + AudioSource *s = new AudioSource; + s->set_sample(sdesc.sample); + s->set_position(sdesc.pos + get_cell_pos(i, y)); + austatic.add_source(s); + } + } + } + } + return true; } @@ -100,6 +115,14 @@ return false; } +GridCell *Level::get_cell(int x, int y) +{ + if(x < 0 || x >= xsz || y < 0 || y >= ysz) { + return 0; + } + return cells[y * xsz + x]; +} + const GridCell *Level::get_cell(int x, int y) const { if(x < 0 || x >= xsz || y < 0 || y >= ysz) { @@ -272,6 +295,18 @@ if(tile) { add_tile(tile); } + + adjmask = TILE_ALL; +} + +void GridCell::set_adj_mask(unsigned int mask) +{ + adjmask = mask; +} + +unsigned int GridCell::get_adj_mask() const +{ + return adjmask; } void GridCell::add_tile(Tile *tile) diff -r 303743485aba -r c40efa9cf844 prototype/src/level.h --- a/prototype/src/level.h Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/level.h Tue Sep 18 04:45:46 2012 +0300 @@ -34,6 +34,7 @@ bool load(const char *fname); bool save(const char *fname) const; + GridCell *get_cell(int x, int y); const GridCell *get_cell(int x, int y) const; Vector3 get_cell_pos(int x, int y) const; void get_cell_coords_at(const Vector3 &pos, int *xptr, int *yptr) const; @@ -57,9 +58,14 @@ // particle systems std::vector psys; + unsigned int adjmask; + public: GridCell(Tile *tile = 0); + void set_adj_mask(unsigned int mask); + unsigned int get_adj_mask() const; + void add_tile(Tile *tile); void update(unsigned long msec, float dt); diff -r 303743485aba -r c40efa9cf844 prototype/src/main.cc --- a/prototype/src/main.cc Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/main.cc Tue Sep 18 04:45:46 2012 +0300 @@ -271,8 +271,11 @@ level->set_player_position(cam.get_position()); level->update(msec, dt); - // play the walking sound if we're walking if(cfg.sound) { + // set the listener matrix + set_audio_listener(cam.matrix()); + + // play the walking sound if we're walking int cellx, celly; level->get_cell_coords_at(cam.get_position(), &cellx, &celly); diff -r 303743485aba -r c40efa9cf844 prototype/src/tile.cc --- a/prototype/src/tile.cc Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/tile.cc Tue Sep 18 04:45:46 2012 +0300 @@ -58,7 +58,7 @@ const Tile::AudioSourceDesc &Tile::get_audio_source(int idx) const { if(idx < 0 || idx >= (int)ausrc.size()) { - static AudioSourceDesc d = { Vector3(), 0 }; + static AudioSourceDesc d = { 0, Vector3(), 0 }; return d; } return ausrc[idx]; @@ -291,7 +291,7 @@ SampleSet *sampleset = tset->get_samples(); AudioSample *sample = sampleset->get("fire.ogg"); if(sample) { - AudioSourceDesc adesc = {lt->get_position(), sample}; + AudioSourceDesc adesc = {side, lt->get_position(), sample}; ausrc.push_back(adesc); } } diff -r 303743485aba -r c40efa9cf844 prototype/src/tile.h --- a/prototype/src/tile.h Tue Sep 18 00:34:29 2012 +0300 +++ b/prototype/src/tile.h Tue Sep 18 04:45:46 2012 +0300 @@ -30,6 +30,7 @@ class Tile { public: struct AudioSourceDesc { + unsigned int dirmask; Vector3 pos; AudioSample *sample; };