29 using System.Collections.Generic;
30 using System.Reflection;
37 using OpenSim.Framework;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
43 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SoundModule")]
49 private Scene m_scene;
60 SYNC_MASK = SYNC_MASTER | SYNC_SLAVE | SYNC_PENDING
63 public bool Enabled {
get;
private set; }
65 public float MaxDistance {
get;
private set; }
67 #region INonSharedRegionModule
71 IConfig config = configSource.Configs[
"Sounds"];
80 Enabled = config.GetString(
"Module",
"OpenSim.Region.CoreModules.dll:SoundModule") ==
81 Path.GetFileName(Assembly.GetExecutingAssembly()
.Location)
82 +
":" + MethodBase.GetCurrentMethod().DeclaringType.Name;
83 MaxDistance = config.GetFloat(
"MaxDistance", 100.0f);
91 m_scene.EventManager.OnNewClient -= OnNewClient;
100 m_scene.EventManager.OnNewClient += OnNewClient;
107 public Type ReplaceableInterface
112 public string Name {
get {
return "Sound Module"; } }
116 #region Event Handlers
120 client.OnSoundTrigger += TriggerSound;
128 UUID soundID, UUID ownerID, UUID objectID,
double gain, Vector3 position, byte flags,
float radius)
131 if (!m_scene.TryGetSceneObjectPart(objectID, out part))
137 radius = MaxDistance;
139 if (part.SoundQueueing)
148 if (!ssp.ParcelAllowThisAvatarSounds)
153 ssp.ControllingClient.SendPlayAttachedSound(soundID, objectID,
154 ownerID, (float)gain, flags);
161 sp.ControllingClient.SendPlayAttachedSound(soundID, objectID,
162 ownerID, (float)gain, flags);
167 UUID soundId, UUID ownerID, UUID objectID, UUID parentID,
double gain, Vector3 position, UInt64 handle,
float radius)
171 if (!m_scene.TryGetSceneObjectPart(objectID, out part))
173 if (!m_scene.TryGetScenePresence(ownerID, out ssp))
175 if (!ssp.ParcelAllowThisAvatarSounds)
187 if (!ssp.ParcelAllowThisAvatarSounds)
192 ssp.ControllingClient.SendTriggeredSound(soundId, ownerID,
193 objectID, parentID, handle, position,
201 radius = MaxDistance;
205 double dis = Util.GetDistanceTo(sp.AbsolutePosition, position);
209 sp.ControllingClient.SendTriggeredSound(soundId, ownerID,
210 objectID, parentID, handle, position,
218 if (!m_scene.TryGetSceneObjectPart(objectID, out m_host))
227 m_host.Sound = UUID.Zero;
228 m_host.SoundFlags = (byte)SoundFlags.STOP;
232 m_host.SendFullUpdateToAllClients();
235 public virtual void PreloadSound(UUID objectID, UUID soundID,
float radius)
238 if (soundID ==
UUID.Zero
239 || !m_scene.TryGetSceneObjectPart(objectID, out part))
245 radius = MaxDistance;
249 if (Util.GetDistanceTo(sp.
AbsolutePosition, part.AbsolutePosition) < radius)
263 double volume,
double radius,
bool isMaster,
bool isSlave)
266 if (!m_scene.TryGetSceneObjectPart(objectID, out m_host))
275 if (m_host.SoundQueueing)
278 m_host.
Sound = soundID;
279 m_host.SoundGain = volume;
280 m_host.SoundFlags = iflags;
281 m_host.SoundRadius = radius;
283 m_host.ScheduleFullUpdate();
284 m_host.SendFullUpdateToAllClients();
287 public void SendSound(UUID objectID, UUID soundID,
double volume,
288 bool triggered, byte flags,
float radius,
bool useMaster,
291 if (soundID ==
UUID.Zero)
295 if (!m_scene.TryGetSceneObjectPart(objectID, out part))
298 volume = Util.Clip((float)volume, 0, 1);
300 UUID parentID = part.ParentGroup.UUID;
302 Vector3 position = part.AbsolutePosition;
303 ulong regionHandle = m_scene.RegionInfo.RegionHandle;
306 TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius);
316 PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, bflags, radius);
321 double volume, Vector3 min, Vector3 max)
323 if (sound ==
UUID.Zero)
327 if (!m_scene.TryGetSceneObjectPart(objectID, out part))
332 double dis = Util.GetDistanceTo(sp.AbsolutePosition,
333 part.AbsolutePosition);
335 if (dis > MaxDistance)
341 double thisSpGain = volume * ((MaxDistance - dis) / MaxDistance);
343 sp.ControllingClient.SendTriggeredSound(sound, part.OwnerID,
344 part.UUID, part.ParentGroup.UUID,
345 m_scene.RegionInfo.RegionHandle,
346 part.AbsolutePosition, (float)thisSpGain);
353 if (!m_scene.TryGetSceneObjectPart(objectID, out part))
356 part.SoundQueueing = shouldQueue;
void SetSoundQueueing(UUID objectID, bool shouldQueue)
Set whether sounds on the given prim should be queued.
IClientAPI ControllingClient
bool HasPrivateAttachmentPoint
If this scene object has an attachment point then indicate whether there is a point where attachments...
void SendSound(UUID objectID, UUID soundID, double volume, bool triggered, byte flags, float radius, bool useMaster, bool isMaster)
Trigger or play an attached sound in this part's inventory.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
virtual void TriggerSound(UUID soundId, UUID ownerID, UUID objectID, UUID parentID, double gain, Vector3 position, UInt64 handle, float radius)
Trigger a sound in the scene.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void LoopSound(UUID objectID, UUID soundID, double volume, double radius, bool isMaster, bool isSlave)
Loop specified sound at specified volume with specified radius, optionally declaring object as new sy...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
override Vector3 AbsolutePosition
Position of this avatar relative to the region the avatar is in
virtual void StopSound(UUID objectID)
Stop sounds eminating from an object.
Interactive OpenSim region server
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
virtual void PlayAttachedSound(UUID soundID, UUID ownerID, UUID objectID, double gain, Vector3 position, byte flags, float radius)
Play a sound from an object.
void Initialise(IConfigSource configSource)
This is called to initialize the region module. For shared modules, this is called exactly once...
UUID AttachedAvatar
The avatar to which this scene object is attached.
virtual void PreloadSound(UUID objectID, UUID soundID, float radius)
Preload sound to viewers within range.
void SendPreLoadSound(UUID objectID, UUID ownerID, UUID soundID)
bool IsAttachment
Is this scene object acting as an attachment?
void TriggerSoundLimited(UUID objectID, UUID sound, double volume, Vector3 min, Vector3 max)
Trigger a sound to be played to all agents within an axis-aligned bounding box.
void ScheduleFullUpdate()
Schedules this prim for a full update