modulate collision sound intensity with collision relative velocity for parts also

avinationmerge
UbitUmarov 2012-05-19 02:04:10 +01:00
parent 98a2c7bfee
commit 9ecdef2686
2 changed files with 89 additions and 46 deletions

View File

@ -114,12 +114,9 @@ namespace OpenSim.Region.Framework.Scenes
snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber
};
public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders)
public static void PartCollisionSound(SceneObjectPart part, List<CollisionForSoundInfo> collidersinfolist)
{
// temporary mute sounds
// return;
if(Colliders.Count == 0 || part == null)
if (collidersinfolist.Count == 0 || part == null)
return;
if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
@ -128,19 +125,20 @@ namespace OpenSim.Region.Framework.Scenes
if (part.ParentGroup == null)
return;
if (part.CollisionSound == part.invalidCollisionSoundUUID)
UUID soundID = part.CollisionSound;
if (soundID == part.invalidCollisionSoundUUID)
return;
UUID soundID;
float volume = 0.0f;
int otherMaterial;
bool HaveSound = false;
Vector3 position = part.AbsolutePosition;
if (part.CollisionSound != UUID.Zero)
if (soundID != UUID.Zero)
{
if (part.CollisionSoundVolume > 0.0f)
part.SendCollisionSound(part.CollisionSound, part.CollisionSoundVolume, position);
return;
volume = part.CollisionSoundVolume;
if (volume == 0.0f)
return;
HaveSound = true;
}
int thisMaterial = (int) part.Material;
@ -152,41 +150,73 @@ namespace OpenSim.Region.Framework.Scenes
bool doneownsound = false;
foreach (uint Id in Colliders)
CollisionForSoundInfo colInfo;
uint id;
for(int i = 0; i< collidersinfolist.Count; i++)
{
if (Id == 0)
colInfo = collidersinfolist[i];
if (!HaveSound)
{
volume = Math.Abs(colInfo.relativeVel);
if (volume < 0.2f)
continue;
}
id = colInfo.colliderID;
if (id == 0)
{
if (!doneownsound)
{
soundID = m_TerrainPart[thisMaterial];
part.SendCollisionSound(soundID, 1.0, position);
if (!HaveSound)
{
volume *= volume * .0625f; // 4m/s == full volume
if (volume > 1.0f)
volume = 1.0f;
soundID = m_TerrainPart[thisMaterial];
}
part.SendCollisionSound(soundID, volume, colInfo.position);
doneownsound = true;
}
continue;
}
SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(Id);
SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(id);
if (otherPart != null)
{
if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive)
continue;
if (otherPart.CollisionSound != UUID.Zero)
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position);
else
if (!HaveSound)
{
otherMaterial = (int)otherPart.Material;
if (otherMaterial >= MaxMaterials)
otherMaterial = 3;
index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index];
if (doneownsound)
otherPart.SendCollisionSound(soundID, 1.0, position);
if (otherPart.CollisionSound != UUID.Zero)
{
soundID = otherPart.CollisionSound;
volume = otherPart.CollisionSoundVolume;
if (volume == 0.0f)
continue;
}
else
{
part.SendCollisionSound(soundID, 1.0, position);
doneownsound = true;
volume *= volume * .0625f; // 4m/s == full volume
if (volume > 1.0f)
volume = 1.0f;
otherMaterial = (int)otherPart.Material;
if (otherMaterial >= MaxMaterials)
otherMaterial = 3;
index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index];
}
}
if (doneownsound)
otherPart.SendCollisionSound(soundID, volume, colInfo.position);
else
{
part.SendCollisionSound(soundID, volume, colInfo.position);
doneownsound = true;
}
}
}
}

View File

@ -333,7 +333,7 @@ namespace OpenSim.Region.Framework.Scenes
private UUID m_collisionSound;
private float m_collisionSoundVolume;
private DateTime LastColSoundSentTime;
private int LastColSoundSentTime;
private SOPVehicle m_vehicle = null;
@ -374,7 +374,7 @@ namespace OpenSim.Region.Framework.Scenes
// this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
// the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
m_inventory = new SceneObjectPartInventory(this);
LastColSoundSentTime = DateTime.UtcNow;
LastColSoundSentTime = Util.EnvironmentTickCount();
}
/// <summary>
@ -2632,13 +2632,29 @@ namespace OpenSim.Region.Framework.Scenes
else
{
List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
CollisionForSoundInfo soundinfo;
ContactPoint curcontact;
// calculate things that started colliding this time
// and build up list of colliders this time
foreach (uint localid in collissionswith.Keys)
foreach (uint id in collissionswith.Keys)
{
thisHitColliders.Add(localid);
if (!m_lastColliders.Contains(localid))
startedColliders.Add(localid);
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
{
startedColliders.Add(id);
curcontact = collissionswith[id];
if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
{
soundinfo = new CollisionForSoundInfo();
soundinfo.colliderID = id;
soundinfo.position = curcontact.Position;
soundinfo.relativeVel = curcontact.RelativeSpeed;
soundinfolist.Add(soundinfo);
}
}
}
// calculate things that ended colliding
@ -2655,17 +2671,14 @@ namespace OpenSim.Region.Framework.Scenes
// remove things that ended colliding from the last colliders list
foreach (uint localID in endedColliders)
m_lastColliders.Remove(localID);
// play sounds.
if (soundinfolist.Count > 0 && !VolumeDetectActive && CollisionSound != invalidCollisionSoundUUID)
CollisionSounds.PartCollisionSound(this, soundinfolist);
}
// play the sound.
bool IsNotVolumeDtc = !VolumeDetectActive;
if (IsNotVolumeDtc && startedColliders.Count > 0 && CollisionSound != invalidCollisionSoundUUID)
CollisionSounds.PartCollisionSound(this, startedColliders);
SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
if (IsNotVolumeDtc)
if (!VolumeDetectActive)
SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
@ -3210,8 +3223,8 @@ namespace OpenSim.Region.Framework.Scenes
if (volume < 0)
volume = 0;
DateTime now = DateTime.UtcNow;
if((now - LastColSoundSentTime).Milliseconds < 200) // reduce rate to 5 per sec per part ??
int now = Util.EnvironmentTickCount();
if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
return;
LastColSoundSentTime = now;