Merge branch 'avination' into careminster

avinationmerge
Melanie 2012-05-27 19:35:36 +01:00
commit 78e657fd8d
8 changed files with 561 additions and 342 deletions

View File

@ -33,67 +33,116 @@ using OpenSim.Framework;
namespace OpenSim.Region.Framework.Scenes namespace OpenSim.Region.Framework.Scenes
{ {
public struct CollisionForSoundInfo
{
public uint colliderID;
public Vector3 position;
public float relativeVel;
}
public static class CollisionSounds public static class CollisionSounds
{ {
// defines for cases
// only know one UUID for now (woodflesh)
private const int MaxMaterials = 7; private const int MaxMaterials = 7;
// part part // part part
/*
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_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_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_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_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_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_StoneStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_StoneMetal = 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_StoneGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_StoneWood = 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_StoneFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_StonePlastic = 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_StoneRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_MetalStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_MetalMetal = 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_MetalGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_MetalWood = 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_MetalFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_MetalPlastic = 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_MetalRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_GlassStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_GlassGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_GlassMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_GlassWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_GlassGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_GlassFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_GlassWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_GlassPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_GlassFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_GlassRubber = 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_WoodStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_WoodWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_WoodMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_WoodFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_WoodGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_WoodPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_WoodWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_WoodRubber = 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_FleshStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_FleshFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_FleshMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_FleshPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_FleshGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_FleshRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_FleshWood = 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_PlasticStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_PlasticPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_PlasticMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_PlasticRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_PlasticGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_PlasticWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_PlasticFlesh = 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_RubberStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_RubberMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_RubberGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_RubberWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_RubberFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_RubberPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_RubberRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a"); private static UUID snd_RubberRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
// terrain part // terrain part
@ -114,7 +163,8 @@ namespace OpenSim.Region.Framework.Scenes
snd_TerrainPlastic, snd_TerrainPlastic,
snd_TerrainRubber snd_TerrainRubber
}; };
/*
//full assimetric sounds
public static UUID[] m_PartPart = { public static UUID[] m_PartPart = {
snd_StoneStone, snd_StoneMetal, snd_StoneGlass, snd_StoneWood, snd_StoneFlesh, snd_StonePlastic, snd_StoneRubber, 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_MetalStone, snd_MetalMetal, snd_MetalGlass, snd_MetalWood, snd_MetalFlesh, snd_MetalPlastic, snd_MetalRubber,
@ -124,10 +174,21 @@ namespace OpenSim.Region.Framework.Scenes
snd_PlasticStone, snd_PlasticMetal, snd_PlasticGlass, snd_PlasticWood, snd_PlasticFlesh, snd_PlasticPlastic, snd_PlasticRubber, 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 snd_RubberStone, snd_RubberMetal, snd_RubberGlass, snd_RubberWood, snd_RubberFlesh, snd_RubberPlastic, snd_RubberRubber
}; };
*/
public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders) // 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,
snd_StoneGlass, snd_MetalGlass, snd_GlassGlass, snd_GlassWood, snd_GlassFlesh, snd_GlassPlastic, snd_GlassRubber,
snd_StoneWood, snd_MetalWood, snd_GlassWood, snd_WoodWood, snd_WoodFlesh, snd_WoodPlastic, snd_WoodRubber,
snd_StoneFlesh, snd_MetalFlesh, snd_GlassFlesh, snd_WoodFlesh, snd_FleshFlesh, snd_FleshPlastic, snd_FleshRubber,
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<CollisionForSoundInfo> collidersinfolist)
{ {
if(Colliders.Count == 0 || part == null) if (collidersinfolist.Count == 0 || part == null)
return; return;
if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0) if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
@ -136,121 +197,161 @@ namespace OpenSim.Region.Framework.Scenes
if (part.ParentGroup == null) if (part.ParentGroup == null)
return; return;
if (part.CollisionSound == part.invalidCollisionSoundUUID) if (part.CollisionSoundType < 0)
return; return;
UUID soundID; float volume = 0.0f;
int otherMaterial; 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) // soundID = part.CollisionSound;
part.SendCollisionSound(part.CollisionSound, part.CollisionSoundVolume, position); volume = part.CollisionSoundVolume;
return; 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; 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) if (!doneownsound)
{ {
soundID = m_TerrainPart[thisMaterial]; if (!HaveSound)
part.SendCollisionSound(soundID, 1.0, position); {
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; doneownsound = true;
} }
continue; continue;
} }
SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(Id); SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(id);
if (otherPart != null) if (otherPart != null)
{ {
if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive) if (otherPart.CollisionSoundType < 0 || otherPart.VolumeDetectActive)
continue; continue;
if (otherPart.CollisionSound != UUID.Zero)
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position); if (!HaveSound)
else
{ {
otherMaterial = (int)otherPart.Material; if (otherPart.CollisionSoundType > 0)
if (otherMaterial >= MaxMaterials) {
otherMaterial = 3; soundID = otherPart.CollisionSound;
index = thisMatScaled + otherMaterial; volume = otherPart.CollisionSoundVolume;
soundID = m_PartPart[index]; if (volume == 0.0f)
if (doneownsound) continue;
otherPart.SendCollisionSound(soundID, 1.0, position); }
else else
{ {
part.SendCollisionSound(soundID, 1.0, position); volume = Math.Abs(colInfo.relativeVel);
doneownsound = true; 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 if (doneownsound)
else if (!doneownsound) otherPart.SendCollisionSound(soundID, volume, colInfo.position);
{ else
ScenePresence av = part.ParentGroup.Scene.GetScenePresence(Id);
if (av != null && (!av.IsChildAgent))
{ {
index = thisMatScaled + 4; // flesh part.SendCollisionSound(soundID, volume, colInfo.position);
soundID = m_PartPart[index];
part.SendCollisionSound(soundID, 1.0);
doneownsound = true; doneownsound = true;
} }
} }
*/
} }
} }
public static void AvatarCollisionSound(ScenePresence av, List<uint> Colliders) public static void AvatarCollisionSound(ScenePresence av, List<CollisionForSoundInfo> collidersinfolist)
{ {
if (Colliders.Count == 0 || av == null) if (collidersinfolist.Count == 0 || av == null)
return; return;
UUID soundID; UUID soundID;
int otherMaterial; int otherMaterial;
int thisMaterial = 3; int thisMaterial = 4; // flesh
int thisMatScaled = thisMaterial * MaxMaterials; 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; 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 != null)
{ {
if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID) if (otherPart.CollisionSoundType < 0)
continue; continue;
if (otherPart.CollisionSound != UUID.Zero) if (otherPart.CollisionSoundType > 0 && otherPart.CollisionSoundVolume > 0f)
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position); otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, colInfo.position);
else 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; otherMaterial = (int)otherPart.Material;
if (otherMaterial >= MaxMaterials) if (otherMaterial >= MaxMaterials)
otherMaterial = 3; otherMaterial = 3;
index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index]; soundID = m_PartPart[thisMatScaled + otherMaterial];
otherPart.SendCollisionSound(soundID, 1.0, position); otherPart.SendCollisionSound(soundID, volume, colInfo.position);
} }
continue;
} }
/* /*
else if (!doneownsound) else if (!doneownsound)
@ -266,6 +367,5 @@ namespace OpenSim.Region.Framework.Scenes
*/ */
} }
} }
} }
} }

