From: Bastiaan Zapf Date: Tue, 10 May 2005 17:27:29 +0000 (+0000) Subject: - Upgraded ambient sound source to rounded rectangule dimension X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b4d61788c3766a02d1e30866852cfb1ac2d557a6;p=supertux.git - Upgraded ambient sound source to rounded rectangule dimension - A few general improvements SVN-Revision: 2463 --- diff --git a/data/levels/test/ambient_sound.stl b/data/levels/test/ambient_sound.stl index e4cd7eeae..38a284685 100644 --- a/data/levels/test/ambient_sound.stl +++ b/data/levels/test/ambient_sound.stl @@ -137,7 +137,8 @@ (distance_bias 200.0) (sample "rain")) (ambient_sound (x 512) (y 900) (distance_factor 0.05) (distance_bias 100.0) (sample "waterfall") (volume 0.2)) - (ambient_sound (x 800) (y 900) (distance_factor 0.1) + (ambient_sound (x 700) (y 900) (width 300) +(height 200) (distance_factor 0.1) (distance_bias 50.0) (sample "lava")) (infoblock (x 128) (y 864) (message (_ "-Info @@ -145,21 +146,20 @@ #source playing the #rain effect should #be audible here. -#Find Waterfall and -#Lava sources with -#smaller geometry -#further right. ")) ) (infoblock (x 512) (y 864) (message (_ "-Info #Waterfall #Volume 0.2 +#smaller geometry +#than rain source ")) ) - (infoblock (x 800) (y 864) + (infoblock (x 700) (y 864) (message (_ "-Info -#Lava +#Lava (Area) +#extending right ")) ) ) diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index ea7a9aa0f..bec0d9cfe 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -30,6 +30,10 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) position.x=0; position.y=0; + + dimension.x=0; + dimension.y=0; + distance_factor=0; distance_bias=0; maximumvolume=1; @@ -38,14 +42,22 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) { std::cerr << "No Position in ambient_sound" << std::endl; } + + lisp.get("width" , dimension.x); + lisp.get("height", dimension.y); + lisp.get("distance_factor",distance_factor); lisp.get("distance_bias" ,distance_bias ); lisp.get("sample" ,sample ); lisp.get("volume" ,maximumvolume ); + // square all distances (saves us a sqrt later) + distance_bias*=distance_bias; distance_factor*=distance_factor; + // set default silence_distance + if (distance_factor == 0) silence_distance = 10e99; else @@ -55,7 +67,6 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) playing=-1; // not playing at the beginning latency=0; - } AmbientSound::~AmbientSound() { @@ -88,23 +99,49 @@ AmbientSound::update(float deltat) { if (latency--<=0) { - float dx=Sector::current()->player->get_pos().x-position.x; - float dy=Sector::current()->player->get_pos().y-position.y; - float sqrdistance=dx*dx+dy*dy; + float px,py; + float rx,ry; + + // Player position + + px=Sector::current()->player->get_pos().x; + py=Sector::current()->player->get_pos().y; + + // Relate to which point in the area + + rx=px=0) { + + // set the volume Mix_Volume(playing,(int)(currentvolume*maximumvolume*MIX_MAX_VOLUME)); - if (sqrdistance>=silence_distance && currentvolume<0.05) + + if (sqrdistance>=silence_distance && currentvolume<1e-3) stop_playing(); latency=0; } else { @@ -112,13 +149,16 @@ AmbientSound::update(float deltat) start_playing(); latency=0; } - else - latency=(int)(10*((sqrdistance-silence_distance)/silence_distance)); + else // set a reasonable latency + latency=(int)(0.001/distance_factor); + //(int)(10*((sqrdistance-silence_distance)/silence_distance)); } + } - } - if (latency>0.001/distance_factor) - latency=(int)(0.001/distance_factor); + // heuristically measured "good" latency maximum + + // if (latency>0.001/distance_factor) + // latency= } void diff --git a/src/object/ambient_sound.h b/src/object/ambient_sound.h index 00e43cfc2..864bf4a7e 100644 --- a/src/object/ambient_sound.h +++ b/src/object/ambient_sound.h @@ -18,17 +18,23 @@ // 02111-1307, USA. /** - * Ambient Sound Source, beta version. Features: + * Ambient Sound Source, gamma version. Features: * - * - "disc" like structure. Full volume up to some distance - * (distance_bias) to the source, then fading proportional to - * inverse square distance + * - "rounded rectancle" geometry with position, dimension and + * "rounding radius" (extending in all directions) of a 100% + * volume area, adjustable maximum volume, inverse square + * falloff outside area. * - * - parameters for point source: + * - degenerates gracefully to a disc for dimension=0 + * + * - parameters: + * * x, y position + * width, height dimension * distance_factor high = steep fallofff * distance_bias high = big "100% disc" * silence_distance defaults reasonably. + * sample sample to be played back in loop mode * * basti_ */ @@ -55,6 +61,7 @@ protected: virtual void stop_playing(); private: Vector position; + Vector dimension; std::string sample; int playing;