Play stereo effects in relation to camera, not player (closes issue 56)
authorChristoph Sommer <mail@christoph-sommer.de>
Sun, 6 Jan 2008 02:52:24 +0000 (02:52 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sun, 6 Jan 2008 02:52:24 +0000 (02:52 +0000)
SVN-Revision: 5258

src/game_session.cpp
src/object/ambient_sound.cpp
src/object/camera.cpp
src/object/camera.hpp

index a0e48c3..e918a09 100644 (file)
@@ -528,7 +528,7 @@ GameSession::update(float elapsed_time)
   }
 
   // update sounds
-  sound_manager->set_listener_position(currentsector->player->get_pos());
+  if (currentsector && currentsector->camera) sound_manager->set_listener_position(currentsector->camera->get_center());
 
   /* Handle music: */
   if (end_sequence)
index 5d3a792..14df038 100644 (file)
@@ -32,6 +32,7 @@
 #include "audio/sound_source.hpp"
 #include "log.hpp"
 #include "scripting/squirrel_util.hpp"
+#include "object/camera.hpp"
 
 AmbientSound::AmbientSound(const lisp::Lisp& lisp)
 {
@@ -83,6 +84,7 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp)
   lisp.get("silence_distance",silence_distance);
 
   sound_source = 0; // not playing at the beginning
+  sound_manager->preload(sample);
   latency=0;
 }
 
@@ -152,9 +154,10 @@ AmbientSound::update(float deltat)
     float px,py;
     float rx,ry;
 
-    // Player position
-    px=Sector::current()->player->get_pos().x;
-    py=Sector::current()->player->get_pos().y;
+    if (!Sector::current() || !Sector::current()->camera) return;
+    // Camera position
+    px=Sector::current()->camera->get_center().x;
+    py=Sector::current()->camera->get_center().y;
 
     // Relate to which point in the area
     rx=px<position.x?position.x:
index 42dd1aa..14d97a4 100644 (file)
@@ -536,3 +536,9 @@ Camera::update_scroll_to(float elapsed_time)
 
   translation = scroll_from + (scroll_goal - scroll_from) * scroll_to_pos;
 }
+
+Vector
+Camera::get_center() const {
+  return translation + Vector(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
+}
+
index d5ca2d0..726a3e0 100644 (file)
@@ -86,6 +86,11 @@ public:
   };
   CameraMode mode;
 
+  /**
+   * get the coordinates of the point directly in the center of this camera
+   */
+  Vector get_center() const;
+
 private:
   void update_scroll_normal(float elapsed_time);
   void update_scroll_autoscroll(float elapsed_time);