From f852b6455550569d002d0b1c527249f3f7894326 Mon Sep 17 00:00:00 2001
From: Teravus Ovares
Date: Wed, 26 Dec 2007 17:16:47 +0000
Subject: * This update includes a wide range of changes to the ODEPlugin for
 avatar movement, including: ** - avatar can navigate stairs better now ** -
 avatar can land without shooting into the air ** - excessive collisions with
 the ground are tempered somewhat and should only shoot the avatar up 20m
 instead of 200m ** - Try Catched a TextureDownloadModule.cs array out of
 bounds error with a report that causes it not to crash the sim, however it
 reports a few important items for tracking it down.

---
 .../Environment/Modules/TextureDownloadModule.cs   | 10 ++++-
 OpenSim/Region/Environment/Scenes/ScenePresence.cs | 22 +++++-----
 OpenSim/Region/Physics/OdePlugin/ODECharacter.cs   | 39 +++++++++--------
 OpenSim/Region/Physics/OdePlugin/ODEPrim.cs        |  8 ----
 OpenSim/Region/Physics/OdePlugin/OdePlugin.cs      | 50 +++++++++++++++++++---
 5 files changed, 86 insertions(+), 43 deletions(-)

(limited to 'OpenSim/Region')

diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
index d126569..0adace1 100644
--- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs
@@ -319,7 +319,15 @@ namespace OpenSim.Region.Environment.Modules
                         int size = m_asset.Data.Length - 600 - (1000 * (PacketCounter - 1));
                         if (size > 1000) size = 1000;
                         im.ImageData.Data = new byte[size];
-                        Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), im.ImageData.Data, 0, size);
+                        try
+                        {
+                            Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), im.ImageData.Data, 0, size);
+                        }
+                        catch (System.ArgumentOutOfRangeException)
+                        {
+                            OpenSim.Framework.Console.MainLog.Instance.Warn("TEXTURE", "Unable to separate texture into multiple packets: Array bounds failure on asset:" + m_asset.FullID.ToString() + "- TextureDownloadModule.cs. line:328");
+                            return;
+                        }
                         RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
                         PacketCounter++;
                     }
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index 5570136..03f1a70 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -999,17 +999,17 @@ namespace OpenSim.Region.Environment.Scenes
             if (m_physicsActor.Flying)
             {
                 direc *= 4;
-                bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
-                bool colliding = (m_physicsActor.IsColliding==true);
-                if (controlland) 
-                    MainLog.Instance.Verbose("AGENT","landCommand");
-                if (colliding ) 
-                    MainLog.Instance.Verbose("AGENT","colliding");
-                if (m_physicsActor.Flying && colliding && controlland)
-                {
-                    StopFlying();
-                    MainLog.Instance.Verbose("AGENT", "Stop FLying");
-                }
+                //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
+                //bool colliding = (m_physicsActor.IsColliding==true);
+                //if (controlland) 
+                //    MainLog.Instance.Verbose("AGENT","landCommand");
+                //if (colliding ) 
+                //    MainLog.Instance.Verbose("AGENT","colliding");
+                //if (m_physicsActor.Flying && colliding && controlland)
+                //{
+                //    StopFlying();
+                //    MainLog.Instance.Verbose("AGENT", "Stop FLying");
+                //}
             }
             else
             {
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 33b2e4f..9676db4 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -111,22 +111,22 @@ namespace OpenSim.Region.Physics.OdePlugin
 
 
 
-                Amotor = d.JointCreateAMotor(parent_scene.world, IntPtr.Zero); 
-                d.JointAttach(Amotor, Body, IntPtr.Zero);
-                d.JointSetAMotorMode(Amotor, dAMotorEuler);
-                d.JointSetAMotorNumAxes(Amotor, 3);
-                d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
-                d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
-                d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
-                d.JointSetAMotorAngle(Amotor, 0, 0);
-                d.JointSetAMotorAngle(Amotor, 1, 0);
-                d.JointSetAMotorAngle(Amotor, 2, 0);
-                d.JointSetAMotorParam(Amotor, 0, -0);
-                d.JointSetAMotorParam(Amotor, 0x200, -0);
-                d.JointSetAMotorParam(Amotor, 0x100, -0);
-                d.JointSetAMotorParam(Amotor, 0, 0);
-                d.JointSetAMotorParam(Amotor, 3, 0);
-                d.JointSetAMotorParam(Amotor, 2, 0);
+                //Amotor = d.JointCreateAMotor(parent_scene.world, IntPtr.Zero); 
+                //d.JointAttach(Amotor, Body, IntPtr.Zero);
+                //d.JointSetAMotorMode(Amotor, dAMotorEuler);
+                //d.JointSetAMotorNumAxes(Amotor, 3);
+                //d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
+                //d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
+                ///d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
+                //d.JointSetAMotorAngle(Amotor, 0, 0);
+                //d.JointSetAMotorAngle(Amotor, 1, 0);
+                //d.JointSetAMotorAngle(Amotor, 2, 0);
+                //d.JointSetAMotorParam(Amotor, 0, -0);
+                //d.JointSetAMotorParam(Amotor, 0x200, -0);
+                //d.JointSetAMotorParam(Amotor, 0x100, -0);
+               // d.JointSetAMotorParam(Amotor, 0, 0);
+               // d.JointSetAMotorParam(Amotor, 3, 0);
+               // d.JointSetAMotorParam(Amotor, 2, 0);
                 
 
                 
@@ -269,7 +269,10 @@ namespace OpenSim.Region.Physics.OdePlugin
                     m_pidControllerActive = true;
             }
         }
