aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs85
1 files changed, 41 insertions, 44 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 6d2e2c8..fb35a54 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -6394,64 +6394,61 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6394 { 6394 {
6395 m_host.AddScriptLPS(1); 6395 m_host.AddScriptLPS(1);
6396 6396
6397 // edge will be used to pass the Region Coordinates offset 6397 if(dir.x == 0.0 && dir.y == 0.0)
6398 // we want to check for a neighboring sim 6398 return 1; // SL wiki
6399 LSL_Vector edge = new LSL_Vector(0, 0, 0); 6399
6400 float rsx = World.RegionInfo.RegionSizeX;
6401 float rsy = World.RegionInfo.RegionSizeY;
6402
6403 // can understand what sl does if position is not in region, so do something :)
6404 float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
6405 float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
6406
6407 float ex, ey;
6400 6408
6401 if (dir.x == 0) 6409 if (dir.x == 0)
6402 { 6410 {
6403 if (dir.y == 0) 6411 ex = px;
6404 { 6412 ey = dir.y > 0.0 ? rsy + 1.0f : -1.0f;
6405 // Direction vector is 0,0 so return 6413 }
6406 // false since we're staying in the sim 6414 else if(dir.y == 0.0f)
6407 return 0; 6415 {
6408 } 6416 ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
6409 else 6417 ey = py;
6410 {
6411 // Y is the only valid direction
6412 edge.y = dir.y / Math.Abs(dir.y) * (World.RegionInfo.RegionSizeY / Constants.RegionSize);
6413 }
6414 } 6418 }
6415 else 6419 else
6416 { 6420 {
6417 LSL_Float mag; 6421 float dx = (float) dir.x;
6418 if (dir.x > 0) 6422 float dy = (float) dir.y;
6419 {
6420 mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x;
6421 }
6422 else
6423 {
6424 mag = (pos.x/dir.x);
6425 }
6426 6423
6427 mag = Math.Abs(mag); 6424 float t1 = dx * dx + dy * dy;
6425 dx /= t1;
6426 dy /= t1;
6428 6427
6429 edge.y = pos.y + (dir.y * mag); 6428 if(dx > 0)
6430 6429 t1 = (rsx + 1f - px)/dx;
6431 if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0)
6432 {
6433 // Y goes out of bounds first
6434 edge.y = dir.y / Math.Abs(dir.y) * (World.RegionInfo.RegionSizeY / Constants.RegionSize);
6435 }
6436 else 6430 else
6437 { 6431 t1 = -(px + 1f)/dx;
6438 // X goes out of bounds first or its a corner exit
6439 edge.y = 0;
6440 edge.x = dir.x / Math.Abs(dir.x) * (World.RegionInfo.RegionSizeY / Constants.RegionSize);
6441 }
6442 }
6443 6432
6444 List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
6445 6433
6446 uint neighborX = World.RegionInfo.RegionLocX + (uint)edge.x; 6434 float t2;
6447 uint neighborY = World.RegionInfo.RegionLocY + (uint)edge.y; 6435 if(dy > 0)
6436 t2 = (rsy + 1f - py)/dy;
6437 else
6438 t2 = -(py + 1f)/dy;
6448 6439
6449 foreach (GridRegion sri in neighbors) 6440 if(t1 > t2)
6450 { 6441 t1 = t2;
6451 if (sri.RegionCoordX == neighborX && sri.RegionCoordY == neighborY) 6442
6452 return 0; 6443 ex = px + t1 * dx;
6444 ey = py + t1 * dy;
6453 } 6445 }
6454 6446
6447 ex += World.RegionInfo.WorldLocX;
6448 ey += World.RegionInfo.WorldLocY;
6449
6450 if(World.GridService.GetRegionByPosition(World.RegionInfo.ScopeID, (int)ex, (int)ey) != null)
6451 return 0;
6455 return 1; 6452 return 1;
6456 } 6453 }
6457 6454