do agent crossing async, including QUERYACCESS ( need to check vehicles for

UbitUmarov [2014-10-21 10:57:47]
do agent crossing async, including QUERYACCESS ( need to check vehicles for
this also ), so it doesn't stop heartbeat
Filename
OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
index 19f748a..c898946 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
@@ -1511,6 +1511,30 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer

         public bool Cross(ScenePresence agent, bool isFlying)
         {
+            agent.IsInTransit = true;
+            CrossAsyncDelegate d = CrossAsync;
+            d.BeginInvoke(agent, isFlying, CrossCompleted, d);
+            return true;
+        }
+
+        private void CrossCompleted(IAsyncResult iar)
+        {
+            CrossAsyncDelegate icon = (CrossAsyncDelegate)iar.AsyncState;
+            ScenePresence agent = icon.EndInvoke(iar);
+
+            m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname);
+
+            if(!agent.IsChildAgent)
+            {
+                // crossing failed
+                agent.CrossToNewRegionFail();
+            }
+            agent.IsInTransit = false;
+        }
+
+
+        public ScenePresence CrossAsync(ScenePresence agent, bool isFlying)
+        {
             uint x;
             uint y;
             Vector3 newpos;
@@ -1525,16 +1549,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
                 if (reason == String.Empty)
                     agent.ControllingClient.SendAlertMessage("Cannot cross to region");
                 else
-                    agent.ControllingClient.SendAlertMessage("Cannot cross to region: " + reason);
-                return false;
+                    agent.ControllingClient.SendAlertMessage("Cannot cross to region: " + reason);
+                return agent;
             }

-            agent.IsInTransit = true;
-
-            CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync;
-            d.BeginInvoke(agent, newpos, neighbourRegion, isFlying, version, CrossAgentToNewRegionCompleted, d);
+//            agent.IsInTransit = true;

-            return true;
+            CrossAgentToNewRegionAsync(agent, newpos, neighbourRegion, isFlying, version);
+            agent.IsInTransit = false;
+            return agent;
         }


@@ -1787,8 +1810,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer

             agent.CloseChildAgents(neighbourx, neighboury);

-
-
             // the user may change their profile information in other region,
             // so the userinfo in UserProfileCache is not reliable any more, delete it
             // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
diff --git a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
index 214b07a..0c34c90 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs
@@ -36,6 +36,7 @@ using OpenSim.Region.Framework.Scenes;
 namespace OpenSim.Region.Framework.Interfaces
 {
     public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, GridRegion neighbourRegion, bool isFlying, string version);
+    public delegate ScenePresence CrossAsyncDelegate(ScenePresence agent, bool isFlying);

     public interface IEntityTransferModule
     {
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 754dd96..b746e3a 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -3980,6 +3980,30 @@ namespace OpenSim.Region.Framework.Scenes

         }

+        public void CrossToNewRegionFail()
+        {
+            if (m_requestedSitTargetUUID == UUID.Zero)
+            {
+                bool isFlying = Flying;
+                RemoveFromPhysicalScene();
+
+                Vector3 pos = AbsolutePosition;
+                if (AbsolutePosition.X < 0)
+                    pos.X += Velocity.X * 2;
+                else if (AbsolutePosition.X > Constants.RegionSize)
+                    pos.X -= Velocity.X * 2;
+                if (AbsolutePosition.Y < 0)
+                    pos.Y += Velocity.Y * 2;
+                else if (AbsolutePosition.Y > Constants.RegionSize)
+                    pos.Y -= Velocity.Y * 2;
+                Velocity = Vector3.Zero;
+                AbsolutePosition = pos;
+
+                AddToPhysicalScene(isFlying);
+            }
+
+        }
+
         /// <summary>
         /// Moves the agent outside the region bounds
         /// Tells neighbor region that we're crossing to it
@@ -3996,7 +4020,7 @@ namespace OpenSim.Region.Framework.Scenes
             }
             catch
             {
-                result = m_scene.CrossAgentToNewRegion(this, false);
+//                result = m_scene.CrossAgentToNewRegion(this, false);
             }
  //           if(!result)
  //               parcelRegionCross(true);
ViewGit