aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs154
1 files changed, 44 insertions, 110 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index cf98ef2..a98baea 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -76,6 +76,7 @@ namespace OpenSim.Region.Framework.Scenes
76 public class ScenePresence : EntityBase, IScenePresence 76 public class ScenePresence : EntityBase, IScenePresence
77 { 77 {
78 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 78 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
79 private static readonly String LogHeader = "[SCENE PRESENCE]";
79 80
80// ~ScenePresence() 81// ~ScenePresence()
81// { 82// {
@@ -749,9 +750,8 @@ namespace OpenSim.Region.Framework.Scenes
749 foreach (ulong handle in seeds.Keys) 750 foreach (ulong handle in seeds.Keys)
750 { 751 {
751 uint x, y; 752 uint x, y;
752 Utils.LongToUInts(handle, out x, out y); 753 Util.RegionHandleToRegionLoc(handle, out x, out y);
753 x = x / Constants.RegionSize; 754
754 y = y / Constants.RegionSize;
755 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) 755 if (Util.IsOutsideView(DrawDistance, x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY))
756 { 756 {
757 old.Add(handle); 757 old.Add(handle);
@@ -773,9 +773,7 @@ namespace OpenSim.Region.Framework.Scenes
773 foreach (KeyValuePair<ulong, string> kvp in KnownRegions) 773 foreach (KeyValuePair<ulong, string> kvp in KnownRegions)
774 { 774 {
775 uint x, y; 775 uint x, y;
776 Utils.LongToUInts(kvp.Key, out x, out y); 776 Util.RegionHandleToRegionLoc(kvp.Key, out x, out y);
777 x = x / Constants.RegionSize;
778 y = y / Constants.RegionSize;
779 m_log.Info(" >> "+x+", "+y+": "+kvp.Value); 777 m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
780 } 778 }
781 } 779 }
@@ -1109,7 +1107,7 @@ namespace OpenSim.Region.Framework.Scenes
1109 1107
1110 float posZLimit = 0; 1108 float posZLimit = 0;
1111 1109
1112 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1110 if (pos.X < m_scene.RegionInfo.RegionSizeX && pos.Y < m_scene.RegionInfo.RegionSizeY)
1113 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1111 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
1114 1112
1115 float newPosZ = posZLimit + localAVHeight / 2; 1113 float newPosZ = posZLimit + localAVHeight / 2;
@@ -2362,7 +2360,7 @@ namespace OpenSim.Region.Framework.Scenes
2362 if (regionCombinerModule != null) 2360 if (regionCombinerModule != null)
2363 regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID); 2361 regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID);
2364 else 2362 else
2365 regionSize = new Vector2(Constants.RegionSize); 2363 regionSize = new Vector2(m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);
2366 2364
2367 if (pos.X < 0 || pos.X >= regionSize.X 2365 if (pos.X < 0 || pos.X >= regionSize.X
2368 || pos.Y < 0 || pos.Y >= regionSize.Y 2366 || pos.Y < 0 || pos.Y >= regionSize.Y
@@ -2380,8 +2378,8 @@ namespace OpenSim.Region.Framework.Scenes
2380// } 2378// }
2381 2379
2382 // Get terrain height for sub-region in a megaregion if necessary 2380 // Get terrain height for sub-region in a megaregion if necessary
2383 int X = (int)((m_scene.RegionInfo.RegionLocX * Constants.RegionSize) + pos.X); 2381 int X = (int)((m_scene.RegionInfo.WorldLocX) + pos.X);
2384 int Y = (int)((m_scene.RegionInfo.RegionLocY * Constants.RegionSize) + pos.Y); 2382 int Y = (int)((m_scene.RegionInfo.WorldLocY) + pos.Y);
2385 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y); 2383 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y);
2386 // If X and Y is NaN, target_region will be null 2384 // If X and Y is NaN, target_region will be null
2387 if (target_region == null) 2385 if (target_region == null)
@@ -2392,7 +2390,7 @@ namespace OpenSim.Region.Framework.Scenes
2392 if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene)) 2390 if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene))
2393 targetScene = m_scene; 2391 targetScene = m_scene;
2394 2392
2395 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % Constants.RegionSize), (int)(pos.Y % Constants.RegionSize)]; 2393 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)];
2396 pos.Z = Math.Max(terrainHeight, pos.Z); 2394 pos.Z = Math.Max(terrainHeight, pos.Z);
2397 2395
2398 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is 2396 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is
@@ -3427,10 +3425,14 @@ namespace OpenSim.Region.Framework.Scenes
3427 if (!IsInTransit) 3425 if (!IsInTransit)
3428 { 3426 {
3429 Vector3 pos2 = AbsolutePosition; 3427 Vector3 pos2 = AbsolutePosition;
3428 Vector3 origPosition = pos2;
3430 Vector3 vel = Velocity; 3429 Vector3 vel = Velocity;
3431 int neighbor = 0; 3430 int neighbor = 0;
3432 int[] fix = new int[2]; 3431 int[] fix = new int[2];
3433 3432
3433 // Compute the avatar position in the next physics tick.
3434 // If the avatar will be crossing, we force the crossing to happen now
3435 // in the hope that this will make the avatar movement smoother when crossing.
3434 float timeStep = 0.1f; 3436 float timeStep = 0.1f;
3435 pos2.X = pos2.X + (vel.X * timeStep); 3437 pos2.X = pos2.X + (vel.X * timeStep);
3436 pos2.Y = pos2.Y + (vel.Y * timeStep); 3438 pos2.Y = pos2.Y + (vel.Y * timeStep);
@@ -3438,111 +3440,44 @@ namespace OpenSim.Region.Framework.Scenes
3438 3440
3439 if (!IsInTransit) 3441 if (!IsInTransit)
3440 { 3442 {
3441// m_log.DebugFormat( 3443 if (!m_scene.PositionIsInCurrentRegion(pos2))
3442// "[SCENE PRESENCE]: Testing border check for projected position {0} of {1} in {2}",
3443// pos2, Name, Scene.Name);
3444
3445 // Checks if where it's headed exists a region
3446 bool needsTransit = false;
3447 if (m_scene.TestBorderCross(pos2, Cardinals.W))
3448 { 3444 {
3449 if (m_scene.TestBorderCross(pos2, Cardinals.S)) 3445 m_log.DebugFormat("{0} CheckForBorderCrossing: position outside region. {1} in {2} at pos {3}",
3450 { 3446 LogHeader, Name, Scene.Name, pos2);
3451 needsTransit = true; 3447
3452 neighbor = m_scene.HaveNeighbor(Cardinals.SW, ref fix); 3448 // Disconnect from the current region
3453 } 3449 bool isFlying = Flying;
3454 else if (m_scene.TestBorderCross(pos2, Cardinals.N)) 3450 RemoveFromPhysicalScene();
3451 // pos2 is the forcasted position so make that the 'current' position so the crossing
3452 // code will move us into the newly addressed region.
3453 m_pos = pos2;
3454 if (CrossToNewRegion())
3455 { 3455 {
3456 needsTransit = true; 3456 AddToPhysicalScene(isFlying);
3457 neighbor = m_scene.HaveNeighbor(Cardinals.NW, ref fix);
3458 } 3457 }
3459 else 3458 else
3460 { 3459 {
3461 needsTransit = true; 3460 // Tried to make crossing happen but it failed.
3462 neighbor = m_scene.HaveNeighbor(Cardinals.W, ref fix);
3463 }
3464 }
3465 else if (m_scene.TestBorderCross(pos2, Cardinals.E))
3466 {
3467 if (m_scene.TestBorderCross(pos2, Cardinals.S))
3468 {
3469 needsTransit = true;
3470 neighbor = m_scene.HaveNeighbor(Cardinals.SE, ref fix);
3471 }
3472 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3473 {
3474 needsTransit = true;
3475 neighbor = m_scene.HaveNeighbor(Cardinals.NE, ref fix);
3476 }
3477 else
3478 {
3479 needsTransit = true;
3480 neighbor = m_scene.HaveNeighbor(Cardinals.E, ref fix);
3481 }
3482 }
3483 else if (m_scene.TestBorderCross(pos2, Cardinals.S))
3484 {
3485 needsTransit = true;
3486 neighbor = m_scene.HaveNeighbor(Cardinals.S, ref fix);
3487 }
3488 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3489 {
3490 needsTransit = true;
3491 neighbor = m_scene.HaveNeighbor(Cardinals.N, ref fix);
3492 }
3493
3494 // Makes sure avatar does not end up outside region
3495 if (neighbor <= 0)
3496 {
3497 if (needsTransit)
3498 {
3499 if (m_requestedSitTargetUUID == UUID.Zero)
3500 {
3501 bool isFlying = Flying;
3502 RemoveFromPhysicalScene();
3503
3504 Vector3 pos = AbsolutePosition;
3505 if (AbsolutePosition.X < 0)
3506 pos.X += Velocity.X * 2;
3507 else if (AbsolutePosition.X > Constants.RegionSize)
3508 pos.X -= Velocity.X * 2;
3509 if (AbsolutePosition.Y < 0)
3510 pos.Y += Velocity.Y * 2;
3511 else if (AbsolutePosition.Y > Constants.RegionSize)
3512 pos.Y -= Velocity.Y * 2;
3513 Velocity = Vector3.Zero;
3514 AbsolutePosition = pos;
3515
3516// m_log.DebugFormat("[SCENE PRESENCE]: Prevented flyoff for {0} at {1}", Name, AbsolutePosition);
3517
3518 AddToPhysicalScene(isFlying);
3519 }
3520 }
3521 }
3522 else if (neighbor > 0)
3523 {
3524 if (!CrossToNewRegion())
3525 {
3526 if (m_requestedSitTargetUUID == UUID.Zero) 3461 if (m_requestedSitTargetUUID == UUID.Zero)
3527 { 3462 {
3528 bool isFlying = Flying; 3463 m_log.DebugFormat("{0} CheckForBorderCrossing: Crossing failed. Restoring old position.", LogHeader);
3529 RemoveFromPhysicalScene(); 3464 const float borderFudge = 0.1f;
3530 3465
3531 Vector3 pos = AbsolutePosition; 3466 if (origPosition.X < 0)
3532 if (AbsolutePosition.X < 0) 3467 origPosition.X = borderFudge;
3533 pos.X += Velocity.X * 2; 3468 else if (origPosition.X > (float)m_scene.RegionInfo.RegionSizeX)
3534 else if (AbsolutePosition.X > Constants.RegionSize) 3469 origPosition.X = (float)m_scene.RegionInfo.RegionSizeX - borderFudge;
3535 pos.X -= Velocity.X * 2; 3470 if (origPosition.Y < 0)
3536 if (AbsolutePosition.Y < 0) 3471 origPosition.Y = borderFudge;
3537 pos.Y += Velocity.Y * 2; 3472 else if (origPosition.Y > (float)m_scene.RegionInfo.RegionSizeY)
3538 else if (AbsolutePosition.Y > Constants.RegionSize) 3473 origPosition.Y = (float)m_scene.RegionInfo.RegionSizeY - borderFudge;
3539 pos.Y -= Velocity.Y * 2;
3540 Velocity = Vector3.Zero; 3474 Velocity = Vector3.Zero;
3541 AbsolutePosition = pos; 3475 AbsolutePosition = origPosition;
3542 3476
3543 AddToPhysicalScene(isFlying); 3477 AddToPhysicalScene(isFlying);
3544 } 3478 }
3545 } 3479 }
3480
3546 } 3481 }
3547 } 3482 }
3548 else 3483 else
@@ -3584,7 +3519,7 @@ namespace OpenSim.Region.Framework.Scenes
3584 3519
3585 // Put the child agent back at the center 3520 // Put the child agent back at the center
3586 AbsolutePosition 3521 AbsolutePosition
3587 = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); 3522 = new Vector3(((float)m_scene.RegionInfo.RegionSizeX * 0.5f), ((float)m_scene.RegionInfo.RegionSizeY * 0.5f), 70);
3588 3523
3589 Animator.ResetAnimations(); 3524 Animator.ResetAnimations();
3590 } 3525 }
@@ -3611,9 +3546,7 @@ namespace OpenSim.Region.Framework.Scenes
3611 if (handle != Scene.RegionInfo.RegionHandle) 3546 if (handle != Scene.RegionInfo.RegionHandle)
3612 { 3547 {
3613 uint x, y; 3548 uint x, y;
3614 Utils.LongToUInts(handle, out x, out y); 3549 Util.RegionHandleToRegionLoc(handle, out x, out y);
3615 x = x / Constants.RegionSize;
3616 y = y / Constants.RegionSize;
3617 3550
3618// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); 3551// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
3619// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); 3552// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
@@ -3694,8 +3627,9 @@ namespace OpenSim.Region.Framework.Scenes
3694 return; 3627 return;
3695 3628
3696 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); 3629 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY);
3697 int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; 3630 // Find the distance (in meters) between the two regions
3698 int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; 3631 uint shiftx = Util.RegionToWorldLoc(rRegionX - tRegionX);
3632 uint shifty = Util.RegionToWorldLoc(rRegionY - tRegionY);
3699 3633
3700 Vector3 offset = new Vector3(shiftx, shifty, 0f); 3634 Vector3 offset = new Vector3(shiftx, shifty, 0f);
3701 3635