X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fambient_sound.cpp;h=a4a26e7a5ca4a4b690ed4c9f82456977cddd7cf1;hb=8a627e73d824b5a14249cfe066dc2fdc643ce28d;hp=8fad2a9c5e514fe7da15c64af09bd163d2116546;hpb=e66a5fa8d047b05f784ee4f595d8895eff129fc3;p=supertux.git diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index 8fad2a9c5..a4a26e7a5 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -32,41 +32,21 @@ #include "log.hpp" #include "scripting/squirrel_util.hpp" -AmbientSound::AmbientSound(const lisp::Lisp& lisp) +AmbientSound::AmbientSound(const lisp::Lisp& lisp) : + MovingObject(lisp), sample(""), sound_source(0), latency(0), + distance_factor(0), distance_bias(0), maximumvolume(1), currentvolume(0) { - name=""; - position.x = 0; - position.y = 0; - - dimension.x = 0; - dimension.y = 0; - - distance_factor = 0; - distance_bias = 0; - maximumvolume = 1; - sample = ""; - currentvolume = 0; - - if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) { - log_warning << "No Position in ambient_sound" << std::endl; - } - - lisp.get("name" , name); - 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 ); // set dimension to zero if smaller than 64, which is default size in flexlay - - if ((dimension.x <= 64) || (dimension.y <= 64)) { - dimension.x = 0; - dimension.y = 0; + + if ((get_width() <= 64) || (get_height() <= 64)) { + set_size(0, 0); } - + // square all distances (saves us a sqrt later) distance_bias*=distance_bias; @@ -78,35 +58,23 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) silence_distance = 10e99; else silence_distance = 1/distance_factor; - - lisp.get("silence_distance",silence_distance); - sound_source = 0; // not playing at the beginning - latency=0; + lisp.get("silence_distance",silence_distance); } -AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file) +AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file) : + sample(file), sound_source(0), latency(0), distance_factor(factor*factor), + distance_bias(bias*bias), maximumvolume(vol), currentvolume(0) { - position.x=pos.x; - position.y=pos.y; - - dimension.x=0; - dimension.y=0; + bbox.p1 = pos; + bbox.p2 = pos; - distance_factor=factor*factor; - distance_bias=bias*bias; - maximumvolume=vol; - sample=file; - // set default silence_distance if (distance_factor == 0) silence_distance = 10e99; else silence_distance = 1/distance_factor; - - sound_source = 0; // not playing at the beginning - latency=0; } AmbientSound::~AmbientSound() { @@ -131,7 +99,7 @@ AmbientSound::start_playing() sound_source = sound_manager->create_sound_source(sample); if(!sound_source) throw std::runtime_error("file not found"); - + sound_source->set_gain(0); sound_source->set_looping(true); currentvolume=targetvolume=1e-20; @@ -145,8 +113,8 @@ AmbientSound::start_playing() } void -AmbientSound::update(float deltat) -{ +AmbientSound::update(float deltat) +{ if (latency-- <= 0) { float px,py; float rx,ry; @@ -156,10 +124,10 @@ AmbientSound::update(float deltat) py=Sector::current()->player->get_pos().y; // Relate to which point in the area - rx=pxset_gain(currentvolume*maximumvolume); if (sqrdistance>=silence_distance && currentvolume<1e-3) - stop_playing(); + stop_playing(); latency=0; } else { if (sqrdistance (this); - expose_object(vm, table_idx, interface, name, false); + if(name.empty()) return; + expose_object(vm, table_idx, dynamic_cast(this), name, false); } void AmbientSound::unexpose(HSQUIRRELVM vm, SQInteger table_idx) { + if(name.empty()) return; Scripting::unexpose_object(vm, table_idx, name); } -void -AmbientSound::set_pos(float x, float y){ - position.x = x; - position.y = y; -} - -float -AmbientSound::get_pos_x(){; - return position.x; -} - -float -AmbientSound::get_pos_y(){ - return position.y; -} - IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");