diff --git a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs index b1b0f5b768..81ca9f1ce9 100644 --- a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs +++ b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs @@ -33,45 +33,115 @@ using OpenSim.Framework; namespace OpenSim.Region.Framework.Scenes { + public struct CollisionForSoundInfo + { + public uint colliderID; + public Vector3 position; + public float relativeVel; + } + public static class CollisionSounds { - // defines for cases - // only know one UUID for now (woodflesh) - private const int MaxMaterials = 7; // part part - private static UUID snd_StoneStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_StoneMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_StoneGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_StoneWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_StoneFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_StonePlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_StoneRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); +/* + private static UUID snd_StoneStone = new UUID("be7295c0-a158-11e1-b3dd-0800200c9a66"); + private static UUID snd_StoneMetal = new UUID("be7295c0-a158-11e1-b3dd-0800201c9a66"); + private static UUID snd_StoneGlass = new UUID("be7295c0-a158-11e1-b3dd-0800202c9a66"); + private static UUID snd_StoneWood = new UUID("be7295c0-a158-11e1-b3dd-0800203c9a66"); + private static UUID snd_StoneFlesh = new UUID("be7295c0-a158-11e1-b3dd-0800204c9a66"); + private static UUID snd_StonePlastic = new UUID("be7295c0-a158-11e1-b3dd-0800205c9a66"); + private static UUID snd_StoneRubber = new UUID("be7295c0-a158-11e1-b3dd-0800206c9a66"); - private static UUID snd_MetalMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_MetalGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_MetalWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_MetalFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_MetalPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_MetalRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_MetalStone = new UUID("be7295c0-a158-11e1-b3dd-0801200c9a66"); + private static UUID snd_MetalMetal = new UUID("be7295c0-a158-11e1-b3dd-0801201c9a66"); + private static UUID snd_MetalGlass = new UUID("be7295c0-a158-11e1-b3dd-0801202c9a66"); + private static UUID snd_MetalWood = new UUID("be7295c0-a158-11e1-b3dd-0801203c9a66"); + private static UUID snd_MetalFlesh = new UUID("be7295c0-a158-11e1-b3dd-0801204c9a66"); + private static UUID snd_MetalPlastic = new UUID("be7295c0-a158-11e1-b3dd-0801205c9a66"); + private static UUID snd_MetalRubber = new UUID("be7295c0-a158-11e1-b3dd-0801206c9a66"); - private static UUID snd_GlassGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_GlassWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_GlassFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_GlassPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_GlassRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_GlassStone = new UUID("be7295c0-a158-11e1-b3dd-0802200c9a66"); + private static UUID snd_GlassMetal = new UUID("be7295c0-a158-11e1-b3dd-0802201c9a66"); + private static UUID snd_GlassGlass = new UUID("be7295c0-a158-11e1-b3dd-0802202c9a66"); + private static UUID snd_GlassWood = new UUID("be7295c0-a158-11e1-b3dd-0802203c9a66"); + private static UUID snd_GlassFlesh = new UUID("be7295c0-a158-11e1-b3dd-0802204c9a66"); + private static UUID snd_GlassPlastic = new UUID("be7295c0-a158-11e1-b3dd-0802205c9a66"); + private static UUID snd_GlassRubber = new UUID("be7295c0-a158-11e1-b3dd-0802206c9a66"); - private static UUID snd_WoodWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_WoodFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_WoodPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_WoodRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_WoodStone = new UUID("be7295c0-a158-11e1-b3dd-0803200c9a66"); + private static UUID snd_WoodMetal = new UUID("be7295c0-a158-11e1-b3dd-0803201c9a66"); + private static UUID snd_WoodGlass = new UUID("be7295c0-a158-11e1-b3dd-0803202c9a66"); + private static UUID snd_WoodWood = new UUID("be7295c0-a158-11e1-b3dd-0803203c9a66"); + private static UUID snd_WoodFlesh = new UUID("be7295c0-a158-11e1-b3dd-0803204c9a66"); + private static UUID snd_WoodPlastic = new UUID("be7295c0-a158-11e1-b3dd-0803205c9a66"); + private static UUID snd_WoodRubber = new UUID("be7295c0-a158-11e1-b3dd-0803206c9a66"); - private static UUID snd_FleshFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_FleshPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_FleshRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_FleshStone = new UUID("be7295c0-a158-11e1-b3dd-0804200c9a66"); + private static UUID snd_FleshMetal = new UUID("be7295c0-a158-11e1-b3dd-0804201c9a66"); + private static UUID snd_FleshGlass = new UUID("be7295c0-a158-11e1-b3dd-0804202c9a66"); + private static UUID snd_FleshWood = new UUID("be7295c0-a158-11e1-b3dd-0804203c9a66"); + private static UUID snd_FleshFlesh = new UUID("be7295c0-a158-11e1-b3dd-0804204c9a66"); + private static UUID snd_FleshPlastic = new UUID("be7295c0-a158-11e1-b3dd-0804205c9a66"); + private static UUID snd_FleshRubber = new UUID("be7295c0-a158-11e1-b3dd-0804206c9a66"); - private static UUID snd_PlasticPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); - private static UUID snd_PlasticRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_PlasticStone = new UUID("be7295c0-a158-11e1-b3dd-0805200c9a66"); + private static UUID snd_PlasticMetal = new UUID("be7295c0-a158-11e1-b3dd-0805201c9a66"); + private static UUID snd_PlasticGlass = new UUID("be7295c0-a158-11e1-b3dd-0805202c9a66"); + private static UUID snd_PlasticWood = new UUID("be7295c0-a158-11e1-b3dd-0805203c9a66"); + private static UUID snd_PlasticFlesh = new UUID("be7295c0-a158-11e1-b3dd-0805204c9a66"); + private static UUID snd_PlasticPlastic = new UUID("be7295c0-a158-11e1-b3dd-0805205c9a66"); + private static UUID snd_PlasticRubber = new UUID("be7295c0-a158-11e1-b3dd-0805206c9a66"); + + private static UUID snd_RubberStone = new UUID("be7295c0-a158-11e1-b3dd-0806200c9a66"); + private static UUID snd_RubberMetal = new UUID("be7295c0-a158-11e1-b3dd-0806201c9a66"); + private static UUID snd_RubberGlass = new UUID("be7295c0-a158-11e1-b3dd-0806202c9a66"); + private static UUID snd_RubberWood = new UUID("be7295c0-a158-11e1-b3dd-0806203c9a66"); + private static UUID snd_RubberFlesh = new UUID("be7295c0-a158-11e1-b3dd-0806204c9a66"); + private static UUID snd_RubberPlastic = new UUID("be7295c0-a158-11e1-b3dd-0806205c9a66"); + private static UUID snd_RubberRubber = new UUID("be7295c0-a158-11e1-b3dd-0806206c9a66"); + + // terrain part + private static UUID snd_TerrainStone = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); + private static UUID snd_TerrainMetal = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); + private static UUID snd_TerrainGlass = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); + private static UUID snd_TerrainWood = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); + private static UUID snd_TerrainFlesh = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); + private static UUID snd_TerrainPlastic = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); + private static UUID snd_TerrainRubber = new UUID("be7295c0-a158-11e1-b3dd-0807200c9a66"); +*/ + private static UUID snd_StoneStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_StoneMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_StoneGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_StoneWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_StoneFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_StonePlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_StoneRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + + private static UUID snd_MetalMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_MetalGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_MetalWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_MetalFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_MetalPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_MetalRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + + private static UUID snd_GlassGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_GlassWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_GlassFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_GlassPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_GlassRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + + private static UUID snd_WoodWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_WoodFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_WoodPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_WoodRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + + private static UUID snd_FleshFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_FleshPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_FleshRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + + private static UUID snd_PlasticPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); + private static UUID snd_PlasticRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_RubberRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); @@ -93,7 +163,19 @@ namespace OpenSim.Region.Framework.Scenes snd_TerrainPlastic, snd_TerrainRubber }; - +/* + //full assimetric sounds + public static UUID[] m_PartPart = { + snd_StoneStone, snd_StoneMetal, snd_StoneGlass, snd_StoneWood, snd_StoneFlesh, snd_StonePlastic, snd_StoneRubber, + snd_MetalStone, snd_MetalMetal, snd_MetalGlass, snd_MetalWood, snd_MetalFlesh, snd_MetalPlastic, snd_MetalRubber, + snd_GlassStone, snd_GlassMetal, snd_GlassGlass, snd_GlassWood, snd_GlassFlesh, snd_GlassPlastic, snd_GlassRubber, + snd_WoodStone, snd_WoodMetal, snd_WoodGlass, snd_WoodWood, snd_WoodFlesh, snd_WoodPlastic, snd_WoodRubber, + snd_FleshStone, snd_FleshMetal, snd_FleshGlass, snd_FleshWood, snd_FleshFlesh, snd_FleshPlastic, snd_FleshRubber, + snd_PlasticStone, snd_PlasticMetal, snd_PlasticGlass, snd_PlasticWood, snd_PlasticFlesh, snd_PlasticPlastic, snd_PlasticRubber, + snd_RubberStone, snd_RubberMetal, snd_RubberGlass, snd_RubberWood, snd_RubberFlesh, snd_RubberPlastic, snd_RubberRubber + }; +*/ + // simetric sounds public static UUID[] m_PartPart = { snd_StoneStone, snd_StoneMetal, snd_StoneGlass, snd_StoneWood, snd_StoneFlesh, snd_StonePlastic, snd_StoneRubber, snd_StoneMetal, snd_MetalMetal, snd_MetalGlass, snd_MetalWood, snd_MetalFlesh, snd_MetalPlastic, snd_MetalRubber, @@ -103,13 +185,10 @@ namespace OpenSim.Region.Framework.Scenes snd_StonePlastic, snd_MetalPlastic, snd_GlassPlastic, snd_WoodPlastic, snd_FleshPlastic, snd_PlasticPlastic, snd_PlasticRubber, snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber }; - - public static void PartCollisionSound(SceneObjectPart part,List Colliders) + + public static void PartCollisionSound(SceneObjectPart part, List 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) @@ -118,124 +197,161 @@ namespace OpenSim.Region.Framework.Scenes if (part.ParentGroup == null) return; - if (part.CollisionSound == part.invalidCollisionSoundUUID) + if (part.CollisionSoundType < 0) return; - UUID soundID; - int otherMaterial; + float volume = 0.0f; + bool HaveSound = false; - Vector3 position = part.AbsolutePosition; + UUID soundID = part.CollisionSound; - if (part.CollisionSound != UUID.Zero) + if (part.CollisionSoundType > 0) { - if (part.CollisionSoundVolume > 0.0f) - part.SendCollisionSound(part.CollisionSound, part.CollisionSoundVolume, position); - return; + // soundID = part.CollisionSound; + volume = part.CollisionSoundVolume; + if (volume == 0.0f) + return; + HaveSound = true; } - int thisMaterial = (int) part.Material; - if (thisMaterial >= MaxMaterials) - thisMaterial = 3; - - int thisMatScaled = thisMaterial * MaxMaterials; - int index; - bool doneownsound = false; - foreach (uint Id in Colliders) + int thisMaterial = (int)part.Material; + if (thisMaterial >= MaxMaterials) + thisMaterial = 3; + int thisMatScaled = thisMaterial * MaxMaterials; + + CollisionForSoundInfo colInfo; + uint id; + + for(int i = 0; i< collidersinfolist.Count; i++) { - if (Id == 0) + colInfo = collidersinfolist[i]; + + id = colInfo.colliderID; + if (id == 0) // terrain collision { if (!doneownsound) { - soundID = m_TerrainPart[thisMaterial]; - part.SendCollisionSound(soundID, 1.0, position); + 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); 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) + if (otherPart.CollisionSoundType < 0 || 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.CollisionSoundType > 0) + { + soundID = otherPart.CollisionSound; + volume = otherPart.CollisionSoundVolume; + if (volume == 0.0f) + continue; + } else { - part.SendCollisionSound(soundID, 1.0, position); - doneownsound = true; + volume = Math.Abs(colInfo.relativeVel); + if (volume < 0.2f) + continue; + + volume *= volume * .0625f; // 4m/s == full volume + if (volume > 1.0f) + volume = 1.0f; + + int otherMaterial = (int)otherPart.Material; + if (otherMaterial >= MaxMaterials) + otherMaterial = 3; + + soundID = m_PartPart[thisMatScaled + otherMaterial]; } } - } -/* avatars get notification let them trigger the sound - else if (!doneownsound) - { - ScenePresence av = part.ParentGroup.Scene.GetScenePresence(Id); - if (av != null && (!av.IsChildAgent)) + + if (doneownsound) + otherPart.SendCollisionSound(soundID, volume, colInfo.position); + else { - index = thisMatScaled + 4; // flesh - soundID = m_PartPart[index]; - part.SendCollisionSound(soundID, 1.0); + part.SendCollisionSound(soundID, volume, colInfo.position); doneownsound = true; } } - */ } } - public static void AvatarCollisionSound(ScenePresence av, List Colliders) + public static void AvatarCollisionSound(ScenePresence av, List collidersinfolist) { - // temporary mute sounds - return; - - if (Colliders.Count == 0 || av == null) + if (collidersinfolist.Count == 0 || av == null) return; UUID soundID; int otherMaterial; - int thisMaterial = 3; + int thisMaterial = 4; // flesh int thisMatScaled = thisMaterial * MaxMaterials; - int index; -// bool doneownsound = false; - Vector3 position = av.AbsolutePosition; + // bool doneownsound = false; - foreach (uint Id in Colliders) + CollisionForSoundInfo colInfo; + uint id; + float volume; + + for(int i = 0; i< collidersinfolist.Count; i++) { - if (Id == 0) + colInfo = collidersinfolist[i]; + + 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); + SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(id); if (otherPart != null) { - if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID) + if (otherPart.CollisionSoundType < 0) continue; - if (otherPart.CollisionSound != UUID.Zero) - otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position); + 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]; - otherPart.SendCollisionSound(soundID, 1.0, position); + + soundID = m_PartPart[thisMatScaled + otherMaterial]; + otherPart.SendCollisionSound(soundID, volume, colInfo.position); } + continue; } /* else if (!doneownsound) @@ -251,6 +367,5 @@ namespace OpenSim.Region.Framework.Scenes */ } } - } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index b5705b7897..2852c4b5a2 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -329,11 +329,13 @@ 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; - private DateTime LastColSoundSentTime; + private int LastColSoundSentTime; private SOPVehicle m_vehicle = null; @@ -374,7 +376,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(); } /// @@ -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(); } } @@ -1575,7 +1604,10 @@ namespace OpenSim.Region.Framework.Scenes } } else if (PhysActor == null) + { ApplyPhysics((uint)Flags, VolumeDetectActive, false); + UpdatePhysicsSubscribedEvents(); + } else { PhysActor.PhysicsShapeType = m_physicsShapeType; @@ -2632,13 +2664,42 @@ namespace OpenSim.Region.Framework.Scenes else { + List soundinfolist = new List(); + // calculate things that started colliding this time // and build up list of colliders this time - foreach (uint localid in collissionswith.Keys) + if (!VolumeDetectActive && CollisionSoundType >= 0) { - thisHitColliders.Add(localid); - if (!m_lastColliders.Contains(localid)) - startedColliders.Add(localid); + CollisionForSoundInfo soundinfo; + ContactPoint curcontact; + + foreach (uint id in collissionswith.Keys) + { + 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); + } + } + } + } + else + { + foreach (uint id in collissionswith.Keys) + { + thisHitColliders.Add(id); + if (!m_lastColliders.Contains(id)) + startedColliders.Add(id); + } } // calculate things that ended colliding @@ -2655,17 +2716,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) + 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 +3268,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; @@ -4609,7 +4667,15 @@ namespace OpenSim.Region.Framework.Scenes /// public void RemoveFromPhysics() { - ParentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); + PhysicsActor pa = PhysActor; + if (pa != null) + { + pa.OnCollisionUpdate -= PhysicsCollision; + pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; + pa.OnOutOfBounds -= PhysicsOutOfBounds; + + ParentGroup.Scene.PhysicsScene.RemovePrim(pa); + } PhysActor = null; } @@ -4778,7 +4844,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 @@ -4787,10 +4854,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 diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index ebddf21032..5a3b518d99 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2032,7 +2032,7 @@ namespace OpenSim.Region.Framework.Scenes // m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied); if (PhysicsActor != null) - m_sitAvatarHeight = PhysicsActor.Size.Z; + m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f; bool canSit = false; pos = part.AbsolutePosition + offset; @@ -4098,6 +4098,7 @@ namespace OpenSim.Region.Framework.Scenes private void RaiseCollisionScriptEvents(Dictionary coldata) { + /* lock(m_collisionEventLock) { if (m_collisionEventFlag) @@ -4107,76 +4108,106 @@ namespace OpenSim.Region.Framework.Scenes Util.FireAndForget(delegate(object x) { + */ try { List thisHitColliders = new List(); List endedColliders = new List(); List startedColliders = new List(); + List soundinfolist = new List(); + CollisionForSoundInfo soundinfo; + ContactPoint curcontact; - foreach (uint localid in coldata.Keys) + if (coldata.Count == 0) { - thisHitColliders.Add(localid); - if (!m_lastColliders.Contains(localid)) - { - startedColliders.Add(localid); - } - //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); - } - - // calculate things that ended colliding - foreach (uint localID in m_lastColliders) - { - if (!thisHitColliders.Contains(localID)) + if (m_lastColliders.Count == 0) + return; // nothing to do + + foreach (uint localID in m_lastColliders) { endedColliders.Add(localID); } - } - //add the items that started colliding this time to the last colliders list. - foreach (uint localID in startedColliders) - { - m_lastColliders.Add(localID); - } - // remove things that ended colliding from the last colliders list - foreach (uint localID in endedColliders) - { - m_lastColliders.Remove(localID); + m_lastColliders.Clear(); } - // do event notification - if (startedColliders.Count > 0) + else { - CollisionSounds.AvatarCollisionSound(this, startedColliders); - - ColliderArgs StartCollidingMessage = new ColliderArgs(); - List colliding = new List(); - foreach (uint localId in startedColliders) + foreach (uint id in coldata.Keys) { - if (localId == 0) - continue; - - SceneObjectPart obj = Scene.GetSceneObjectPart(localId); - string data = ""; - if (obj != null) + thisHitColliders.Add(id); + if (!m_lastColliders.Contains(id)) { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = obj.UUID; - detobj.nameStr = obj.Name; - detobj.ownerUUID = obj.OwnerID; - detobj.posVector = obj.AbsolutePosition; - detobj.rotQuat = obj.GetWorldRotation(); - detobj.velVector = obj.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = obj.GroupID; - colliding.Add(detobj); + startedColliders.Add(id); + curcontact = coldata[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); + } } + //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); } - if (colliding.Count > 0) + // calculate things that ended colliding + foreach (uint localID in m_lastColliders) { - StartCollidingMessage.Colliders = colliding; + if (!thisHitColliders.Contains(localID)) + { + endedColliders.Add(localID); + } + } + //add the items that started colliding this time to the last colliders list. + foreach (uint localID in startedColliders) + { + m_lastColliders.Add(localID); + } + // remove things that ended colliding from the last colliders list + foreach (uint localID in endedColliders) + { + m_lastColliders.Remove(localID); + } - foreach (SceneObjectGroup att in GetAttachments()) - Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); + if (soundinfolist.Count > 0) + CollisionSounds.AvatarCollisionSound(this, soundinfolist); + + // do event notification + if (startedColliders.Count > 0) + { + + ColliderArgs StartCollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in startedColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + StartCollidingMessage.Colliders = colliding; + + foreach (SceneObjectGroup att in GetAttachments()) + Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); + } } } @@ -4257,7 +4288,7 @@ namespace OpenSim.Region.Framework.Scenes { m_collisionEventFlag = false; } - }); +// }); } private void TeleportFlagsDebug() { diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index b66d7f1152..fb90887f6d 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -59,12 +59,14 @@ namespace OpenSim.Region.Physics.Manager public Vector3 Position; public Vector3 SurfaceNormal; public float PenetrationDepth; + public float RelativeSpeed; public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth) { Position = position; SurfaceNormal = surfaceNormal; PenetrationDepth = penetrationDepth; + RelativeSpeed = 0f; // for now let this one be set explicity } } diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs index b0711d786d..1084b0e2a7 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs @@ -128,9 +128,10 @@ namespace OpenSim.Region.Physics.OdePlugin public d.Mass ShellMass; // public bool collidelock = false; - private bool m_haseventsubscription = false; public int m_eventsubscription = 0; - private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); + private int m_cureventsubscription = 0; + private CollisionEventUpdate CollisionEventsThisFrame = null; + private bool SentEmptyCollisionsEvent; // unique UUID of this character object public UUID m_uuid; @@ -239,7 +240,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override bool IsPhysical { - get { return false; } + get { return m_isPhysical; } set { return; } } @@ -783,8 +784,6 @@ namespace OpenSim.Region.Physics.OdePlugin // the Amotor still lets avatar rotation to drift during colisions // so force it back to identity - - d.Quaternion qtmp; qtmp.W = 1; @@ -903,6 +902,7 @@ namespace OpenSim.Region.Physics.OdePlugin contact.SurfaceNormal.X = 0f; contact.SurfaceNormal.Y = 0f; contact.SurfaceNormal.Z = -1f; + contact.RelativeSpeed = -vel.Z; AddCollisionEvent(0, contact); vec.Z *= 0.5f; @@ -1119,47 +1119,71 @@ namespace OpenSim.Region.Physics.OdePlugin public override void SubscribeEvents(int ms) { - m_requestedUpdateFrequency = ms; m_eventsubscription = ms; - _parent_scene.AddCollisionEventReporting(this); - m_haseventsubscription = true; + m_cureventsubscription = 0; + if (CollisionEventsThisFrame == null) + CollisionEventsThisFrame = new CollisionEventUpdate(); + SentEmptyCollisionsEvent = false; } public override void UnSubscribeEvents() { - m_haseventsubscription = false; - _parent_scene.RemoveCollisionEventReporting(this); - m_requestedUpdateFrequency = 0; + if (CollisionEventsThisFrame != null) + { + CollisionEventsThisFrame.Clear(); + CollisionEventsThisFrame = null; + } m_eventsubscription = 0; } public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) { - if (m_haseventsubscription) - { - // m_log.DebugFormat( - // "[PHYSICS]: Adding collision event for {0}, collidedWith {1}, contact {2}", "", CollidedWith, contact); - - CollisionEventsThisFrame.AddCollider(CollidedWith, contact); - } + if (CollisionEventsThisFrame == null) + CollisionEventsThisFrame = new CollisionEventUpdate(); + CollisionEventsThisFrame.AddCollider(CollidedWith, contact); } public void SendCollisions() { - if (m_haseventsubscription && m_eventsubscription > m_requestedUpdateFrequency) + if (CollisionEventsThisFrame == null) + return; + + if (m_cureventsubscription < m_eventsubscription) + return; + + m_cureventsubscription = 0; + + int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; + + if (!SentEmptyCollisionsEvent || ncolisions > 0) { - if (CollisionEventsThisFrame != null) + base.SendCollisionUpdate(CollisionEventsThisFrame); + + if (ncolisions == 0) { - base.SendCollisionUpdate(CollisionEventsThisFrame); + SentEmptyCollisionsEvent = true; + _parent_scene.RemoveCollisionEventReporting(this); } - CollisionEventsThisFrame = new CollisionEventUpdate(); - m_eventsubscription = 0; - } + else + { + SentEmptyCollisionsEvent = false; + CollisionEventsThisFrame.Clear(); + } + } + } + + internal void AddCollisionFrameTime(int t) + { + // protect it from overflow crashing + if (m_cureventsubscription < 50000) + m_cureventsubscription += t; } public override bool SubscribedEvents() { - return m_haseventsubscription; + if (m_eventsubscription > 0) + return true; + return false; } private void changePhysicsStatus(bool NewStatus) @@ -1465,14 +1489,5 @@ namespace OpenSim.Region.Physics.OdePlugin { _parent_scene.AddChange((PhysicsActor)this, what, arg); } - - - internal void AddCollisionFrameTime(int p) - { - // protect it from overflow crashing - if (m_eventsubscription + p >= int.MaxValue) - m_eventsubscription = 0; - m_eventsubscription += p; - } } } diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 5db4f1753e..62fd279464 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs @@ -477,58 +477,58 @@ namespace OpenSim.Region.Physics.OdePlugin // if(childPrim) we only know about physical linksets return Ptot; - /* - float tmass = _mass; - Ptot *= tmass; +/* + float tmass = _mass; + Ptot *= tmass; - float m; + float m; - foreach (OdePrim prm in childrenPrim) - { - m = prm._mass; - Ptot += prm.CenterOfMass * m; - tmass += m; - } + foreach (OdePrim prm in childrenPrim) + { + m = prm._mass; + Ptot += prm.CenterOfMass * m; + tmass += m; + } - if (tmass == 0) - tmass = 0; - else - tmass = 1.0f / tmass; + if (tmass == 0) + tmass = 0; + else + tmass = 1.0f / tmass; - Ptot *= tmass; - return Ptot; - */ + Ptot *= tmass; + return Ptot; +*/ } else return _position; } } } - /* - public override Vector3 PrimOOBsize - { - get - { - return primOOBsize; - } - } +/* + public override Vector3 PrimOOBsize + { + get + { + return primOOBsize; + } + } - public override Vector3 PrimOOBoffset - { - get - { - return primOOBoffset; - } - } + public override Vector3 PrimOOBoffset + { + get + { + return primOOBoffset; + } + } - public override float PrimOOBRadiusSQ - { - get - { - return primOOBradiusSQ; - } - } - */ + public override float PrimOOBRadiusSQ + { + get + { + return primOOBradiusSQ; + } + } +*/ public override PrimitiveBaseShape Shape { set @@ -582,7 +582,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (value.IsFinite()) { AddChange(changes.Velocity, value); - // _velocity = value; +// _velocity = value; } else @@ -937,12 +937,10 @@ namespace OpenSim.Region.Physics.OdePlugin if (CollisionEventsThisFrame == null) CollisionEventsThisFrame = new CollisionEventUpdate(); SentEmptyCollisionsEvent = false; - _parent_scene.AddCollisionEventReporting(this); } public override void UnSubscribeEvents() { - _parent_scene.RemoveCollisionEventReporting(this); if (CollisionEventsThisFrame != null) { CollisionEventsThisFrame.Clear(); @@ -975,7 +973,10 @@ namespace OpenSim.Region.Physics.OdePlugin base.SendCollisionUpdate(CollisionEventsThisFrame); if (ncolisions == 0) + { SentEmptyCollisionsEvent = true; + _parent_scene.RemoveCollisionEventReporting(this); + } else { SentEmptyCollisionsEvent = false; @@ -986,11 +987,10 @@ namespace OpenSim.Region.Physics.OdePlugin internal void AddCollisionFrameTime(int t) { - // protect it from overflow crashing - if (m_cureventsubscription + t >= int.MaxValue) - m_cureventsubscription = 0; - m_cureventsubscription += t; + if (m_cureventsubscription < 50000) + m_cureventsubscription += t; } + public override bool SubscribedEvents() { if (m_eventsubscription > 0) @@ -1735,8 +1735,8 @@ namespace OpenSim.Region.Physics.OdePlugin d.BodySetAutoDisableFlag(Body, true); d.BodySetAutoDisableSteps(Body, body_autodisable_frames); - // d.BodySetLinearDampingThreshold(Body, 0.01f); - // d.BodySetAngularDampingThreshold(Body, 0.001f); +// d.BodySetLinearDampingThreshold(Body, 0.01f); +// d.BodySetAngularDampingThreshold(Body, 0.001f); d.BodySetDamping(Body, .002f, .002f); if (m_targetSpace != IntPtr.Zero) @@ -2966,7 +2966,7 @@ namespace OpenSim.Region.Physics.OdePlugin givefakepos--; if (givefakepos < 0) givefakepos = 0; - // changeSelectedStatus(); +// changeSelectedStatus(); resetCollisionAccounting(); } @@ -2981,14 +2981,14 @@ namespace OpenSim.Region.Physics.OdePlugin { _orientation = newOri; } - /* - else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero) - { - FixInertia(_position, newOri); - if (!d.BodyIsEnabled(Body)) - d.BodyEnable(Body); - } - */ +/* + else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero) + { + FixInertia(_position, newOri); + if (!d.BodyIsEnabled(Body)) + d.BodyEnable(Body); + } +*/ } else { @@ -3939,12 +3939,12 @@ namespace OpenSim.Region.Physics.OdePlugin changevelocity((Vector3)arg); break; - // case changes.Acceleration: - // changeacceleration((Vector3)arg); - // break; - // case changes.AngVelocity: - // changeangvelocity((Vector3)arg); - // break; +// case changes.Acceleration: +// changeacceleration((Vector3)arg); +// break; +// case changes.AngVelocity: +// changeangvelocity((Vector3)arg); +// break; case changes.Force: changeForce((Vector3)arg); diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index ddfdea4f6c..bfcfd21a97 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs @@ -190,6 +190,7 @@ namespace OpenSim.Region.Physics.OdePlugin public float ODE_STEPSIZE = 0.020f; public float HalfOdeStep = 0.01f; + public int odetimestepMS = 20; // rounded private float metersInSpace = 25.6f; private float m_timeDilation = 1.0f; @@ -247,6 +248,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// A list of actors that should receive collision events. /// private readonly List _collisionEventPrim = new List(); + private readonly List _collisionEventPrimRemove = new List(); private readonly HashSet _badCharacter = new HashSet(); public Dictionary geom_name_map = new Dictionary(); @@ -489,6 +491,7 @@ namespace OpenSim.Region.Physics.OdePlugin } HalfOdeStep = ODE_STEPSIZE * 0.5f; + odetimestepMS = (int)(1000.0f * ODE_STEPSIZE +0.5f); ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); @@ -1064,7 +1067,7 @@ namespace OpenSim.Region.Physics.OdePlugin obj2LocalID = 0; bool p1events = p1.SubscribedEvents(); bool p2events = p2.SubscribedEvents(); - + if (p1.IsVolumeDtc) p2events = false; if (p2.IsVolumeDtc) @@ -1073,6 +1076,21 @@ namespace OpenSim.Region.Physics.OdePlugin if (!(p2events || p1events)) return; + if (p1events) + AddCollisionEventReporting(p1); + + if (p2events) + AddCollisionEventReporting(p2); + + Vector3 vel = Vector3.Zero; + if (p2 != null && p2.IsPhysical) + vel = p2.Velocity; + + if (p1 != null && p1.IsPhysical) + vel -= p1.Velocity; + + contact.RelativeSpeed = Vector3.Dot(vel, contact.SurfaceNormal); + switch ((ActorTypes)p1.PhysicsActorType) { case ActorTypes.Agent: @@ -1246,20 +1264,14 @@ namespace OpenSim.Region.Physics.OdePlugin } #endregion - - - /// /// Add actor to the list that should receive collision events in the simulate loop. /// /// public void AddCollisionEventReporting(PhysicsActor obj) { - lock (_collisionEventPrim) - { - if (!_collisionEventPrim.Contains(obj)) - _collisionEventPrim.Add(obj); - } + if (!_collisionEventPrim.Contains(obj)) + _collisionEventPrim.Add(obj); } /// @@ -1268,13 +1280,11 @@ namespace OpenSim.Region.Physics.OdePlugin /// public void RemoveCollisionEventReporting(PhysicsActor obj) { - lock (_collisionEventPrim) - { - if (_collisionEventPrim.Contains(obj)) - _collisionEventPrim.Remove(obj); - } + if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj)) + _collisionEventPrimRemove.Add(obj); } + #region Add/Remove Entities public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) @@ -1463,6 +1473,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // lock (OdeLock) { + OdePrim p = (OdePrim)prim; p.setPrimForRemoval(); } @@ -1818,7 +1829,6 @@ namespace OpenSim.Region.Physics.OdePlugin { int ttmpstart = Util.EnvironmentTickCount(); int ttmp; - int ttmp2; while(ChangesQueue.Dequeue(out item)) { @@ -1840,11 +1850,6 @@ namespace OpenSim.Region.Physics.OdePlugin if (ttmp > 20) break; } - - ttmp2 = Util.EnvironmentTickCountSubtract(ttmpstart); - if (ttmp2 > 50) - ttmp2 = 0; - } // Move characters @@ -1881,53 +1886,55 @@ namespace OpenSim.Region.Physics.OdePlugin collision_optimized(); - lock (_collisionEventPrim) + foreach (PhysicsActor obj in _collisionEventPrim) { - foreach (PhysicsActor obj in _collisionEventPrim) + if (obj == null) + continue; + + switch ((ActorTypes)obj.PhysicsActorType) { - if (obj == null) - continue; + case ActorTypes.Agent: + OdeCharacter cobj = (OdeCharacter)obj; + cobj.AddCollisionFrameTime((int)(odetimestepMS)); + cobj.SendCollisions(); + break; - switch ((ActorTypes)obj.PhysicsActorType) - { - case ActorTypes.Agent: - OdeCharacter cobj = (OdeCharacter)obj; - cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE*1000.0f)); - cobj.SendCollisions(); - break; - - case ActorTypes.Prim: - OdePrim pobj = (OdePrim)obj; - if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) - { - pobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f)); - pobj.SendCollisions(); - } - break; - } + case ActorTypes.Prim: + OdePrim pobj = (OdePrim)obj; + if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) + { + pobj.AddCollisionFrameTime((int)(odetimestepMS)); + pobj.SendCollisions(); + } + break; } } + foreach (PhysicsActor obj in _collisionEventPrimRemove) + _collisionEventPrim.Remove(obj); + + _collisionEventPrimRemove.Clear(); + // do a ode simulation step d.WorldQuickStep(world, ODE_STEPSIZE); d.JointGroupEmpty(contactgroup); // update managed ideia of physical data and do updates to core - /* - lock (_characters) - { - foreach (OdeCharacter actor in _characters) - { - if (actor != null) - { - if (actor.bad) - m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); + /* + lock (_characters) + { + foreach (OdeCharacter actor in _characters) + { + if (actor != null) + { + if (actor.bad) + m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); - actor.UpdatePositionAndVelocity(); - } - } - } - */ + actor.UpdatePositionAndVelocity(); + } + } + } + */ lock (_activegroups) {