From d002509e55516caff62ba5125ae6f96867478e89 Mon Sep 17 00:00:00 2001 From: Mojito Sorbet Date: Thu, 6 May 2010 18:30:57 +0000 Subject: [PATCH] Provide a 'tick' to FMOD so callbacks will work. git-svn-id: https://radegast.googlecode.com/svn/branches/sounds@611 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/Core/Media/BufferSound.cs | 1 - Radegast/Core/Media/MediaManager.cs | 23 ++++++++++++++++++----- Radegast/Core/Media/MediaObject.cs | 21 +++++++++++++++++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Radegast/Core/Media/BufferSound.cs b/Radegast/Core/Media/BufferSound.cs index 7616f39..e003743 100644 --- a/Radegast/Core/Media/BufferSound.cs +++ b/Radegast/Core/Media/BufferSound.cs @@ -39,7 +39,6 @@ namespace Radegast.Media public class BufferSound : MediaObject { private FMOD.CREATESOUNDEXINFO extendedInfo; - private FMOD.VECTOR position; public Sound Sound { get { return sound; } } diff --git a/Radegast/Core/Media/MediaManager.cs b/Radegast/Core/Media/MediaManager.cs index 4217ab3..20abef9 100644 --- a/Radegast/Core/Media/MediaManager.cs +++ b/Radegast/Core/Media/MediaManager.cs @@ -220,24 +220,37 @@ namespace Radegast.Media base.Dispose(); } - private void OnListenerUpdate() + /// + /// Thread to update listener position and generally keep + /// FMOD up to date. + /// + private void ListenerUpdate() { Vector3 lastpos = new Vector3(0.0f, 0.0f, 0.0f ); float lastface = 0.0f; while (true) { - // TODO would be nice if there was an event for this. Thread.Sleep(500); if (system == null) continue; AgentManager my = instance.Client.Self; - // If we are standing still, nothing to update. - if (my.SimPosition.Equals( lastpos ) && + // If we are standing still, nothing to update now, but + // FMOD needs a 'tick' anyway for callbacks, etc. In looping + // 'game' programs, the loop is the 'tick'. Since Radegast + // uses events and has no loop, we use this position update + // thread to drive the tick. + if (my.SimPosition.Equals(lastpos) && my.Movement.BodyRotation.W == lastface) + { + invoke(new SoundDelegate(delegate + { + system.update(); + })); continue; + } lastpos = my.SimPosition; lastface = my.Movement.BodyRotation.W; @@ -258,7 +271,7 @@ namespace Radegast.Media // Tell FMOD the new orientation. invoke( new SoundDelegate( delegate { - MediaManager.FMODExec( system.set3DListenerAttributes( + FMODExec( system.set3DListenerAttributes( 0, ref listenerpos, // Position ref ZeroVector, // Velocity diff --git a/Radegast/Core/Media/MediaObject.cs b/Radegast/Core/Media/MediaObject.cs index 6ca67f6..135a3fa 100644 --- a/Radegast/Core/Media/MediaObject.cs +++ b/Radegast/Core/Media/MediaObject.cs @@ -127,10 +127,27 @@ namespace Radegast.Media } set { + volume = value; invoke(new SoundDelegate(delegate { - MediaManager.FMODExec(channel.setVolume(value)); - volume = value; + FMODExec(channel.setVolume(volume)); + system.update(); + })); + } + } + + protected FMOD.VECTOR position = new FMOD.VECTOR(); + public OpenMetaverse.Vector3 Position + { + set + { + position = FromOMVSpace(value); + invoke(new SoundDelegate(delegate + { + FMODExec(channel.set3DAttributes( + ref position, + ref ZeroVector)); + system.update(); })); } } -- 2.11.0