-
+        public void SetPidStatus(bool status)
+        {
+            m_pidControllerActive = status;
+        }
         public override PhysicsVector Position
         {
             get { return _position; }
@@ -583,7 +586,7 @@ namespace OpenSim.Region.Physics.OdePlugin
         {
             lock (OdeScene.OdeLock)
             {
-                d.JointDestroy(Amotor);
+               // d.JointDestroy(Amotor);
                 d.GeomDestroy(Shell);
                 _parent_scene.geom_name_map.Remove(Shell);
                 d.BodyDestroy(Body);
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 32a9fc7..35328b8 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -375,14 +375,6 @@ namespace OpenSim.Region.Physics.OdePlugin
             {
                 string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
                 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
-                if (primScenAvatarIn == "0")
-                {
-                    MainLog.Instance.Verbose("Physics", "Prim " + m_primName + " in space with no prim: " + primScenAvatarIn + ". Expected to be at: " + m_targetSpace.ToString() + " . Arr:': " + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
-                }
-                else
-                {
-                    MainLog.Instance.Verbose("Physics", "Prim " + m_primName + " in Prim space with prim: " + primScenAvatarIn + ". Expected to be at: " + m_targetSpace.ToString() + ".  Arr:" + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
-                }
                 m_targetSpace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
                 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
                 d.SpaceAdd(m_targetSpace, prim_geom);
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 51c0e15..8bb822e 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -136,7 +136,7 @@ namespace OpenSim.Region.Physics.OdePlugin
             TerrainContact.surface.soft_erp = 0.1025f;
 
             AvatarMovementprimContact.surface.mu = 150.0f;
-            AvatarMovementprimContact.surface.bounce = 0.2f;
+            AvatarMovementprimContact.surface.bounce = 0.1f;
 
             AvatarMovementTerrainContact.surface.mode |= d.ContactFlags.SoftERP;
             AvatarMovementTerrainContact.surface.mu = 150.0f;
@@ -297,7 +297,9 @@ namespace OpenSim.Region.Physics.OdePlugin
                             {
                                 p2.CollidingObj = true;
                                 //contacts[i].depth = 0.003f;
-                                //p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f);
+                                p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f);
+                                OdeCharacter character = (OdeCharacter)p2;
+                                character.SetPidStatus(true);
                                 //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2));
 
                             }
@@ -309,8 +311,10 @@ namespace OpenSim.Region.Physics.OdePlugin
                             {
                                 p1.CollidingObj = true;
                                 //contacts[i].depth = 0.003f;
-                                //p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f);
+                                p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f);
                                 //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p2.Size.X / 2), contacts[i].pos.Y + (p2.Size.Y / 2), contacts[i].pos.Z + (p2.Size.Z / 2));
+                                OdeCharacter character = (OdeCharacter)p2;
+                                character.SetPidStatus(true);
                             }
                             else
                             {
@@ -321,12 +325,48 @@ namespace OpenSim.Region.Physics.OdePlugin
                         if (p1.PhysicsActorType == (int)ActorTypes.Prim && p2.PhysicsActorType == (int)ActorTypes.Prim)
                         {
                             // Don't collide, one or both prim will explode.
-                            contacts[i].depth = 0.0f;
+                            contacts[i].depth = -1f;
+                        }
+                        if (contacts[i].depth >= 1.00f)
+                        {
+                            if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Unknown) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Unknown))
+                            {
+                                
+                                if (p2.PhysicsActorType == (int)ActorTypes.Agent)
+                                {
+                                    OdeCharacter character = (OdeCharacter)p2;
+                                    
+                                    //p2.CollidingObj = true;
+                                    contacts[i].depth = 0.003f;
+                                    p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f);
+                                    contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2));
+                                    character.SetPidStatus(true);
+
+                                }
+                                else
+                                {
+                                    
+                                }
+                                if (p1.PhysicsActorType == (int)ActorTypes.Agent)
+                                {
+                                    OdeCharacter character = (OdeCharacter)p2;
+
+                                    //p2.CollidingObj = true;
+                                    contacts[i].depth = 0.003f;
+                                    p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f);
+                                    contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2));
+                                    character.SetPidStatus(true);
+                                }
+                                else
+                                {
+                                    //contacts[i].depth = 0.0000000f;
+                                }
+                            }
                         }
                     }
                     #endregion
 
-                    if (contacts[i].depth > 0f)
+                    if (contacts[i].depth >= 0f)
                     {
                         if (name1 == "Terrain" || name2 == "Terrain")
                         {
-- 
cgit v1.1