- Remove ManagedSoundSource
authorMatthias Braun <matze@braunis.de>
Fri, 26 May 2006 17:37:36 +0000 (17:37 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 26 May 2006 17:37:36 +0000 (17:37 +0000)
- Make SoundManage::create_sound_source always return a valid object,
  it returns a dummy sound source now if something fails

SVN-Revision: 3595

24 files changed:
Jamrules
src/audio/dummy_sound_source.cpp [new file with mode: 0644]
src/audio/dummy_sound_source.hpp [new file with mode: 0644]
src/audio/managed_sound_source.cpp [deleted file]
src/audio/managed_sound_source.hpp [deleted file]
src/audio/openal_sound_source.cpp [new file with mode: 0644]
src/audio/openal_sound_source.hpp [new file with mode: 0644]
src/audio/sound_manager.cpp
src/audio/sound_manager.hpp
src/audio/sound_source.cpp [deleted file]
src/audio/sound_source.hpp
src/audio/stream_sound_source.hpp
src/badguy/badguy.hpp
src/badguy/dart.cpp
src/badguy/dart.hpp
src/badguy/flame.cpp
src/badguy/flame.hpp
src/badguy/willowisp.cpp
src/badguy/willowisp.hpp
src/gui/menu.cpp
src/object/coin.cpp
src/object/moving_sprite.hpp
src/object/scripted_object.cpp
src/sector.hpp

index 920185f..5c35590 100644 (file)
--- a/Jamrules
+++ b/Jamrules
@@ -52,7 +52,7 @@ if $(XGETTEXT) != ""
 {
     actions XGetText
     {
-        $(XGETTEXT) $(XGETTEXT_FLAGS) --keyword='_:1' -o $(<) "$(>)"
+        $(XGETTEXT) $(XGETTEXT_FLAGS) -o $(<) "$(>)"
     }
     rule MakePot
     {
diff --git a/src/audio/dummy_sound_source.cpp b/src/audio/dummy_sound_source.cpp
new file mode 100644 (file)
index 0000000..13c1c2e
--- /dev/null
@@ -0,0 +1,82 @@
+//  $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();
+}
+
diff --git a/src/audio/dummy_sound_source.hpp b/src/audio/dummy_sound_source.hpp
new file mode 100644 (file)
index 0000000..53a3e91
--- /dev/null
@@ -0,0 +1,27 @@
+//  $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
+
diff --git a/src/audio/managed_sound_source.cpp b/src/audio/managed_sound_source.cpp
deleted file mode 100644 (file)
index 167608f..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-//  $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();
-}
-
diff --git a/src/audio/managed_sound_source.hpp b/src/audio/managed_sound_source.hpp
deleted file mode 100644 (file)
index cebf6ad..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-//  $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
-
diff --git a/src/audio/openal_sound_source.cpp b/src/audio/openal_sound_source.cpp
new file mode 100644 (file)
index 0000000..e5c5861
--- /dev/null
@@ -0,0 +1,105 @@
+//  $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);
+}
diff --git a/src/audio/openal_sound_source.hpp b/src/audio/openal_sound_source.hpp
new file mode 100644 (file)
index 0000000..75b6ef6
--- /dev/null
@@ -0,0 +1,53 @@
+//  $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
+
index 6905621..0c77b99 100644 (file)
@@ -27,7 +27,9 @@
 
 #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"
 
@@ -112,7 +114,7 @@ SoundSource*
 SoundManager::create_sound_source(const std::string& filename)
 {
   if(!sound_enabled)
-    return 0;
+    return create_dummy_sound_source();
 
   ALuint buffer;
   
@@ -121,20 +123,25 @@ SoundManager::create_sound_source(const std::string& filename)
   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;  
 }
@@ -162,12 +169,15 @@ SoundManager::preload(const std::string& filename)
 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);
     }
@@ -179,17 +189,13 @@ SoundManager::play(const std::string& filename, const Vector& 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);
   }
 }
 
