a bit faster collision sound type verification plus a few fixes/changes

avinationmerge
UbitUmarov 2012-05-19 13:53:49 +01:00
parent a2c64d9795
commit 2c498baf58
2 changed files with 100 additions and 53 deletions

View File

@ -197,30 +197,29 @@ namespace OpenSim.Region.Framework.Scenes
if (part.ParentGroup == null)
return;
UUID soundID = part.CollisionSound;
if (soundID == part.invalidCollisionSoundUUID)
if (part.CollisionSoundType < 0)
return;
float volume = 0.0f;
int otherMaterial;
bool HaveSound = false;
if (soundID != UUID.Zero)
UUID soundID = part.CollisionSound;
if (part.CollisionSoundType > 0)
{
// soundID = part.CollisionSound;
volume = part.CollisionSoundVolume;
if (volume == 0.0f)
return;
HaveSound = true;
}
int thisMaterial = (int) part.Material;
bool doneownsound = false;
int thisMaterial = (int)part.Material;
if (thisMaterial >= MaxMaterials)
thisMaterial = 3;
int thisMatScaled = thisMaterial * MaxMaterials;
int index;
bool doneownsound = false;
CollisionForSoundInfo colInfo;
uint id;
@ -229,23 +228,21 @@ namespace OpenSim.Region.Framework.Scenes
{
colInfo = collidersinfolist[i];
if (!HaveSound)
{
volume = Math.Abs(colInfo.relativeVel);
if (volume < 0.2f)
continue;
}
id = colInfo.colliderID;
if (id == 0)
if (id == 0) // terrain collision
{
if (!doneownsound)
{
if (!HaveSound)
{
volume = Math.Abs(colInfo.relativeVel);
if (volume < 0.2f)
continue;
volume *= volume * .0625f; // 4m/s == full volume
if (volume > 1.0f)
volume = 1.0f;
soundID = m_TerrainPart[thisMaterial];
}
part.SendCollisionSound(soundID, volume, colInfo.position);
@ -257,12 +254,12 @@ namespace OpenSim.Region.Framework.Scenes
SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(id);
if (otherPart != null)
{
if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive)
if (otherPart.CollisionSoundType < 0 || otherPart.VolumeDetectActive)
continue;
if (!HaveSound)
{
if (otherPart.CollisionSound != UUID.Zero)
if (otherPart.CollisionSoundType > 0)
{
soundID = otherPart.CollisionSound;
volume = otherPart.CollisionSoundVolume;
@ -271,14 +268,19 @@ namespace OpenSim.Region.Framework.Scenes
}
else
{
volume = Math.Abs(colInfo.relativeVel);
if (volume < 0.2f)
continue;
volume *= volume * .0625f; // 4m/s == full volume
if (volume > 1.0f)
volume = 1.0f;
otherMaterial = (int)otherPart.Material;
int otherMaterial = (int)otherPart.Material;
if (otherMaterial >= MaxMaterials)
otherMaterial = 3;
index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index];
soundID = m_PartPart[thisMatScaled + otherMaterial];
}
}
@ -301,11 +303,11 @@ namespace OpenSim.Region.Framework.Scenes
UUID soundID;
int otherMaterial;
int thisMaterial = 3;
int thisMaterial = 4; // flesh
int thisMatScaled = thisMaterial * MaxMaterials;
int index;
// bool doneownsound = false;
// bool doneownsound = false;
CollisionForSoundInfo colInfo;
uint id;
@ -315,36 +317,41 @@ namespace OpenSim.Region.Framework.Scenes
{
colInfo = collidersinfolist[i];
volume = Math.Abs(colInfo.relativeVel);
if(volume < 0.2f)
continue;
id = colInfo.colliderID;
if (id == 0) // no terrain collision sounds for now
{
continue;
// volume = Math.Abs(colInfo.relativeVel);
// if (volume < 0.2f)
// continue;
}
SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(id);
if (otherPart != null)
{
if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID)
if (otherPart.CollisionSoundType < 0)
continue;
if (otherPart.CollisionSound != UUID.Zero)
if (otherPart.CollisionSoundType > 0 && otherPart.CollisionSoundVolume > 0f)
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, colInfo.position);
else
{
volume = Math.Abs(colInfo.relativeVel);
if (volume < 0.2f)
continue;
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];
soundID = m_PartPart[thisMatScaled + otherMaterial];
otherPart.SendCollisionSound(soundID, volume, colInfo.position);
}
continue;
}
/*
else if (!doneownsound)

View File

@ -329,7 +329,9 @@ namespace OpenSim.Region.Framework.Scenes
private Vector3 m_cameraAtOffset;
private bool m_forceMouselook;
// TODO: Collision sound should have default.
// 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
private sbyte m_collisionSoundType;
private UUID m_collisionSound;
private float m_collisionSoundVolume;
@ -1342,12 +1344,39 @@ namespace OpenSim.Region.Framework.Scenes
public UUID invalidCollisionSoundUUID = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff");
// 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
// runtime thing.. do not persist
[XmlIgnore]
public sbyte CollisionSoundType
{
get
{
return m_collisionSoundType;
}
set
{
m_collisionSoundType = value;
if (value == -1)
m_collisionSound = invalidCollisionSoundUUID;
else if (value == 0)
m_collisionSound = UUID.Zero;
}
}
public UUID CollisionSound
{
get { return m_collisionSound; }
set
{
m_collisionSound = value;
if (value == invalidCollisionSoundUUID)
m_collisionSoundType = -1;
else if (value == UUID.Zero)
m_collisionSoundType = 0;
else
m_collisionSoundType = 1;
aggregateScriptEvents();
}
}
@ -2633,29 +2662,42 @@ 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 id in collissionswith.Keys)
if (!VolumeDetectActive && CollisionSoundType >= 0)
{
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
{
startedColliders.Add(id);
CollisionForSoundInfo soundinfo;
ContactPoint curcontact;
curcontact = collissionswith[id];
if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
foreach (uint id in collissionswith.Keys)
{
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
{
soundinfo = new CollisionForSoundInfo();
soundinfo.colliderID = id;
soundinfo.position = curcontact.Position;
soundinfo.relativeVel = curcontact.RelativeSpeed;
soundinfolist.Add(soundinfo);
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);
}
}
}
}
else
{
foreach (uint id in collissionswith.Keys)
{
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
startedColliders.Add(id);
}
}
// calculate things that ended colliding
foreach (uint localID in m_lastColliders)
@ -2673,7 +2715,7 @@ namespace OpenSim.Region.Framework.Scenes
m_lastColliders.Remove(localID);
// play sounds.
if (soundinfolist.Count > 0 && !VolumeDetectActive && CollisionSound != invalidCollisionSoundUUID)
if (soundinfolist.Count > 0)
CollisionSounds.PartCollisionSound(this, soundinfolist);
}
@ -4791,7 +4833,8 @@ namespace OpenSim.Region.Framework.Scenes
pa.OnCollisionUpdate -= PhysicsCollision;
bool hassound = ( CollisionSound != invalidCollisionSoundUUID);
bool hassound = (CollisionSoundType >= 0 && !VolumeDetectActive);
scriptEvents CombinedEvents = AggregateScriptEvents;
// merge with root part
@ -4800,10 +4843,7 @@ namespace OpenSim.Region.Framework.Scenes
// submit to this part case
if (VolumeDetectActive)
{
CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
hassound = false;
}
else if ((Flags & PrimFlags.Phantom) != 0)
CombinedEvents &= PhyscicsPhantonSubsEvents;
else