{
actions XGetText
{
- $(XGETTEXT) $(XGETTEXT_FLAGS) --keyword='_:1' -o $(<) "$(>)"
+ $(XGETTEXT) $(XGETTEXT_FLAGS) -o $(<) "$(>)"
}
rule MakePot
{
--- /dev/null
+// $Id: sound_source.hpp 3462 2006-04-28 19:38:41Z sommer $
+//
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <config.h>
+
+#include "dummy_sound_source.hpp"
+
+class DummySoundSource : public SoundSource
+{
+public:
+ DummySoundSource()
+ {}
+ virtual ~DummySoundSource()
+ {}
+
+ virtual void play()
+ {
+ is_playing = true;
+ }
+
+ virtual void stop()
+ {
+ is_playing = false;
+ }
+
+ virtual bool playing()
+ {
+ return is_playing;
+ }
+
+ virtual void set_looping(bool )
+ {
+ }
+
+ virtual void set_gain(float )
+ {
+ }
+
+ virtual void set_pitch(float )
+ {
+ }
+
+ virtual void set_position(const Vector& )
+ {
+ }
+
+ virtual void set_velocity(const Vector& )
+ {
+ }
+
+ virtual void set_reference_distance(float )
+ {
+ }
+
+ virtual void set_rollof_factor(float )
+ {
+ }
+
+private:
+ bool is_playing;
+};
+
+SoundSource* create_dummy_sound_source()
+{
+ return new DummySoundSource();
+}
+
--- /dev/null
+// $Id: sound_source.hpp 3462 2006-04-28 19:38:41Z sommer $
+//
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#ifndef __DUMMY_SOUND_SOURCE_HPP__
+#define __DUMMY_SOUND_SOURCE_HPP__
+
+#include "sound_source.hpp"
+
+SoundSource* create_dummy_sound_source();
+
+#endif
+
+++ /dev/null
-// $Id$
-//
-// SuperTux - Managed Sound Source
-// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-#include <config.h>
-
-#include "audio/managed_sound_source.hpp"
-#include "log.hpp"
-
-ManagedSoundSource::ManagedSoundSource(SoundManager* sound_manager, const std::string& name)
- : name(name), soundSource(0), soundManager(sound_manager)
-{
-}
-
-ManagedSoundSource::ManagedSoundSource(const ManagedSoundSource& other)
- : name(other.name), soundSource(0), soundManager(other.soundManager)
-{
-}
-
-ManagedSoundSource::~ManagedSoundSource()
-{
- delete soundSource;
-}
-
-bool
-ManagedSoundSource::preload()
-{
- if (soundSource) return true;
- soundSource = soundManager->create_sound_source(name);
- return (soundSource != 0);
-}
-
-void
-ManagedSoundSource::release()
-{
- if (!soundSource) return;
- if (playing()) soundSource->stop();
- delete soundSource;
- soundSource = 0;
-}
-
-void
-ManagedSoundSource::play()
-{
- if (!preload()) {
- log_warning << "Couldn't play \"" << name << "\"" << std::endl;
- return;
- }
- soundSource->play();
-}
-
-void
-ManagedSoundSource::stop()
-{
- // FIXME: calling release() instead of stop() seems necessary due to an unconfirmed sound bug
- release();
-}
-
-bool
-ManagedSoundSource::playing()
-{
- if (!soundSource) return false;
- return soundSource->playing();
-}
-
+++ /dev/null
-// $Id$
-//
-// SuperTux - Managed Sound Source
-// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-
-#ifndef __MANAGED_SOUND_SOURCE_H__
-#define __MANAGED_SOUND_SOURCE_H__
-
-#include <string>
-#include "audio/sound_manager.hpp"
-#include "audio/sound_source.hpp"
-
-/**
- * Encapsulates a SoundSource that is managed by a SoundManager
- */
-class ManagedSoundSource
-{
-public:
- ManagedSoundSource(SoundManager* sound_manager, const std::string& name);
- ManagedSoundSource(const ManagedSoundSource& managed_sound_source);
- virtual ManagedSoundSource* clone() const { return new ManagedSoundSource(*this); }
- virtual ~ManagedSoundSource();
-
- /**
- * pre-loads SoundSource and indicates success.
- * If pre-loading failed, the SoundSource will be loaded at first use
- */
- bool preload();
-
- /**
- * stops playing and temporarily releases memory for the SoundSource.
- * Memory will be re-allocated on next use
- */
- void release();
-
- void play();
- void stop();
- bool playing();
- void set_looping(bool looping) { if (preload()) soundSource->set_looping(looping); }
- void set_gain(float gain) { if (preload()) soundSource->set_gain(gain); }
- void set_pitch(float pitch) { if (preload()) soundSource->set_pitch(pitch); }
- void set_position(Vector position) { if (preload()) soundSource->set_position(position); }
- void set_velocity(Vector position) { if (preload()) soundSource->set_velocity(position); }
- void set_reference_distance(float distance) { if (preload()) soundSource->set_reference_distance(distance); }
-
-protected:
- std::string name;
- SoundSource* soundSource;
- SoundManager* soundManager;
-
-private:
-};
-
-#endif
-
--- /dev/null
+// $Id$
+//
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <config.h>
+
+#include "openal_sound_source.hpp"
+#include "sound_manager.hpp"
+
+OpenALSoundSource::OpenALSoundSource()
+{
+ alGenSources(1, &source);
+ SoundManager::check_al_error("Couldn't create audio source: ");
+ set_reference_distance(128);
+}
+
+OpenALSoundSource::~OpenALSoundSource()
+{
+ stop();
+ alSourcei(source, AL_BUFFER, AL_NONE);
+ alDeleteSources(1, &source);
+}
+
+void
+OpenALSoundSource::stop()
+{
+ alSourceStop(source);
+ SoundManager::check_al_error("Problem stopping audio source: ");
+}
+
+void
+OpenALSoundSource::play()
+{
+ alSourcePlay(source);
+ SoundManager::check_al_error("Couldn't start audio source: ");
+}
+
+bool
+OpenALSoundSource::playing()
+{
+ ALint state = AL_PLAYING;
+ alGetSourcei(source, AL_SOURCE_STATE, &state);
+ return state != AL_STOPPED;
+}
+
+void
+OpenALSoundSource::update()
+{
+}
+
+void
+OpenALSoundSource::set_looping(bool looping)
+{
+ alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
+}
+
+void
+OpenALSoundSource::set_position(const Vector& position)
+{
+ alSource3f(source, AL_POSITION, position.x, position.y, 0);
+}
+
+void
+OpenALSoundSource::set_velocity(const Vector& velocity)
+{
+ alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
+}
+
+void
+OpenALSoundSource::set_gain(float gain)
+{
+ alSourcef(source, AL_GAIN, gain);
+}
+
+void
+OpenALSoundSource::set_pitch(float pitch)
+{
+ alSourcef(source, AL_PITCH, pitch);
+}
+
+void
+OpenALSoundSource::set_reference_distance(float distance)
+{
+ alSourcef(source, AL_REFERENCE_DISTANCE, distance);
+}
+
+void
+OpenALSoundSource::set_rollof_factor(float factor)
+{
+ alSourcef(source, AL_ROLLOFF_FACTOR, factor);
+}
--- /dev/null
+// $Id: sound_source.hpp 3462 2006-04-28 19:38:41Z sommer $
+//
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#ifndef __OPENAL_SOUND_SOURCE_H__
+#define __OPENAL_SOUND_SOURCE_H__
+
+#include <AL/al.h>
+#include "math/vector.hpp"
+#include "sound_source.hpp"
+
+class OpenALSoundSource : public SoundSource
+{
+public:
+ OpenALSoundSource();
+ virtual ~OpenALSoundSource();
+
+ virtual void play();
+ virtual void stop();
+ virtual bool playing();
+
+ virtual void update();
+
+ virtual void set_looping(bool looping);
+ virtual void set_gain(float gain);
+ virtual void set_pitch(float pitch);
+ virtual void set_position(const Vector& position);
+ virtual void set_velocity(const Vector& position);
+ virtual void set_reference_distance(float distance);
+ virtual void set_rollof_factor(float factor);
+
+protected:
+ friend class SoundManager;
+
+ ALuint source;
+};
+
+#endif
+
#include "sound_file.hpp"
#include "sound_source.hpp"
+#include "openal_sound_source.hpp"
#include "stream_sound_source.hpp"
+#include "dummy_sound_source.hpp"
#include "log.hpp"
#include "timer.hpp"
SoundManager::create_sound_source(const std::string& filename)
{
if(!sound_enabled)
- return 0;
+ return create_dummy_sound_source();
ALuint buffer;
if(i != buffers.end()) {
buffer = i->second;
} else {
- // Load sound file
- std::auto_ptr<SoundFile> file (load_sound_file(filename));
-
- if(file->size < 100000) {
- buffer = load_file_into_buffer(file.get());
- buffers.insert(std::make_pair(filename, buffer));
- } else {
- StreamSoundSource* source = new StreamSoundSource();
- source->set_sound_file(file.release());
- return source;
+ try {
+ // Load sound file
+ std::auto_ptr<SoundFile> file (load_sound_file(filename));
+
+ if(file->size < 100000) {
+ buffer = load_file_into_buffer(file.get());
+ buffers.insert(std::make_pair(filename, buffer));
+ } else {
+ StreamSoundSource* source = new StreamSoundSource();
+ source->set_sound_file(file.release());
+ return source;
+ }
+ } catch(std::exception& e) {
+ log_warning << "Couldn't load soundfile '" << filename << "': " << e.what() << std::endl;
+ return create_dummy_sound_source();
}
}
- SoundSource* source = new SoundSource();
+ OpenALSoundSource* source = new OpenALSoundSource();
alSourcei(source->source, AL_BUFFER, buffer);
return source;
}
void
SoundManager::play(const std::string& filename, const Vector& pos)
{
+ if(!sound_enabled)
+ return;
+
try {
- SoundSource* source = create_sound_source(filename);
- if(source == NULL)
- return;
+ OpenALSoundSource* source
+ = static_cast<OpenALSoundSource*> (create_sound_source(filename));
+
if(pos == Vector(-1, -1)) {
- alSourcef(source->source, AL_ROLLOFF_FACTOR, 0);
+ source->set_rollof_factor(0);
} else {
source->set_position(pos);
}
}
void
-SoundManager::play_and_delete(SoundSource* source)
+SoundManager::manage_source(SoundSource* source)
{
- if (!source) {
- log_debug << "ignoring NULL SoundSource" << std::endl;
- return;
- }
- try {
- source->play();
- sources.push_back(source);
- } catch(std::exception& e) {
- log_warning << "Couldn't play SoundSource: " << e.what() << std::endl;
+ assert(source != NULL);
+
+ OpenALSoundSource* openal_source = dynamic_cast<OpenALSoundSource*> (source);
+ if(openal_source != NULL) {
+ sources.push_back(openal_source);
}
}
// update and check for finished sound sources
for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) {
- SoundSource* source = *i;
+ OpenALSoundSource* source = *i;
source->update();
class SoundFile;
class SoundSource;
class StreamSoundSource;
+class OpenALSoundSource;
class SoundManager
{
* Convenience function to simply play a sound at a given position.
*/
void play(const std::string& name, const Vector& pos = Vector(-1, -1));
- void play_and_delete(SoundSource* source);
+ /**
+ * Adds the source to the list of managed sources (= the source gets deleted
+ * when it finished playing)
+ */
+ void manage_source(SoundSource* source);
/// preloads a sound, so that you don't get a lag later when playing it
void preload(const std::string& name);
void update();
private:
- friend class SoundSource;
+ friend class OpenALSoundSource;
friend class StreamSoundSource;
static ALuint load_file_into_buffer(SoundFile* file);
typedef std::map<std::string, ALuint> SoundBuffers;
SoundBuffers buffers;
- typedef std::vector<SoundSource*> SoundSources;
+ typedef std::vector<OpenALSoundSource*> SoundSources;
SoundSources sources;
StreamSoundSource* music_source;
+++ /dev/null
-// $Id$
-//
-// SuperTux
-// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#include <config.h>
-
-#include "sound_source.hpp"
-#include "sound_manager.hpp"
-
-SoundSource::SoundSource()
-{
- alGenSources(1, &source);
- SoundManager::check_al_error("Couldn't create audio source: ");
- set_reference_distance(128);
-}
-
-SoundSource::~SoundSource()
-{
- stop();
- alDeleteSources(1, &source);
-}
-
-void
-SoundSource::stop()
-{
- alSourceStop(source);
- alSourcei(source, AL_BUFFER, AL_NONE);
- SoundManager::check_al_error("Problem stopping audio source: ");
-}
-
-void
-SoundSource::play()
-{
- alSourcePlay(source);
- SoundManager::check_al_error("Couldn't start audio source: ");
-}
-
-bool
-SoundSource::playing()
-{
- ALint state = AL_PLAYING;
- alGetSourcei(source, AL_SOURCE_STATE, &state);
- return state != AL_STOPPED;
-}
-
-void
-SoundSource::update()
-{
-}
-
-void
-SoundSource::set_looping(bool looping)
-{
- alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
-}
-
-void
-SoundSource::set_position(Vector position)
-{
- alSource3f(source, AL_POSITION, position.x, position.y, 0);
-}
-
-void
-SoundSource::set_velocity(Vector velocity)
-{
- alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
-}
-
-void
-SoundSource::set_gain(float gain)
-{
- alSourcef(source, AL_GAIN, gain);
-}
-
-void
-SoundSource::set_pitch(float pitch)
-{
- alSourcef(source, AL_PITCH, pitch);
-}
-
-void
-SoundSource::set_reference_distance(float distance)
-{
- alSourcef(source, AL_REFERENCE_DISTANCE, distance);
-}
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
#ifndef __SOUND_SOURCE_H__
#define __SOUND_SOURCE_H__
-#include <AL/al.h>
#include "math/vector.hpp"
+/**
+ * A sound source represents the source of audio output. You can place
+ * sources at certain points in your world or set their velocity to produce
+ * doppler effects
+ */
class SoundSource
{
public:
- SoundSource();
- virtual ~SoundSource();
-
- void play();
- void stop();
- bool playing();
+ virtual ~SoundSource()
+ { }
- virtual void update();
+ virtual void play() = 0;
+ virtual void stop() = 0;
+ virtual bool playing() = 0;
- void set_looping(bool looping);
+ virtual void set_looping(bool looping) = 0;
/// Set volume (0.0 is silent, 1.0 is normal)
- void set_gain(float gain);
- void set_pitch(float pitch);
- void set_position(Vector position);
- void set_velocity(Vector position);
- void set_reference_distance(float distance);
-
-protected:
- friend class SoundManager;
-
- ALuint source;
+ virtual void set_gain(float gain) = 0;
+ virtual void set_pitch(float pitch) = 0;
+ virtual void set_position(const Vector& position) = 0;
+ virtual void set_velocity(const Vector& position) = 0;
+ virtual void set_reference_distance(float distance) = 0;
+ virtual void set_rollof_factor(float factor) = 0;
};
#endif
#include <stdio.h>
#include <SDL.h>
-#include "sound_source.hpp"
+#include "openal_sound_source.hpp"
class SoundFile;
-class StreamSoundSource : public SoundSource
+class StreamSoundSource : public OpenALSoundSource
{
public:
StreamSoundSource();
public:
BadGuy(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS);
BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer = LAYER_OBJECTS);
- virtual BadGuy* clone() const = 0;
/** Called when the badguy is drawn. The default implementation simply draws
* the badguy sprite on screen
const float SPEED = 200;
}
+static const std::string SOUNDFILE = "sounds/flame.wav";
+
Dart::Dart(const lisp::Lisp& reader)
- : BadGuy(reader, "images/creatures/dart/dart.sprite"), set_direction(false), parent(0), soundSource(0)
+ : BadGuy(reader, "images/creatures/dart/dart.sprite"), set_direction(false), parent(0)
{
physic.enable_gravity(false);
countMe = false;
}
Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0)
- : BadGuy(pos, "images/creatures/dart/dart.sprite"), set_direction(true), initial_direction(d), parent(parent), soundSource(0)
+ : BadGuy(pos, "images/creatures/dart/dart.sprite"), set_direction(true), initial_direction(d), parent(parent)
{
physic.enable_gravity(false);
countMe = false;
Dart::Dart(const Dart& other)
: BadGuy(other), set_direction(other.set_direction), initial_direction(other.initial_direction), parent(other.parent)
{
- soundSource = sound_manager->create_sound_source("sounds/flame.wav");
+ sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
}
Dart::~Dart()
{
- delete soundSource;
}
bool
physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
- delete soundSource;
- soundSource = sound_manager->create_sound_source("sounds/flame.wav");
- if(soundSource) {
- soundSource->set_position(get_pos());
- soundSource->set_looping(true);
- soundSource->set_gain(1.0);
- soundSource->set_reference_distance(32);
- soundSource->play();
- } else {
- log_warning << "Couldn't start Dart ambient sound" << std::endl;
- }
+ sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
+ sound_source->set_position(get_pos());
+ sound_source->set_looping(true);
+ sound_source->set_gain(1.0);
+ sound_source->set_reference_distance(32);
+ sound_source->play();
}
void
Dart::deactivate()
{
- delete soundSource;
- soundSource = 0;
+ sound_source.release();
remove_me();
}
Dart::active_update(float elapsed_time)
{
BadGuy::active_update(elapsed_time);
- if (soundSource) soundSource->set_position(get_pos());
+ sound_source->set_position(get_pos());
}
bool set_direction;
Direction initial_direction;
const BadGuy* parent; /**< collisions with this BadGuy will be ignored */
- SoundSource* soundSource; /**< SoundSource for ambient sound */
+ std::auto_ptr<SoundSource> sound_source; /**< SoundSource for ambient sound */
};
#endif
#include "flame.hpp"
#include "log.hpp"
+static const std::string SOUNDFILE = "sounds/flame.wav";
+
Flame::Flame(const lisp::Lisp& reader)
- : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2), source(0)
+ : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2), sound_source(0)
{
reader.get("radius", radius);
reader.get("speed", speed);
bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
start_position.y + sin(angle) * radius));
countMe = false;
-}
-
-Flame::Flame(const Flame& other)
- : BadGuy(other), angle(other.angle), radius(other.radius), speed(other.speed)
-{
- if (sound_manager->is_sound_enabled()) {
- source.reset(sound_manager->create_sound_source("sounds/flame.wav"));
- }
+ sound_manager->preload(SOUNDFILE);
}
void
start_position.y + sin(angle) * radius);
movement = newpos - get_pos();
- if (sound_manager->is_sound_enabled())
- source->set_position(get_pos());
+ sound_source->set_position(get_pos());
}
void
{
set_group(COLGROUP_TOUCHABLE);
- if (!sound_manager->is_sound_enabled())
- return;
-
- source.reset(sound_manager->create_sound_source("sounds/flame.wav"));
- if(source.get() == NULL) {
- log_warning << "Couldn't start flame sound" << std::endl;
- return;
- }
- source->set_position(get_pos());
- source->set_looping(true);
- source->set_gain(2.0);
- source->set_reference_distance(32);
- source->play();
+ sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
+ sound_source->set_position(get_pos());
+ sound_source->set_looping(true);
+ sound_source->set_gain(2.0);
+ sound_source->set_reference_distance(32);
+ sound_source->play();
}
void
Flame::deactivate()
{
- source.release();
+ sound_source.release();
}
void
void active_update(float elapsed_time);
void kill_fall();
- virtual Flame* clone() const { return new Flame(*this); }
-
private:
float angle;
float radius;
float speed;
- std::auto_ptr<SoundSource> source;
+ std::auto_ptr<SoundSource> sound_source;
};
#endif
static const float FLYSPEED = 64; /**< speed in px per second */
static const float TRACK_RANGE = 384; /**< at what distance to start tracking the player */
static const float VANISH_RANGE = 512; /**< at what distance to stop tracking and vanish */
+static const std::string SOUNDFILE = "sounds/willowisp.wav";
WillOWisp::WillOWisp(const lisp::Lisp& reader)
- : BadGuy(reader, "images/creatures/willowisp/willowisp.sprite", LAYER_FLOATINGOBJECTS), mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main"), soundSource(sound_manager, "sounds/willowisp.wav")
+ : BadGuy(reader, "images/creatures/willowisp/willowisp.sprite", LAYER_FLOATINGOBJECTS), mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main")
{
reader.get("sector", target_sector);
reader.get("spawnpoint", target_spawnpoint);
countMe = false;
+ sound_manager->preload(SOUNDFILE);
}
void
mystate = STATE_VANISHING;
sprite->set_action("vanishing", 1);
}
- soundSource.set_position(get_pos());
+ sound_source->set_position(get_pos());
}
if (mystate == STATE_WARPING) {
{
sprite->set_action("idle");
- soundSource.set_position(get_pos());
- soundSource.set_looping(true);
- soundSource.set_gain(2.0);
- soundSource.set_reference_distance(32);
- soundSource.play();
+ sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
+ sound_source->set_position(get_pos());
+ sound_source->set_looping(true);
+ sound_source->set_gain(2.0);
+ sound_source->set_reference_distance(32);
+ sound_source->play();
}
void
WillOWisp::deactivate()
{
- soundSource.stop();
- soundSource.release();
+ sound_source.reset(NULL);
switch (mystate) {
case STATE_IDLE:
virtual void draw(DrawingContext& context);
- virtual WillOWisp* clone() const { return new WillOWisp(*this); }
-
protected:
HitResponse collision_player(Player& player, const CollisionHit& hit);
std::string target_sector;
std::string target_spawnpoint;
- ManagedSoundSource soundSource;
+ std::auto_ptr<SoundSource> sound_source;
};
#endif
for(std::vector<MenuItem*>::iterator i = items.begin();
i != items.end(); ++i)
delete *i;
-#ifdef DEBUG
- assert(current_ != this);
-#else
if(current_ == this)
current_ = NULL;
-#endif
}
Menu::Menu()
SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
soundSource->set_position(get_pos());
soundSource->set_pitch(pitch);
- sound_manager->play_and_delete(soundSource);
+ soundSource->play();
+ sound_manager->manage_source(soundSource);
*/
Sector::current()->player->get_status()->add_coins(1);
Sector::current()->add_object(new BouncyCoin(get_pos()));
virtual void draw(DrawingContext& context);
virtual void update(float elapsed_time);
- virtual MovingSprite* clone() const = 0;
-
protected:
std::string sprite_name;
Sprite* sprite;
void
ScriptedObject::set_pos(float x, float y)
{
+ printf("SetPos: %f %f\n", x, y);
bbox.set_pos(Vector(x, y));
+ physic.reset();
}
float
void handle_collisions();
/**
- * Collision checks 2 objects against each other and does instant
+ * Does collision detection between 2 objects and does instant
* collision response handling in case of a collision
*/
void collision_object(MovingObject* object1, MovingObject* object2) const;