dungeon_crawler

changeset 51:d57df51f6b50

- fixed audio panning (listener direction) - particles had no fog - sound sources were not destroyed properly
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 18 Sep 2012 09:40:56 +0300
parents c40efa9cf844
children bcdea26c8f27
files prototype/src/audio/audio.cc prototype/src/audio/auman.cc prototype/src/audio/source.cc prototype/src/audio/source.h prototype/src/level.cc prototype/src/main.cc prototype/src/renderer.cc prototype/src/tile.cc prototype/src/tile.h
diffstat 9 files changed, 54 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/prototype/src/audio/audio.cc	Tue Sep 18 04:45:46 2012 +0300
     1.2 +++ b/prototype/src/audio/audio.cc	Tue Sep 18 09:40:56 2012 +0300
     1.3 @@ -44,7 +44,7 @@
     1.4  
     1.5  	orient[0] = xform[0][2];
     1.6  	orient[1] = xform[1][2];
     1.7 -	orient[2] = xform[2][2];
     1.8 +	orient[2] = -xform[2][2];
     1.9  
    1.10  	orient[3] = xform[0][1];
    1.11  	orient[4] = xform[1][1];
     2.1 --- a/prototype/src/audio/auman.cc	Tue Sep 18 04:45:46 2012 +0300
     2.2 +++ b/prototype/src/audio/auman.cc	Tue Sep 18 09:40:56 2012 +0300
     2.3 @@ -8,6 +8,7 @@
     2.4  		fprintf(stderr, "failed to create kd tree\n");
     2.5  		throw std::bad_alloc();
     2.6  	}
     2.7 +	kd_data_destructor(sources, [](void *s) { delete (AudioSource*)s; });
     2.8  }
     2.9  
    2.10  AudioManager::~AudioManager()
    2.11 @@ -17,12 +18,12 @@
    2.12  
    2.13  void AudioManager::clear()
    2.14  {
    2.15 -	kd_clear(sources);
    2.16 -
    2.17  	for(auto s : active_set) {
    2.18  		s->stop();
    2.19  	}
    2.20  	active_set.clear();
    2.21 +
    2.22 +	kd_clear(sources);
    2.23  }
    2.24  
    2.25  void AudioManager::add_source(AudioSource *s)
     3.1 --- a/prototype/src/audio/source.cc	Tue Sep 18 04:45:46 2012 +0300
     3.2 +++ b/prototype/src/audio/source.cc	Tue Sep 18 09:40:56 2012 +0300
     3.3 @@ -51,6 +51,30 @@
     3.4  	return Vector3(pos[0], pos[1], pos[2]);
     3.5  }
     3.6  
     3.7 +void AudioSource::set_volume(float vol)
     3.8 +{
     3.9 +	alSourcef(alsrc, AL_GAIN, vol);
    3.10 +}
    3.11 +
    3.12 +float AudioSource::get_volume() const
    3.13 +{
    3.14 +	float vol;
    3.15 +	alGetSourcef(alsrc, AL_GAIN, &vol);
    3.16 +	return vol;
    3.17 +}
    3.18 +
    3.19 +void AudioSource::set_reference_dist(float rdist)
    3.20 +{
    3.21 +	alSourcef(alsrc, AL_REFERENCE_DISTANCE, rdist);
    3.22 +}
    3.23 +
    3.24 +float AudioSource::get_reference_dist() const
    3.25 +{
    3.26 +	float res;
    3.27 +	alGetSourcef(alsrc, AL_REFERENCE_DISTANCE, &res);
    3.28 +	return res;
    3.29 +}
    3.30 +
    3.31  bool AudioSource::is_playing() const
    3.32  {
    3.33  	int state;
     4.1 --- a/prototype/src/audio/source.h	Tue Sep 18 04:45:46 2012 +0300
     4.2 +++ b/prototype/src/audio/source.h	Tue Sep 18 09:40:56 2012 +0300
     4.3 @@ -19,6 +19,12 @@
     4.4  	void set_position(const Vector3 &pos, bool viewspace = false);
     4.5  	Vector3 get_position() const;
     4.6  
     4.7 +	void set_volume(float vol);
     4.8 +	float get_volume() const;
     4.9 +
    4.10 +	void set_reference_dist(float rdist);
    4.11 +	float get_reference_dist() const;
    4.12 +
    4.13  	bool is_playing() const;
    4.14  	void play();
    4.15  	void stop();
     5.1 --- a/prototype/src/level.cc	Tue Sep 18 04:45:46 2012 +0300
     5.2 +++ b/prototype/src/level.cc	Tue Sep 18 09:40:56 2012 +0300
     5.3 @@ -98,9 +98,14 @@
     5.4  			std::list<Tile::AudioSourceDesc> asrc = cell->get_audio_sources();
     5.5  			for(auto sdesc : asrc) {
     5.6  				if(sdesc.dirmask & adjmask) {
     5.7 +					Vector3 pos = sdesc.pos + get_cell_pos(j, i);
     5.8 +
     5.9  					AudioSource *s = new AudioSource;
    5.10  					s->set_sample(sdesc.sample);
    5.11 -					s->set_position(sdesc.pos + get_cell_pos(i, y));
    5.12 +					s->set_position(pos);
    5.13 +					s->set_volume(sdesc.volume);
    5.14 +					s->set_reference_dist(sdesc.ref_dist);
    5.15 +					//s->set_rolloff(1.0);
    5.16  					austatic.add_source(s);
    5.17  				}
    5.18  			}
     6.1 --- a/prototype/src/main.cc	Tue Sep 18 04:45:46 2012 +0300
     6.2 +++ b/prototype/src/main.cc	Tue Sep 18 09:40:56 2012 +0300
     6.3 @@ -143,16 +143,16 @@
     6.4  
     6.5  void cleanup()
     6.6  {
     6.7 -	if(cfg.sound) {
     6.8 -		delete move_sound;
     6.9 -		destroy_audio();
    6.10 -	}
    6.11 -
    6.12  	delete level;
    6.13  	delete tileset;
    6.14  	delete rend;
    6.15  
    6.16  	cleanup_cmdcon();
    6.17 +
    6.18 +	if(cfg.sound) {
    6.19 +		delete move_sound;
    6.20 +		destroy_audio();
    6.21 +	}
    6.22  }
    6.23  
    6.24  void idle()
     7.1 --- a/prototype/src/renderer.cc	Tue Sep 18 04:45:46 2012 +0300
     7.2 +++ b/prototype/src/renderer.cc	Tue Sep 18 09:40:56 2012 +0300
     7.3 @@ -85,9 +85,14 @@
     7.4  void FwdRenderer::render(const Level *level) const
     7.5  {
     7.6  	glPushAttrib(GL_ENABLE_BIT);
     7.7 +	glEnable(GL_LIGHTING);
     7.8 +	glEnable(GL_FOG);
     7.9 +	glFogi(GL_FOG_MODE, GL_LINEAR);
    7.10 +	glFogf(GL_FOG_START, 3.0f);
    7.11 +	glFogf(GL_FOG_END, 6.0f);
    7.12 +
    7.13  	glUseProgram(sdrprog);
    7.14  
    7.15 -	glEnable(GL_LIGHTING);
    7.16  	level->draw();
    7.17  
    7.18  	glUseProgram(0);
     8.1 --- a/prototype/src/tile.cc	Tue Sep 18 04:45:46 2012 +0300
     8.2 +++ b/prototype/src/tile.cc	Tue Sep 18 09:40:56 2012 +0300
     8.3 @@ -291,7 +291,7 @@
     8.4  				SampleSet *sampleset = tset->get_samples();
     8.5  				AudioSample *sample = sampleset->get("fire.ogg");
     8.6  				if(sample) {
     8.7 -					AudioSourceDesc adesc = {side, lt->get_position(), sample};
     8.8 +					AudioSourceDesc adesc = {side, lt->get_position(), sample, 1.0, 0.1};
     8.9  					ausrc.push_back(adesc);
    8.10  				}
    8.11  			}
     9.1 --- a/prototype/src/tile.h	Tue Sep 18 04:45:46 2012 +0300
     9.2 +++ b/prototype/src/tile.h	Tue Sep 18 09:40:56 2012 +0300
     9.3 @@ -33,6 +33,8 @@
     9.4  		unsigned int dirmask;
     9.5  		Vector3 pos;
     9.6  		AudioSample *sample;
     9.7 +		float volume;
     9.8 +		float ref_dist;
     9.9  	};
    9.10  
    9.11  private: