Merge branch 'ubitwork' into avination

avinationmerge
Melanie 2012-05-21 07:32:27 +02:00
commit 7305d2e0ef
7 changed files with 560 additions and 326 deletions

View File

@ -33,13 +33,83 @@ 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("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_StoneMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
private static UUID snd_StoneGlass = 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,
@ -104,12 +186,9 @@ namespace OpenSim.Region.Framework.Scenes
snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber
};
public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders)
public static void PartCollisionSound(SceneObjectPart part, List<CollisionForSoundInfo> collidersinfolist)
{
// temporary mute sounds
return;
if(Colliders.Count == 0 || part == null)
if (collidersinfolist.Count == 0 || part == null)
return;
if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
@ -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);
// 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)
{
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, 1.0, position);
}
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);
if (!HaveSound)
{
if (otherPart.CollisionSoundType > 0)
{
soundID = otherPart.CollisionSound;
volume = otherPart.CollisionSoundVolume;
if (volume == 0.0f)
continue;
}
else
{
otherMaterial = (int)otherPart.Material;
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;
index = thisMatScaled + otherMaterial;
soundID = m_PartPart[index];
soundID = m_PartPart[thisMatScaled + otherMaterial];
}
}
if (doneownsound)
otherPart.SendCollisionSound(soundID, 1.0, position);
otherPart.SendCollisionSound(soundID, volume, colInfo.position);
else
{
part.SendCollisionSound(soundID, 1.0, position);
part.SendCollisionSound(soundID, volume, colInfo.position);
doneownsound = true;
}
}
}
/* avatars get notification let them trigger the sound
else if (!doneownsound)
{
ScenePresence av = part.ParentGroup.Scene.GetScenePresence(Id);
if (av != null && (!av.IsChildAgent))
{
index = thisMatScaled + 4; // flesh
soundID = m_PartPart[index];
part.SendCollisionSound(soundID, 1.0);
doneownsound = true;
}
}
*/
}
}
public static void AvatarCollisionSound(ScenePresence av, List<uint> Colliders)
public static void AvatarCollisionSound(ScenePresence av, List<CollisionForSoundInfo> 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
*/
}
}
}
}

View File

@ -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();
}
/// <summary>
@ -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<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
// 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
/// </remarks>
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

View File

@ -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<uint, ContactPoint> coldata)
{
/*
lock(m_collisionEventLock)
{
if (m_collisionEventFlag)
@ -4107,18 +4108,45 @@ namespace OpenSim.Region.Framework.Scenes
Util.FireAndForget(delegate(object x)
{
*/
try
{
List<uint> thisHitColliders = new List<uint>();
List<uint> endedColliders = 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.Contains(localid))
if (m_lastColliders.Count == 0)
return; // nothing to do
foreach (uint localID in m_lastColliders)
{
startedColliders.Add(localid);
endedColliders.Add(localID);
}
m_lastColliders.Clear();
}
else
{
foreach (uint id in coldata.Keys)
{
thisHitColliders.Add(id);
if (!m_lastColliders.Contains(id))
{
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());
}
@ -4142,10 +4170,12 @@ namespace OpenSim.Region.Framework.Scenes
m_lastColliders.Remove(localID);
}
if (soundinfolist.Count > 0)
CollisionSounds.AvatarCollisionSound(this, soundinfolist);
// do event notification
if (startedColliders.Count > 0)
{
CollisionSounds.AvatarCollisionSound(this, startedColliders);
ColliderArgs StartCollidingMessage = new ColliderArgs();
List<DetectedObject> colliding = new List<DetectedObject>();
@ -4179,6 +4209,7 @@ namespace OpenSim.Region.Framework.Scenes
Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
}
}
}
if (endedColliders.Count > 0)
{
@ -4257,7 +4288,7 @@ namespace OpenSim.Region.Framework.Scenes
{
m_collisionEventFlag = false;
}
});
// });
}
private void TeleportFlagsDebug() {

View File

@ -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
}
}

View File

@ -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; }
}
@ -784,8 +785,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;
qtmp.X = 0;
@ -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);
if (CollisionEventsThisFrame == null)
CollisionEventsThisFrame = new CollisionEventUpdate();
CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
}
}
public void SendCollisions()
{
if (m_haseventsubscription && m_eventsubscription > m_requestedUpdateFrequency)
{
if (CollisionEventsThisFrame != null)
if (CollisionEventsThisFrame == null)
return;
if (m_cureventsubscription < m_eventsubscription)
return;
m_cureventsubscription = 0;
int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
if (!SentEmptyCollisionsEvent || ncolisions > 0)
{
base.SendCollisionUpdate(CollisionEventsThisFrame);
if (ncolisions == 0)
{
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;
}
}
}

View File

@ -477,7 +477,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// if(childPrim) we only know about physical linksets
return Ptot;
/*
/*
float tmass = _mass;
Ptot *= tmass;
@ -497,14 +497,14 @@ namespace OpenSim.Region.Physics.OdePlugin
Ptot *= tmass;
return Ptot;
*/
*/
}
else
return _position;
}
}
}
/*
/*
public override Vector3 PrimOOBsize
{
get
@ -528,7 +528,7 @@ namespace OpenSim.Region.Physics.OdePlugin
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;
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
{
@ -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);

View File

@ -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.
/// </summary>
private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
private readonly List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>();
private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>();
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;
odetimestepMS = (int)(1000.0f * ODE_STEPSIZE +0.5f);
ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf);
GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf);
@ -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,21 +1264,15 @@ namespace OpenSim.Region.Physics.OdePlugin
}
#endregion
/// <summary>
/// Add actor to the list that should receive collision events in the simulate loop.
/// </summary>
/// <param name="obj"></param>
public void AddCollisionEventReporting(PhysicsActor obj)
{
lock (_collisionEventPrim)
{
if (!_collisionEventPrim.Contains(obj))
_collisionEventPrim.Add(obj);
}
}
/// <summary>
/// Remove actor from the list that should receive collision events in the simulate loop.
@ -1268,13 +1280,11 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <param name="obj"></param>
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,8 +1886,6 @@ namespace OpenSim.Region.Physics.OdePlugin
collision_optimized();
lock (_collisionEventPrim)
{
foreach (PhysicsActor obj in _collisionEventPrim)
{
if (obj == null)
@ -1892,7 +1895,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
case ActorTypes.Agent:
OdeCharacter cobj = (OdeCharacter)obj;
cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE*1000.0f));
cobj.AddCollisionFrameTime((int)(odetimestepMS));
cobj.SendCollisions();
break;
@ -1900,13 +1903,17 @@ namespace OpenSim.Region.Physics.OdePlugin
OdePrim pobj = (OdePrim)obj;
if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds))
{
pobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f));
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);