View File

@ -3763,7 +3763,7 @@ namespace OpenSim.Region.Framework.Scenes
} }
if ((change & ObjectChangeType.Position) != 0) if ((change & ObjectChangeType.Position) != 0)
{ {
if (m_scene.Permissions.CanObjectEntry(group.UUID, false, data.position)) if (IsAttachment || m_scene.Permissions.CanObjectEntry(group.UUID, false, data.position))
UpdateGroupPosition(data.position); UpdateGroupPosition(data.position);
updateType = updatetype.groupterse; updateType = updatetype.groupterse;
} }

View File

@ -329,11 +329,13 @@ namespace OpenSim.Region.Framework.Scenes
private Vector3 m_cameraAtOffset; private Vector3 m_cameraAtOffset;
private bool m_forceMouselook; 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 UUID m_collisionSound;
private float m_collisionSoundVolume; private float m_collisionSoundVolume;
private DateTime LastColSoundSentTime; private int LastColSoundSentTime;
private SOPVehicle m_vehicle = null; 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 // 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 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
m_inventory = new SceneObjectPartInventory(this); m_inventory = new SceneObjectPartInventory(this);
LastColSoundSentTime = DateTime.UtcNow; LastColSoundSentTime = Util.EnvironmentTickCount();
} }
/// <summary> /// <summary>
@ -1353,12 +1355,39 @@ namespace OpenSim.Region.Framework.Scenes
public UUID invalidCollisionSoundUUID = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff"); 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 public UUID CollisionSound
{ {
get { return m_collisionSound; } get { return m_collisionSound; }
set set
{ {
m_collisionSound = value; m_collisionSound = value;
if (value == invalidCollisionSoundUUID)
m_collisionSoundType = -1;
else if (value == UUID.Zero)
m_collisionSoundType = 0;
else
m_collisionSoundType = 1;
aggregateScriptEvents(); aggregateScriptEvents();
} }
} }
@ -1586,7 +1615,10 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
else if (PhysActor == null) else if (PhysActor == null)
{
ApplyPhysics((uint)Flags, VolumeDetectActive, false); ApplyPhysics((uint)Flags, VolumeDetectActive, false);
UpdatePhysicsSubscribedEvents();
}
else else
{ {
PhysActor.PhysicsShapeType = m_physicsShapeType; PhysActor.PhysicsShapeType = m_physicsShapeType;
@ -2646,13 +2678,42 @@ namespace OpenSim.Region.Framework.Scenes
else else
{ {
List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
// 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) if (!VolumeDetectActive && CollisionSoundType >= 0)
{ {
thisHitColliders.Add(localid); CollisionForSoundInfo soundinfo;
if (!m_lastColliders.Contains(localid)) ContactPoint curcontact;
startedColliders.Add(localid);
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 // calculate things that ended colliding
@ -2669,17 +2730,14 @@ namespace OpenSim.Region.Framework.Scenes
// remove things that ended colliding from the last colliders list // remove things that ended colliding from the last colliders list
foreach (uint localID in endedColliders) foreach (uint localID in endedColliders)
m_lastColliders.Remove(localID); 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); 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 , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
@ -3224,8 +3282,8 @@ namespace OpenSim.Region.Framework.Scenes
if (volume < 0) if (volume < 0)
volume = 0; volume = 0;
DateTime now = DateTime.UtcNow; int now = Util.EnvironmentTickCount();
if((now - LastColSoundSentTime).Milliseconds < 200) // reduce rate to 5 per sec per part ?? if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
return; return;
LastColSoundSentTime = now; LastColSoundSentTime = now;
@ -4623,7 +4681,15 @@ namespace OpenSim.Region.Framework.Scenes
/// </remarks> /// </remarks>
public void RemoveFromPhysics() 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; PhysActor = null;
} }
@ -4792,7 +4858,8 @@ namespace OpenSim.Region.Framework.Scenes
pa.OnCollisionUpdate -= PhysicsCollision; pa.OnCollisionUpdate -= PhysicsCollision;
bool hassound = ( CollisionSound != invalidCollisionSoundUUID); bool hassound = (CollisionSoundType >= 0 && !VolumeDetectActive);
scriptEvents CombinedEvents = AggregateScriptEvents; scriptEvents CombinedEvents = AggregateScriptEvents;
// merge with root part // merge with root part
@ -4801,10 +4868,7 @@ namespace OpenSim.Region.Framework.Scenes
// submit to this part case // submit to this part case
if (VolumeDetectActive) if (VolumeDetectActive)
{
CombinedEvents &= PhyscicsVolumeDtcSubsEvents; CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
hassound = false;
}
else if ((Flags & PrimFlags.Phantom) != 0) else if ((Flags & PrimFlags.Phantom) != 0)
CombinedEvents &= PhyscicsPhantonSubsEvents; CombinedEvents &= PhyscicsPhantonSubsEvents;
else else

View File

@ -2043,7 +2043,7 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied); // m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied);
if (PhysicsActor != null) if (PhysicsActor != null)
m_sitAvatarHeight = PhysicsActor.Size.Z; m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
bool canSit = false; bool canSit = false;
pos = part.AbsolutePosition + offset; pos = part.AbsolutePosition + offset;
@ -4287,6 +4287,7 @@ namespace OpenSim.Region.Framework.Scenes
private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata) private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
{ {
/*
lock(m_collisionEventLock) lock(m_collisionEventLock)
{ {
if (m_collisionEventFlag) if (m_collisionEventFlag)
@ -4296,76 +4297,106 @@ namespace OpenSim.Region.Framework.Scenes
Util.FireAndForget(delegate(object x) Util.FireAndForget(delegate(object x)
{ {
*/
try try
{ {
List<uint> thisHitColliders = new List<uint>(); List<uint> thisHitColliders = new List<uint>();
List<uint> endedColliders = new List<uint>(); List<uint> endedColliders = new List<uint>();
List<uint> startedColliders = new List<uint>(); List<uint> startedColliders = new List<uint>();
List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
CollisionForSoundInfo soundinfo;
ContactPoint curcontact;
foreach (uint localid in coldata.Keys) if (coldata.Count == 0)
{ {
thisHitColliders.Add(localid); if (m_lastColliders.Count == 0)
if (!m_lastColliders.Contains(localid)) return; // nothing to do
{
startedColliders.Add(localid); foreach (uint localID in m_lastColliders)
}
//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))
{ {
endedColliders.Add(localID); endedColliders.Add(localID);
} }
} m_lastColliders.Clear();
//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);
} }
// do event notification else
if (startedColliders.Count > 0)
{ {
CollisionSounds.AvatarCollisionSound(this, startedColliders); foreach (uint id in coldata.Keys)
ColliderArgs StartCollidingMessage = new ColliderArgs();
List<DetectedObject> colliding = new List<DetectedObject>();
foreach (uint localId in startedColliders)
{ {
if (localId == 0) thisHitColliders.Add(id);
continue; if (!m_lastColliders.Contains(id))
SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
string data = "";
if (obj != null)
{ {
DetectedObject detobj = new DetectedObject(); startedColliders.Add(id);
detobj.keyUUID = obj.UUID; curcontact = coldata[id];
detobj.nameStr = obj.Name; if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
detobj.ownerUUID = obj.OwnerID; {
detobj.posVector = obj.AbsolutePosition; soundinfo = new CollisionForSoundInfo();
detobj.rotQuat = obj.GetWorldRotation(); soundinfo.colliderID = id;
detobj.velVector = obj.Velocity; soundinfo.position = curcontact.Position;
detobj.colliderType = 0; soundinfo.relativeVel = curcontact.RelativeSpeed;
detobj.groupUUID = obj.GroupID; soundinfolist.Add(soundinfo);
colliding.Add(detobj); }
} }
//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()) if (soundinfolist.Count > 0)
Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); CollisionSounds.AvatarCollisionSound(this, soundinfolist);
// do event notification
if (startedColliders.Count > 0)
{
ColliderArgs StartCollidingMessage = new ColliderArgs();
List<DetectedObject> colliding = new List<DetectedObject>();
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);
}
} }
} }
@ -4446,7 +4477,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
m_collisionEventFlag = false; m_collisionEventFlag = false;
} }
}); // });
} }
private void TeleportFlagsDebug() { private void TeleportFlagsDebug() {

View File

@ -59,12 +59,14 @@ namespace OpenSim.Region.Physics.Manager
public Vector3 Position; public Vector3 Position;
public Vector3 SurfaceNormal; public Vector3 SurfaceNormal;
public float PenetrationDepth; public float PenetrationDepth;
public float RelativeSpeed;
public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth) public ContactPoint(Vector3 position, Vector3 surfaceNormal, float penetrationDepth)
{ {
Position = position; Position = position;
SurfaceNormal = surfaceNormal; SurfaceNormal = surfaceNormal;
PenetrationDepth = penetrationDepth; PenetrationDepth = penetrationDepth;
RelativeSpeed = 0f; // for now let this one be set explicity
} }
} }

