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

avinationmerge
UbitUmarov 2012-05-17 12:17:29 +01:00
parent e4231e95a9
commit 6af78836a5
2 changed files with 22 additions and 23 deletions

View File

@ -130,7 +130,7 @@ namespace OpenSim.Region.Framework.Scenes
if(Colliders.Count == 0 || part == null) if(Colliders.Count == 0 || part == null)
return; return;
if ((part.Flags & PrimFlags.Physics) == 0) // let only active prims trigger sounds if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
return; return;
if (part.ParentGroup == null) if (part.ParentGroup == null)
@ -142,6 +142,15 @@ namespace OpenSim.Region.Framework.Scenes
UUID soundID; UUID soundID;
int otherMaterial; 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; int thisMaterial = (int) part.Material;
if (thisMaterial >= MaxMaterials) if (thisMaterial >= MaxMaterials)
thisMaterial = 3; thisMaterial = 3;
@ -158,7 +167,7 @@ namespace OpenSim.Region.Framework.Scenes
if (!doneownsound) if (!doneownsound)
{ {
soundID = m_TerrainPart[thisMaterial]; soundID = m_TerrainPart[thisMaterial];
part.SendCollisionSound(soundID, 1.0); part.SendCollisionSound(soundID, 1.0, position);
doneownsound = true; doneownsound = true;
} }
continue; continue;
@ -170,7 +179,7 @@ namespace OpenSim.Region.Framework.Scenes
if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive) if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive)
continue; continue;
if (otherPart.CollisionSound != UUID.Zero) if (otherPart.CollisionSound != UUID.Zero)
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume); otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position);
else else
{ {
otherMaterial = (int)otherPart.Material; otherMaterial = (int)otherPart.Material;
@ -179,10 +188,10 @@ namespace OpenSim.Region.Framework.Scenes
index = thisMatScaled + otherMaterial; index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index]; soundID = m_PartPart[index];
if (doneownsound) if (doneownsound)
otherPart.SendCollisionSound(soundID, 1.0); otherPart.SendCollisionSound(soundID, 1.0, position);
else else
{ {
part.SendCollisionSound(soundID, 1.0); part.SendCollisionSound(soundID, 1.0, position);
doneownsound = true; doneownsound = true;
} }
} }
@ -217,6 +226,8 @@ namespace OpenSim.Region.Framework.Scenes
int index; int index;
// bool doneownsound = false; // bool doneownsound = false;
Vector3 position = av.AbsolutePosition;
foreach (uint Id in Colliders) foreach (uint Id in Colliders)
{ {
if (Id == 0) if (Id == 0)
@ -230,7 +241,7 @@ namespace OpenSim.Region.Framework.Scenes
if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID) if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID)
continue; continue;
if (otherPart.CollisionSound != UUID.Zero) if (otherPart.CollisionSound != UUID.Zero)
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume); otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position);
else else
{ {
otherMaterial = (int)otherPart.Material; otherMaterial = (int)otherPart.Material;
@ -238,7 +249,7 @@ namespace OpenSim.Region.Framework.Scenes
otherMaterial = 3; otherMaterial = 3;
index = thisMatScaled + otherMaterial; index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index]; soundID = m_PartPart[index];
otherPart.SendCollisionSound(soundID, 1.0); otherPart.SendCollisionSound(soundID, 1.0, position);
} }
} }
/* /*

View File

@ -2632,7 +2632,6 @@ namespace OpenSim.Region.Framework.Scenes
else else
{ {
// calculate things that started colliding this time // calculate things that started colliding this time
// and build up list of colliders this time // and build up list of colliders this time
foreach (uint localid in collissionswith.Keys) foreach (uint localid in collissionswith.Keys)
@ -2657,22 +2656,13 @@ namespace OpenSim.Region.Framework.Scenes
foreach (uint localID in endedColliders) foreach (uint localID in endedColliders)
m_lastColliders.Remove(localID); m_lastColliders.Remove(localID);
} }
// play the sound. // play the sound.
bool IsNotVolumeDtc = !VolumeDetectActive; bool IsNotVolumeDtc = !VolumeDetectActive;
if (IsNotVolumeDtc && startedColliders.Count > 0 && CollisionSound != invalidCollisionSoundUUID) if (IsNotVolumeDtc && startedColliders.Count > 0 && CollisionSound != invalidCollisionSoundUUID)
{ CollisionSounds.PartCollisionSound(this, startedColliders);
if (CollisionSound != UUID.Zero)
{
if (CollisionSoundVolume > 0.0f)
SendCollisionSound(CollisionSound, CollisionSoundVolume);
}
else
{
CollisionSounds.PartCollisionSound(this, startedColliders);
}
}
SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
if (IsNotVolumeDtc) 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) if (soundID == UUID.Zero)
return; return;
ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>(); ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>();
if (soundModule == null) if (soundModule == null)
return; return;
@ -3230,10 +3219,9 @@ namespace OpenSim.Region.Framework.Scenes
UUID ownerID = OwnerID; UUID ownerID = OwnerID;
UUID objectID = ParentGroup.RootPart.UUID; UUID objectID = ParentGroup.RootPart.UUID;
UUID parentID = ParentGroup.UUID; UUID parentID = ParentGroup.UUID;
Vector3 position = AbsolutePosition; // region local
ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle; 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 );
} }