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 5e80f5a..b52f48c 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;
@@ -2364,7 +2362,7 @@ namespace OpenSim.Region.Framework.Scenes
2364 if (regionCombinerModule != null) 2362 if (regionCombinerModule != null)
2365 regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID); 2363 regionSize = regionCombinerModule.GetSizeOfMegaregion(m_scene.RegionInfo.RegionID);
2366 else 2364 else
2367 regionSize = new Vector2(Constants.RegionSize); 2365 regionSize = new Vector2(m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY);
2368 2366
2369 if (pos.X < 0 || pos.X >= regionSize.X 2367 if (pos.X < 0 || pos.X >= regionSize.X
2370 || pos.Y < 0 || pos.Y >= regionSize.Y 2368 || pos.Y < 0 || pos.Y >= regionSize.Y
@@ -2382,8 +2380,8 @@ namespace OpenSim.Region.Framework.Scenes
2382// } 2380// }
2383 2381
2384 // Get terrain height for sub-region in a megaregion if necessary 2382 // Get terrain height for sub-region in a megaregion if necessary
2385 int X = (int)((m_scene.RegionInfo.RegionLocX * Constants.RegionSize) + pos.X); 2383 int X = (int)((m_scene.RegionInfo.WorldLocX) + pos.X);
2386 int Y = (int)((m_scene.RegionInfo.RegionLocY * Constants.RegionSize) + pos.Y); 2384 int Y = (int)((m_scene.RegionInfo.WorldLocY) + pos.Y);
2387 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y); 2385 GridRegion target_region = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, X, Y);
2388 // If X and Y is NaN, target_region will be null 2386 // If X and Y is NaN, target_region will be null
2389 if (target_region == null) 2387 if (target_region == null)
@@ -2394,7 +2392,7 @@ namespace OpenSim.Region.Framework.Scenes
2394 if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene)) 2392 if (!SceneManager.Instance.TryGetScene(target_regionID, out targetScene))
2395 targetScene = m_scene; 2393 targetScene = m_scene;
2396 2394
2397 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % Constants.RegionSize), (int)(pos.Y % Constants.RegionSize)]; 2395 float terrainHeight = (float)targetScene.Heightmap[(int)(pos.X % regionSize.X), (int)(pos.Y % regionSize.Y)];
2398 pos.Z = Math.Max(terrainHeight, pos.Z); 2396 pos.Z = Math.Max(terrainHeight, pos.Z);
2399 2397
2400 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is 2398 // Fudge factor. It appears that if one clicks "go here" on a piece of ground, the go here request is
@@ -3429,10 +3427,14 @@ namespace OpenSim.Region.Framework.Scenes
3429 if (!IsInTransit) 3427 if (!IsInTransit)
3430 { 3428 {
3431 Vector3 pos2 = AbsolutePosition; 3429 Vector3 pos2 = AbsolutePosition;
3430 Vector3 origPosition = pos2;
3432 Vector3 vel = Velocity; 3431 Vector3 vel = Velocity;
3433 int neighbor = 0; 3432 int neighbor = 0;
3434 int[] fix = new int[2]; 3433 int[] fix = new int[2];
3435 3434
3435 // Compute the avatar position in the next physics tick.
3436 // If the avatar will be crossing, we force the crossing to happen now
3437 // in the hope that this will make the avatar movement smoother when crossing.
3436 float timeStep = 0.1f; 3438 float timeStep = 0.1f;
3437 pos2.X = pos2.X + (vel.X * timeStep); 3439 pos2.X = pos2.X + (vel.X * timeStep);
3438 pos2.Y = pos2.Y + (vel.Y * timeStep); 3440 pos2.Y = pos2.Y + (vel.Y * timeStep);
@@ -3440,111 +3442,44 @@ namespace OpenSim.Region.Framework.Scenes
3440 3442
3441 if (!IsInTransit) 3443 if (!IsInTransit)
3442 { 3444 {
3443// m_log.DebugFormat( 3445 if (!m_scene.PositionIsInCurrentRegion(pos2))
3444// "[SCENE PRESENCE]: Testing border check for projected position {0} of {1} in {2}",
3445// pos2, Name, Scene.Name);
3446
3447 // Checks if where it's headed exists a region
3448 bool needsTransit = false;
3449 if (m_scene.TestBorderCross(pos2, Cardinals.W))
3450 { 3446 {
3451 if (m_scene.TestBorderCross(pos2, Cardinals.S)) 3447 m_log.DebugFormat("{0} CheckForBorderCrossing: position outside region. {1} in {2} at pos {3}",
3452 { 3448 LogHeader, Name, Scene.Name, pos2);
3453 needsTransit = true; 3449
3454 neighbor = m_scene.HaveNeighbor(Cardinals.SW, ref fix); 3450 // Disconnect from the current region
3455 } 3451 bool isFlying = Flying;
3456 else if (m_scene.TestBorderCross(pos2, Cardinals.N)) 3452 RemoveFromPhysicalScene();
3453 // pos2 is the forcasted position so make that the 'current' position so the crossing
3454 // code will move us into the newly addressed region.
3455 m_pos = pos2;
3456 if (CrossToNewRegion())
3457 { 3457 {
3458 needsTransit = true; 3458 AddToPhysicalScene(isFlying);
3459 neighbor = m_scene.HaveNeighbor(Cardinals.NW, ref fix);
3460 } 3459 }
3461 else 3460 else
3462 { 3461 {
3463 needsTransit = true; 3462 // Tried to make crossing happen but it failed.
3464 neighbor = m_scene.HaveNeighbor(Cardinals.W, ref fix);
3465 }
3466 }
3467 else if (m_scene.TestBorderCross(pos2, Cardinals.E))
3468 {
3469 if (m_scene.TestBorderCross(pos2, Cardinals.S))
3470 {
3471 needsTransit = true;
3472 neighbor = m_scene.HaveNeighbor(Cardinals.SE, ref fix);
3473 }
3474 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3475 {
3476 needsTransit = true;
3477 neighbor = m_scene.HaveNeighbor(Cardinals.NE, ref fix);
3478 }
3479 else
3480 {
3481 needsTransit = true;
3482 neighbor = m_scene.HaveNeighbor(Cardinals.E, ref fix);
3483 }
3484 }
3485 else if (m_scene.TestBorderCross(pos2, Cardinals.S))
3486 {
3487 needsTransit = true;
3488 neighbor = m_scene.HaveNeighbor(Cardinals.S, ref fix);
3489 }
3490 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
3491 {
3492 needsTransit = true;
3493 neighbor = m_scene.HaveNeighbor(Cardinals.N, ref fix);
3494 }
3495
3496 // Makes sure avatar does not end up outside region
3497 if (neighbor <= 0)
3498 {
3499 if (needsTransit)
3500 {
3501 if (m_requestedSitTargetUUID == UUID.Zero)
3502 {
3503 bool isFlying = Flying;
3504 RemoveFromPhysicalScene();
3505
3506 Vector3 pos = AbsolutePosition;
3507 if (AbsolutePosition.X < 0)
3508 pos.X += Velocity.X * 2;
3509 else if (AbsolutePosition.X > Constants.RegionSize)
3510 pos.X -= Velocity.X * 2;
3511 if (AbsolutePosition.Y < 0)
3512 pos.Y += Velocity.Y * 2;
3513 else if (AbsolutePosition.Y > Constants.RegionSize)
3514 pos.Y -= Velocity.Y * 2;
3515 Velocity = Vector3.Zero;
3516 AbsolutePosition = pos;
3517
3518// m_log.DebugFormat("[SCENE PRESENCE]: Prevented flyoff for {0} at {1}", Name, AbsolutePosition);
3519
3520 AddToPhysicalScene(isFlying);
3521 }
3522 }
3523 }
3524 else if (neighbor > 0)
3525 {
3526 if (!CrossToNewRegion())
3527 {
3528 if (m_requestedSitTargetUUID == UUID.Zero) 3463 if (m_requestedSitTargetUUID == UUID.Zero)
3529 { 3464 {
3530 bool isFlying = Flying; 3465 m_log.DebugFormat("{0} CheckForBorderCrossing: Crossing failed. Restoring old position.", LogHeader);
3531 RemoveFromPhysicalScene(); 3466 const float borderFudge = 0.1f;
3532 3467
3533 Vector3 pos = AbsolutePosition; 3468 if (origPosition.X < 0)
3534 if (AbsolutePosition.X < 0) 3469 origPosition.X = borderFudge;
3535 pos.X += Velocity.X * 2; 3470 else if (origPosition.X > (float)m_scene.RegionInfo.RegionSizeX)
3536 else if (AbsolutePosition.X > Constants.RegionSize) 3471 origPosition.X = (float)m_scene.RegionInfo.RegionSizeX - borderFudge;
3537 pos.X -= Velocity.X * 2; 3472 if (origPosition.Y < 0)
3538 if (AbsolutePosition.Y < 0) 3473 origPosition.Y = borderFudge;
3539 pos.Y += Velocity.Y * 2; 3474 else if (origPosition.Y > (float)m_scene.RegionInfo.RegionSizeY)
3540 else if (AbsolutePosition.Y > Constants.RegionSize) 3475 origPosition.Y = (float)m_scene.RegionInfo.RegionSizeY - borderFudge;
3541 pos.Y -= Velocity.Y * 2;
3542 Velocity = Vector3.Zero; 3476 Velocity = Vector3.Zero;
3543 AbsolutePosition = pos; 3477 AbsolutePosition = origPosition;
3544 3478
3545 AddToPhysicalScene(isFlying); 3479 AddToPhysicalScene(isFlying);
3546 } 3480 }
3547 } 3481 }
3482
3548 } 3483 }
3549 } 3484 }
3550 else 3485 else
@@ -3586,7 +3521,7 @@ namespace OpenSim.Region.Framework.Scenes
3586 3521
3587 // Put the child agent back at the center 3522 // Put the child agent back at the center
3588 AbsolutePosition 3523 AbsolutePosition
3589 = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); 3524 = new Vector3(((float)m_scene.RegionInfo.RegionSizeX * 0.5f), ((float)m_scene.RegionInfo.RegionSizeY * 0.5f), 70);
3590 3525
3591 Animator.ResetAnimations(); 3526 Animator.ResetAnimations();
3592 } 3527 }
@@ -3613,9 +3548,7 @@ namespace OpenSim.Region.Framework.Scenes
3613 if (handle != Scene.RegionInfo.RegionHandle) 3548 if (handle != Scene.RegionInfo.RegionHandle)
3614 { 3549 {
3615 uint x, y; 3550 uint x, y;
3616 Utils.LongToUInts(handle, out x, out y); 3551 Util.RegionHandleToRegionLoc(handle, out x, out y);
3617 x = x / Constants.RegionSize;
3618 y = y / Constants.RegionSize;
3619 3552
3620// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); 3553// m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
3621// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); 3554// m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
@@ -3696,8 +3629,9 @@ namespace OpenSim.Region.Framework.Scenes
3696 return; 3629 return;
3697 3630
3698 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); 3631 //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY);
3699 int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; 3632 // Find the distance (in meters) between the two regions
3700 int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; 3633 uint shiftx = Util.RegionToWorldLoc(rRegionX - tRegionX);
3634 uint shifty = Util.RegionToWorldLoc(rRegionY - tRegionY);
3701 3635
3702 Vector3 offset = new Vector3(shiftx, shifty, 0f); 3636 Vector3 offset = new Vector3(shiftx, shifty, 0f);
3703 3637