From 6af78836a540c9b0a5972ab241364dae52e8e74d Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 17 May 2012 12:17:29 +0100 Subject: [PATCH] trigger collision sounds on active agent position for better spatial effect without using the detailed collision position. (current error will be half max physical prim size). Moved some checks from sop to collisionSound code --- .../Framework/Scenes/CollisionSounds.cs | 25 +++++++++++++------ .../Framework/Scenes/SceneObjectPart.cs | 20 +++------------ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs index c46756cf4d..5d4302730c 100644 --- a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs +++ b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs @@ -130,7 +130,7 @@ namespace OpenSim.Region.Framework.Scenes if(Colliders.Count == 0 || part == null) return; - if ((part.Flags & PrimFlags.Physics) == 0) // let only active prims trigger sounds + if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0) return; if (part.ParentGroup == null) @@ -142,6 +142,15 @@ namespace OpenSim.Region.Framework.Scenes UUID soundID; int otherMaterial; + Vector3 position = part.AbsolutePosition; + + if (part.CollisionSound != UUID.Zero) + { + if (part.CollisionSoundVolume > 0.0f) + part.SendCollisionSound(part.CollisionSound, part.CollisionSoundVolume, position); + return; + } + int thisMaterial = (int) part.Material; if (thisMaterial >= MaxMaterials) thisMaterial = 3; @@ -158,7 +167,7 @@ namespace OpenSim.Region.Framework.Scenes if (!doneownsound) { soundID = m_TerrainPart[thisMaterial]; - part.SendCollisionSound(soundID, 1.0); + part.SendCollisionSound(soundID, 1.0, position); doneownsound = true; } continue; @@ -170,7 +179,7 @@ namespace OpenSim.Region.Framework.Scenes if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive) continue; if (otherPart.CollisionSound != UUID.Zero) - otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume); + otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position); else { otherMaterial = (int)otherPart.Material; @@ -179,10 +188,10 @@ namespace OpenSim.Region.Framework.Scenes index = thisMatScaled + otherMaterial; soundID = m_PartPart[index]; if (doneownsound) - otherPart.SendCollisionSound(soundID, 1.0); + otherPart.SendCollisionSound(soundID, 1.0, position); else { - part.SendCollisionSound(soundID, 1.0); + part.SendCollisionSound(soundID, 1.0, position); doneownsound = true; } } @@ -217,6 +226,8 @@ namespace OpenSim.Region.Framework.Scenes int index; // bool doneownsound = false; + Vector3 position = av.AbsolutePosition; + foreach (uint Id in Colliders) { if (Id == 0) @@ -230,7 +241,7 @@ namespace OpenSim.Region.Framework.Scenes if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID) continue; if (otherPart.CollisionSound != UUID.Zero) - otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume); + otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position); else { otherMaterial = (int)otherPart.Material; @@ -238,7 +249,7 @@ namespace OpenSim.Region.Framework.Scenes otherMaterial = 3; index = thisMatScaled + otherMaterial; soundID = m_PartPart[index]; - otherPart.SendCollisionSound(soundID, 1.0); + otherPart.SendCollisionSound(soundID, 1.0, position); } } /* diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 5874d34159..b5705b7897 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2632,7 +2632,6 @@ namespace OpenSim.Region.Framework.Scenes else { - // calculate things that started colliding this time // and build up list of colliders this time foreach (uint localid in collissionswith.Keys) @@ -2657,22 +2656,13 @@ namespace OpenSim.Region.Framework.Scenes foreach (uint localID in endedColliders) m_lastColliders.Remove(localID); } + // play the sound. bool IsNotVolumeDtc = !VolumeDetectActive; if (IsNotVolumeDtc && startedColliders.Count > 0 && CollisionSound != invalidCollisionSoundUUID) - { - if (CollisionSound != UUID.Zero) - { - if (CollisionSoundVolume > 0.0f) - SendCollisionSound(CollisionSound, CollisionSoundVolume); - } - else - { - CollisionSounds.PartCollisionSound(this, startedColliders); - } - } + CollisionSounds.PartCollisionSound(this, startedColliders); SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); if (IsNotVolumeDtc) @@ -3206,12 +3196,11 @@ namespace OpenSim.Region.Framework.Scenes } } - public void SendCollisionSound(UUID soundID, double volume) + public void SendCollisionSound(UUID soundID, double volume, Vector3 position) { if (soundID == UUID.Zero) return; - ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface(); if (soundModule == null) return; @@ -3230,10 +3219,9 @@ namespace OpenSim.Region.Framework.Scenes UUID ownerID = OwnerID; UUID objectID = ParentGroup.RootPart.UUID; UUID parentID = ParentGroup.UUID; - Vector3 position = AbsolutePosition; // region local ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle; - soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, 0); + soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, 0 ); }