View File

@ -128,9 +128,10 @@ namespace OpenSim.Region.Physics.OdePlugin
public d.Mass ShellMass; public d.Mass ShellMass;
// public bool collidelock = false; // public bool collidelock = false;
private bool m_haseventsubscription = false;
public int m_eventsubscription = 0; 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 // unique UUID of this character object
public UUID m_uuid; public UUID m_uuid;
@ -239,7 +240,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override bool IsPhysical public override bool IsPhysical
{ {
get { return false; } get { return m_isPhysical; }
set { return; } set { return; }
} }
@ -783,8 +784,6 @@ namespace OpenSim.Region.Physics.OdePlugin
// the Amotor still lets avatar rotation to drift during colisions // the Amotor still lets avatar rotation to drift during colisions
// so force it back to identity // so force it back to identity
d.Quaternion qtmp; d.Quaternion qtmp;
qtmp.W = 1; qtmp.W = 1;
@ -903,6 +902,7 @@ namespace OpenSim.Region.Physics.OdePlugin
contact.SurfaceNormal.X = 0f; contact.SurfaceNormal.X = 0f;
contact.SurfaceNormal.Y = 0f; contact.SurfaceNormal.Y = 0f;
contact.SurfaceNormal.Z = -1f; contact.SurfaceNormal.Z = -1f;
contact.RelativeSpeed = -vel.Z;
AddCollisionEvent(0, contact); AddCollisionEvent(0, contact);
vec.Z *= 0.5f; vec.Z *= 0.5f;
@ -1119,47 +1119,71 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void SubscribeEvents(int ms) public override void SubscribeEvents(int ms)
{ {
m_requestedUpdateFrequency = ms;
m_eventsubscription = ms; m_eventsubscription = ms;
_parent_scene.AddCollisionEventReporting(this); m_cureventsubscription = 0;
m_haseventsubscription = true; if (CollisionEventsThisFrame == null)
CollisionEventsThisFrame = new CollisionEventUpdate();
SentEmptyCollisionsEvent = false;
} }
public override void UnSubscribeEvents() public override void UnSubscribeEvents()
{ {
m_haseventsubscription = false; if (CollisionEventsThisFrame != null)
_parent_scene.RemoveCollisionEventReporting(this); {
m_requestedUpdateFrequency = 0; CollisionEventsThisFrame.Clear();
CollisionEventsThisFrame = null;
}
m_eventsubscription = 0; m_eventsubscription = 0;
} }
public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
{ {
if (m_haseventsubscription) if (CollisionEventsThisFrame == null)
{ CollisionEventsThisFrame = new CollisionEventUpdate();
// m_log.DebugFormat( CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
// "[PHYSICS]: Adding collision event for {0}, collidedWith {1}, contact {2}", "", CollidedWith, contact);
CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
}
} }
public void SendCollisions() 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(); else
m_eventsubscription = 0; {
} 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() public override bool SubscribedEvents()
{ {
return m_haseventsubscription; if (m_eventsubscription > 0)
return true;
return false;
} }
private void changePhysicsStatus(bool NewStatus) private void changePhysicsStatus(bool NewStatus)
@ -1465,14 +1489,5 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
_parent_scene.AddChange((PhysicsActor)this, what, arg); _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;
}
} }
} }