@@ -294,7 +300,7 @@ SoundManager::update()
 
   // update and check for finished sound sources
   for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) {
-    SoundSource* source = *i;
+    OpenALSoundSource* source = *i;
 
     source->update();
     
index 88f2437..a715d99 100644 (file)
@@ -30,6 +30,7 @@
 class SoundFile;
 class SoundSource;
 class StreamSoundSource;
+class OpenALSoundSource;
 
 class SoundManager
 {
@@ -50,7 +51,11 @@ public:
    * 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);
 
@@ -71,7 +76,7 @@ public:
   void update();
 
 private:
-  friend class SoundSource;
+  friend class OpenALSoundSource;
   friend class StreamSoundSource;
 
   static ALuint load_file_into_buffer(SoundFile* file);
@@ -87,7 +92,7 @@ private:
 
   typedef std::map<std::string, ALuint> SoundBuffers;
   SoundBuffers buffers;
-  typedef std::vector<SoundSource*> SoundSources;
+  typedef std::vector<OpenALSoundSource*> SoundSources;
   SoundSources sources;
 
   StreamSoundSource* music_source;
diff --git a/src/audio/sound_source.cpp b/src/audio/sound_source.cpp
deleted file mode 100644 (file)
index 9864894..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-//  $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);
-}
index d878ef4..3824c3c 100644 (file)
 //  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
index 18b2dc9..de1dbc0 100644 (file)
 
 #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();
index eee973f..425213d 100644 (file)
@@ -43,7 +43,6 @@ class BadGuy : public MovingSprite, public Serializable
 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
index ce9a956..a4cc63e 100644 (file)
@@ -26,15 +26,17 @@ namespace {
   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;
@@ -43,12 +45,11 @@ Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0)
 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 
@@ -77,24 +78,18 @@ Dart::activate()
   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();
 }
 
@@ -102,7 +97,7 @@ void
 Dart::active_update(float elapsed_time)
 {
   BadGuy::active_update(elapsed_time);
-  if (soundSource) soundSource->set_position(get_pos());
+  sound_source->set_position(get_pos());
 }
 
 
index 6a1c20d..1c6a3d3 100644 (file)
@@ -52,7 +52,7 @@ protected:
   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
index 330d828..19211d2 100644 (file)
 #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
@@ -61,8 +56,7 @@ Flame::active_update(float elapsed_time)
                 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
@@ -70,25 +64,18 @@ Flame::activate()
 {
   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
index 303c698..b099eae 100644 (file)
@@ -34,14 +34,12 @@ public:
   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
index 69de916..6480c16 100644 (file)
 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
@@ -85,7 +87,7 @@ WillOWisp::active_update(float elapsed_time)
       mystate = STATE_VANISHING;
       sprite->set_action("vanishing", 1);
     }
-    soundSource.set_position(get_pos());
+    sound_source->set_position(get_pos());
   }
 
   if (mystate == STATE_WARPING) {
@@ -107,18 +109,18 @@ WillOWisp::activate()
 {
   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:
index ce45ced..00cc4c9 100644 (file)
@@ -38,8 +38,6 @@ public:
 
   virtual void draw(DrawingContext& context);
 
-  virtual WillOWisp* clone() const { return new WillOWisp(*this); }
-
 protected:
   HitResponse collision_player(Player& player, const CollisionHit& hit);
 
@@ -52,7 +50,7 @@ private:
   std::string target_sector;
   std::string target_spawnpoint;
 
-  ManagedSoundSource soundSource;
+  std::auto_ptr<SoundSource> sound_source;
 };
 
 #endif
index c140804..e230b3d 100644 (file)
@@ -194,12 +194,8 @@ Menu::~Menu()
   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()
index 566d294..2684bcd 100644 (file)
@@ -115,7 +115,8 @@ Coin::collect()
   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()));
index ae80634..df1743d 100644 (file)
@@ -42,8 +42,6 @@ public:
   virtual void draw(DrawingContext& context);
   virtual void update(float elapsed_time);
 
-  virtual MovingSprite* clone() const = 0;
-
 protected:
   std::string sprite_name;
   Sprite* sprite;
index 009b4a5..69f15ca 100644 (file)
@@ -74,7 +74,9 @@ ScriptedObject::move(float x, float y)
 void
 ScriptedObject::set_pos(float x, float y)
 {
+  printf("SetPos: %f %f\n", x, y);
   bbox.set_pos(Vector(x, y));
+  physic.reset();
 }
 
 float
index 02af026..ab96230 100644 (file)
@@ -162,7 +162,7 @@ private:
   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;