View File

@ -477,58 +477,58 @@ namespace OpenSim.Region.Physics.OdePlugin
// if(childPrim) we only know about physical linksets // if(childPrim) we only know about physical linksets
return Ptot; return Ptot;
/* /*
float tmass = _mass; float tmass = _mass;
Ptot *= tmass; Ptot *= tmass;
float m; float m;
foreach (OdePrim prm in childrenPrim) foreach (OdePrim prm in childrenPrim)
{ {
m = prm._mass; m = prm._mass;
Ptot += prm.CenterOfMass * m; Ptot += prm.CenterOfMass * m;
tmass += m; tmass += m;
} }
if (tmass == 0) if (tmass == 0)
tmass = 0; tmass = 0;
else else
tmass = 1.0f / tmass; tmass = 1.0f / tmass;
Ptot *= tmass; Ptot *= tmass;
return Ptot; return Ptot;
*/ */
} }
else else
return _position; return _position;
} }
} }
} }
/* /*
public override Vector3 PrimOOBsize public override Vector3 PrimOOBsize
{ {
get get
{ {
return primOOBsize; return primOOBsize;
} }
} }
public override Vector3 PrimOOBoffset public override Vector3 PrimOOBoffset
{ {
get get
{ {
return primOOBoffset; return primOOBoffset;
} }
} }
public override float PrimOOBRadiusSQ public override float PrimOOBRadiusSQ
{ {
get get
{ {
return primOOBradiusSQ; return primOOBradiusSQ;
} }
} }
*/ */
public override PrimitiveBaseShape Shape public override PrimitiveBaseShape Shape
{ {
set set
@ -582,7 +582,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (value.IsFinite()) if (value.IsFinite())
{ {
AddChange(changes.Velocity, value); AddChange(changes.Velocity, value);
// _velocity = value; // _velocity = value;
} }
else else
@ -937,12 +937,10 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollisionEventsThisFrame == null) if (CollisionEventsThisFrame == null)
CollisionEventsThisFrame = new CollisionEventUpdate(); CollisionEventsThisFrame = new CollisionEventUpdate();
SentEmptyCollisionsEvent = false; SentEmptyCollisionsEvent = false;
_parent_scene.AddCollisionEventReporting(this);
} }
public override void UnSubscribeEvents() public override void UnSubscribeEvents()
{ {
_parent_scene.RemoveCollisionEventReporting(this);
if (CollisionEventsThisFrame != null) if (CollisionEventsThisFrame != null)
{ {
CollisionEventsThisFrame.Clear(); CollisionEventsThisFrame.Clear();
@ -975,7 +973,10 @@ namespace OpenSim.Region.Physics.OdePlugin
base.SendCollisionUpdate(CollisionEventsThisFrame); base.SendCollisionUpdate(CollisionEventsThisFrame);
if (ncolisions == 0) if (ncolisions == 0)
{
SentEmptyCollisionsEvent = true; SentEmptyCollisionsEvent = true;
_parent_scene.RemoveCollisionEventReporting(this);
}
else else
{ {
SentEmptyCollisionsEvent = false; SentEmptyCollisionsEvent = false;
@ -986,11 +987,10 @@ namespace OpenSim.Region.Physics.OdePlugin
internal void AddCollisionFrameTime(int t) internal void AddCollisionFrameTime(int t)
{ {
// protect it from overflow crashing if (m_cureventsubscription < 50000)
if (m_cureventsubscription + t >= int.MaxValue) m_cureventsubscription += t;
m_cureventsubscription = 0;
m_cureventsubscription += t;
} }
public override bool SubscribedEvents() public override bool SubscribedEvents()
{ {
if (m_eventsubscription > 0) if (m_eventsubscription > 0)
@ -1735,8 +1735,8 @@ namespace OpenSim.Region.Physics.OdePlugin
d.BodySetAutoDisableFlag(Body, true); d.BodySetAutoDisableFlag(Body, true);
d.BodySetAutoDisableSteps(Body, body_autodisable_frames); d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
// d.BodySetLinearDampingThreshold(Body, 0.01f); // d.BodySetLinearDampingThreshold(Body, 0.01f);
// d.BodySetAngularDampingThreshold(Body, 0.001f); // d.BodySetAngularDampingThreshold(Body, 0.001f);
d.BodySetDamping(Body, .002f, .002f); d.BodySetDamping(Body, .002f, .002f);
if (m_targetSpace != IntPtr.Zero) if (m_targetSpace != IntPtr.Zero)
@ -2966,7 +2966,7 @@ namespace OpenSim.Region.Physics.OdePlugin
givefakepos--; givefakepos--;
if (givefakepos < 0) if (givefakepos < 0)
givefakepos = 0; givefakepos = 0;
// changeSelectedStatus(); // changeSelectedStatus();
resetCollisionAccounting(); resetCollisionAccounting();
} }
@ -2981,14 +2981,14 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
_orientation = newOri; _orientation = newOri;
} }
/* /*
else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero) else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero)
{ {
FixInertia(_position, newOri); FixInertia(_position, newOri);
if (!d.BodyIsEnabled(Body)) if (!d.BodyIsEnabled(Body))
d.BodyEnable(Body); d.BodyEnable(Body);
} }
*/ */
} }
else else
{ {
@ -3939,12 +3939,12 @@ namespace OpenSim.Region.Physics.OdePlugin
changevelocity((Vector3)arg); changevelocity((Vector3)arg);
break; break;
// case changes.Acceleration: // case changes.Acceleration:
// changeacceleration((Vector3)arg); // changeacceleration((Vector3)arg);
// break; // break;
// case changes.AngVelocity: // case changes.AngVelocity:
// changeangvelocity((Vector3)arg); // changeangvelocity((Vector3)arg);
// break; // break;
case changes.Force: case changes.Force:
changeForce((Vector3)arg); changeForce((Vector3)arg);

View File

@ -190,6 +190,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public float ODE_STEPSIZE = 0.020f; public float ODE_STEPSIZE = 0.020f;
public float HalfOdeStep = 0.01f; public float HalfOdeStep = 0.01f;
public int odetimestepMS = 20; // rounded
private float metersInSpace = 25.6f; private float metersInSpace = 25.6f;
private float m_timeDilation = 1.0f; private float m_timeDilation = 1.0f;
@ -247,6 +248,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// A list of actors that should receive collision events. /// A list of actors that should receive collision events.
/// </summary> /// </summary>
private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
private readonly List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>();
private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>();
public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
@ -489,6 +491,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
HalfOdeStep = ODE_STEPSIZE * 0.5f; HalfOdeStep = ODE_STEPSIZE * 0.5f;
odetimestepMS = (int)(1000.0f * ODE_STEPSIZE +0.5f);
ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf);
GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf);
@ -1064,7 +1067,7 @@ namespace OpenSim.Region.Physics.OdePlugin
obj2LocalID = 0; obj2LocalID = 0;
bool p1events = p1.SubscribedEvents(); bool p1events = p1.SubscribedEvents();
bool p2events = p2.SubscribedEvents(); bool p2events = p2.SubscribedEvents();
if (p1.IsVolumeDtc) if (p1.IsVolumeDtc)
p2events = false; p2events = false;
if (p2.IsVolumeDtc) if (p2.IsVolumeDtc)
@ -1073,6 +1076,21 @@ namespace OpenSim.Region.Physics.OdePlugin
if (!(p2events || p1events)) if (!(p2events || p1events))
return; 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) switch ((ActorTypes)p1.PhysicsActorType)
{ {
case ActorTypes.Agent: case ActorTypes.Agent:
@ -1246,20 +1264,14 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
#endregion #endregion
/// <summary> /// <summary>
/// Add actor to the list that should receive collision events in the simulate loop. /// Add actor to the list that should receive collision events in the simulate loop.
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
public void AddCollisionEventReporting(PhysicsActor obj) public void AddCollisionEventReporting(PhysicsActor obj)
{ {
lock (_collisionEventPrim) if (!_collisionEventPrim.Contains(obj))
{ _collisionEventPrim.Add(obj);
if (!_collisionEventPrim.Contains(obj))
_collisionEventPrim.Add(obj);
}
} }
/// <summary> /// <summary>
@ -1268,13 +1280,11 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <param name="obj"></param> /// <param name="obj"></param>
public void RemoveCollisionEventReporting(PhysicsActor obj) public void RemoveCollisionEventReporting(PhysicsActor obj)
{ {
lock (_collisionEventPrim) if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj))
{ _collisionEventPrimRemove.Add(obj);
if (_collisionEventPrim.Contains(obj))
_collisionEventPrim.Remove(obj);
}
} }
#region Add/Remove Entities #region Add/Remove Entities
public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
@ -1463,6 +1473,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
// lock (OdeLock) // lock (OdeLock)
{ {
OdePrim p = (OdePrim)prim; OdePrim p = (OdePrim)prim;
p.setPrimForRemoval(); p.setPrimForRemoval();
} }
@ -1818,7 +1829,6 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
int ttmpstart = Util.EnvironmentTickCount(); int ttmpstart = Util.EnvironmentTickCount();
int ttmp; int ttmp;
int ttmp2;
while(ChangesQueue.Dequeue(out item)) while(ChangesQueue.Dequeue(out item))
{ {
@ -1840,11 +1850,6 @@ namespace OpenSim.Region.Physics.OdePlugin
if (ttmp > 20) if (ttmp > 20)
break; break;
} }
ttmp2 = Util.EnvironmentTickCountSubtract(ttmpstart);
if (ttmp2 > 50)
ttmp2 = 0;
} }
// Move characters // Move characters
@ -1881,53 +1886,55 @@ namespace OpenSim.Region.Physics.OdePlugin
collision_optimized(); 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) case ActorTypes.Agent:
continue; OdeCharacter cobj = (OdeCharacter)obj;
cobj.AddCollisionFrameTime((int)(odetimestepMS));
cobj.SendCollisions();
break;
switch ((ActorTypes)obj.PhysicsActorType) case ActorTypes.Prim:
{ OdePrim pobj = (OdePrim)obj;
case ActorTypes.Agent: if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds))
OdeCharacter cobj = (OdeCharacter)obj; {
cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE*1000.0f)); pobj.AddCollisionFrameTime((int)(odetimestepMS));
cobj.SendCollisions(); pobj.SendCollisions();
break; }
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;
}
} }
} }
foreach (PhysicsActor obj in _collisionEventPrimRemove)
_collisionEventPrim.Remove(obj);
_collisionEventPrimRemove.Clear();
// do a ode simulation step // do a ode simulation step
d.WorldQuickStep(world, ODE_STEPSIZE); d.WorldQuickStep(world, ODE_STEPSIZE);
d.JointGroupEmpty(contactgroup); d.JointGroupEmpty(contactgroup);
// update managed ideia of physical data and do updates to core // update managed ideia of physical data and do updates to core
/* /*
lock (_characters) lock (_characters)
{ {
foreach (OdeCharacter actor in _characters) foreach (OdeCharacter actor in _characters)
{ {
if (actor != null) if (actor != null)
{ {
if (actor.bad) if (actor.bad)
m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid);
actor.UpdatePositionAndVelocity(); actor.UpdatePositionAndVelocity();
} }
} }
} }
*/ */
lock (_activegroups) lock (_activegroups)
{ {