aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs')
-rw-r--r--OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs428
1 files changed, 276 insertions, 152 deletions
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
index d8d9554..40daf13 100644
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
+++ b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
@@ -43,9 +43,8 @@ using Mono.Addins;
43[assembly: AddinDependency("OpenSim", "0.5")] 43[assembly: AddinDependency("OpenSim", "0.5")]
44namespace OpenSim.Region.RegionCombinerModule 44namespace OpenSim.Region.RegionCombinerModule
45{ 45{
46
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] 46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
48 public class RegionCombinerModule : ISharedRegionModule 47 public class RegionCombinerModule : ISharedRegionModule, IRegionCombinerModule
49 { 48 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 50
@@ -59,8 +58,22 @@ namespace OpenSim.Region.RegionCombinerModule
59 get { return null; } 58 get { return null; }
60 } 59 }
61 60
62 private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>(); 61 /// <summary>
62 /// Is this module enabled?
63 /// </summary>
63 private bool enabledYN = false; 64 private bool enabledYN = false;
65
66 /// <summary>
67 /// This holds the root regions for the megaregions.
68 /// </summary>
69 /// <remarks>
70 /// Usually there is only ever one megaregion (and hence only one entry here).
71 /// </remarks>
72 private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>();
73
74 /// <summary>
75 /// The scenes that comprise the megaregion.
76 /// </summary>
64 private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>(); 77 private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>();
65 78
66 public void Initialise(IConfigSource source) 79 public void Initialise(IConfigSource source)
@@ -69,9 +82,11 @@ namespace OpenSim.Region.RegionCombinerModule
69 enabledYN = myConfig.GetBoolean("CombineContiguousRegions", false); 82 enabledYN = myConfig.GetBoolean("CombineContiguousRegions", false);
70 83
71 if (enabledYN) 84 if (enabledYN)
85 {
72 MainConsole.Instance.Commands.AddCommand( 86 MainConsole.Instance.Commands.AddCommand(
73 "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms", 87 "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms",
74 "Fixes phantom objects after an import to megaregions", FixPhantoms); 88 "Fixes phantom objects after an import to megaregions", FixPhantoms);
89 }
75 } 90 }
76 91
77 public void Close() 92 public void Close()
@@ -80,6 +95,8 @@ namespace OpenSim.Region.RegionCombinerModule
80 95
81 public void AddRegion(Scene scene) 96 public void AddRegion(Scene scene)
82 { 97 {
98 if (enabledYN)
99 scene.RegisterModuleInterface<IRegionCombinerModule>(this);
83 } 100 }
84 101
85 public void RemoveRegion(Scene scene) 102 public void RemoveRegion(Scene scene)
@@ -89,7 +106,110 @@ namespace OpenSim.Region.RegionCombinerModule
89 public void RegionLoaded(Scene scene) 106 public void RegionLoaded(Scene scene)
90 { 107 {
91 if (enabledYN) 108 if (enabledYN)
109 {
92 RegionLoadedDoWork(scene); 110 RegionLoadedDoWork(scene);
111
112 scene.EventManager.OnNewPresence += NewPresence;
113 }
114 }
115
116 public bool IsRootForMegaregion(UUID regionId)
117 {
118 lock (m_regions)
119 return m_regions.ContainsKey(regionId);
120 }
121
122 public Vector2 GetSizeOfMegaregion(UUID regionId)
123 {
124 lock (m_regions)
125 {
126 if (m_regions.ContainsKey(regionId))
127 {
128 RegionConnections rootConn = m_regions[regionId];
129
130 return new Vector2((float)rootConn.XEnd, (float)rootConn.YEnd);
131 }
132 }
133
134 throw new Exception(string.Format("Region with id {0} not found", regionId));
135 }
136
137 private void NewPresence(ScenePresence presence)
138 {
139 if (presence.IsChildAgent)
140 {
141 byte[] throttleData;
142
143 try
144 {
145 throttleData = presence.ControllingClient.GetThrottlesPacked(1);
146 }
147 catch (NotImplementedException)
148 {
149 return;
150 }
151
152 if (throttleData == null)
153 return;
154
155 if (throttleData.Length == 0)
156 return;
157
158 if (throttleData.Length != 28)
159 return;
160
161 byte[] adjData;
162 int pos = 0;
163
164 if (!BitConverter.IsLittleEndian)
165 {
166 byte[] newData = new byte[7 * 4];
167 Buffer.BlockCopy(throttleData, 0, newData, 0, 7 * 4);
168
169 for (int i = 0; i < 7; i++)
170 Array.Reverse(newData, i * 4, 4);
171
172 adjData = newData;
173 }
174 else
175 {
176 adjData = throttleData;
177 }
178
179 // 0.125f converts from bits to bytes
180 int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
181 int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
182 int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
183 int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
184 int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
185 int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
186 int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
187 // State is a subcategory of task that we allocate a percentage to
188
189
190 //int total = resend + land + wind + cloud + task + texture + asset;
191
192 byte[] data = new byte[7 * 4];
193 int ii = 0;
194
195 Buffer.BlockCopy(Utils.FloatToBytes(resend), 0, data, ii, 4); ii += 4;
196 Buffer.BlockCopy(Utils.FloatToBytes(land * 50), 0, data, ii, 4); ii += 4;
197 Buffer.BlockCopy(Utils.FloatToBytes(wind), 0, data, ii, 4); ii += 4;
198 Buffer.BlockCopy(Utils.FloatToBytes(cloud), 0, data, ii, 4); ii += 4;
199 Buffer.BlockCopy(Utils.FloatToBytes(task), 0, data, ii, 4); ii += 4;
200 Buffer.BlockCopy(Utils.FloatToBytes(texture), 0, data, ii, 4); ii += 4;
201 Buffer.BlockCopy(Utils.FloatToBytes(asset), 0, data, ii, 4);
202
203 try
204 {
205 presence.ControllingClient.SetChildAgentThrottle(data);
206 }
207 catch (NotImplementedException)
208 {
209 return;
210 }
211
212 }
93 } 213 }
94 214
95 private void RegionLoadedDoWork(Scene scene) 215 private void RegionLoadedDoWork(Scene scene)
@@ -124,24 +244,21 @@ namespace OpenSim.Region.RegionCombinerModule
124 westBorder.CrossDirection = Cardinals.W; 244 westBorder.CrossDirection = Cardinals.W;
125 scene.WestBorders[0] = westBorder; 245 scene.WestBorders[0] = westBorder;
126 246
127 247 RegionConnections newConn = new RegionConnections();
128 248 newConn.ConnectedRegions = new List<RegionData>();
129 RegionConnections regionConnections = new RegionConnections(); 249 newConn.RegionScene = scene;
130 regionConnections.ConnectedRegions = new List<RegionData>(); 250 newConn.RegionLandChannel = scene.LandChannel;
131 regionConnections.RegionScene = scene; 251 newConn.RegionId = scene.RegionInfo.originRegionID;
132 regionConnections.RegionLandChannel = scene.LandChannel; 252 newConn.X = scene.RegionInfo.RegionLocX;
133 regionConnections.RegionId = scene.RegionInfo.originRegionID; 253 newConn.Y = scene.RegionInfo.RegionLocY;
134 regionConnections.X = scene.RegionInfo.RegionLocX; 254 newConn.XEnd = (int)Constants.RegionSize;
135 regionConnections.Y = scene.RegionInfo.RegionLocY; 255 newConn.YEnd = (int)Constants.RegionSize;
136 regionConnections.XEnd = (int)Constants.RegionSize;
137 regionConnections.YEnd = (int)Constants.RegionSize;
138
139 256
140 lock (m_regions) 257 lock (m_regions)
141 { 258 {
142 bool connectedYN = false; 259 bool connectedYN = false;
143 260
144 foreach (RegionConnections conn in m_regions.Values) 261 foreach (RegionConnections rootConn in m_regions.Values)
145 { 262 {
146 #region commented 263 #region commented
147 /* 264 /*
@@ -306,13 +423,9 @@ namespace OpenSim.Region.RegionCombinerModule
306 //xxy 423 //xxy
307 //xxx 424 //xxx
308 425
309 426 if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY >= newConn.PosY)
310 if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd
311 >= (regionConnections.X * (int)Constants.RegionSize))
312 && (((int)conn.Y * (int)Constants.RegionSize)
313 >= (regionConnections.Y * (int)Constants.RegionSize)))
314 { 427 {
315 connectedYN = DoWorkForOneRegionOverPlusXY(conn, regionConnections, scene); 428 connectedYN = DoWorkForOneRegionOverPlusXY(rootConn, newConn, scene);
316 break; 429 break;
317 } 430 }
318 431
@@ -320,12 +433,9 @@ namespace OpenSim.Region.RegionCombinerModule
320 //xyx 433 //xyx
321 //xxx 434 //xxx
322 //xxx 435 //xxx
323 if ((((int)conn.X * (int)Constants.RegionSize) 436 if (rootConn.PosX >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
324 >= (regionConnections.X * (int)Constants.RegionSize))
325 && (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
326 >= (regionConnections.Y * (int)Constants.RegionSize)))
327 { 437 {
328 connectedYN = DoWorkForOneRegionOverXPlusY(conn, regionConnections, scene); 438 connectedYN = DoWorkForOneRegionOverXPlusY(rootConn, newConn, scene);
329 break; 439 break;
330 } 440 }
331 441
@@ -333,12 +443,9 @@ namespace OpenSim.Region.RegionCombinerModule
333 //xxy 443 //xxy
334 //xxx 444 //xxx
335 //xxx 445 //xxx
336 if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd 446 if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
337 >= (regionConnections.X * (int)Constants.RegionSize))
338 && (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
339 >= (regionConnections.Y * (int)Constants.RegionSize)))
340 { 447 {
341 connectedYN = DoWorkForOneRegionOverPlusXPlusY(conn, regionConnections, scene); 448 connectedYN = DoWorkForOneRegionOverPlusXPlusY(rootConn, newConn, scene);
342 break; 449 break;
343 450
344 } 451 }
@@ -347,66 +454,63 @@ namespace OpenSim.Region.RegionCombinerModule
347 // If !connectYN means that this region is a root region 454 // If !connectYN means that this region is a root region
348 if (!connectedYN) 455 if (!connectedYN)
349 { 456 {
350 DoWorkForRootRegion(regionConnections, scene); 457 DoWorkForRootRegion(newConn, scene);
351
352 } 458 }
353 } 459 }
460
354 // Set up infinite borders around the entire AABB of the combined ConnectedRegions 461 // Set up infinite borders around the entire AABB of the combined ConnectedRegions
355 AdjustLargeRegionBounds(); 462 AdjustLargeRegionBounds();
356 } 463 }
357 464
358 private bool DoWorkForOneRegionOverPlusXY(RegionConnections conn, RegionConnections regionConnections, Scene scene) 465 private bool DoWorkForOneRegionOverPlusXY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
359 { 466 {
360 Vector3 offset = Vector3.Zero; 467 Vector3 offset = Vector3.Zero;
361 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) - 468 offset.X = newConn.PosX - rootConn.PosX;
362 ((conn.X * (int)Constants.RegionSize))); 469 offset.Y = newConn.PosY - rootConn.PosY;
363 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
364 ((conn.Y * (int)Constants.RegionSize)));
365 470
366 Vector3 extents = Vector3.Zero; 471 Vector3 extents = Vector3.Zero;
367 extents.Y = conn.YEnd; 472 extents.Y = rootConn.YEnd;
368 extents.X = conn.XEnd + regionConnections.XEnd; 473 extents.X = rootConn.XEnd + newConn.XEnd;
369 474
370 conn.UpdateExtents(extents); 475 rootConn.UpdateExtents(extents);
371 476
372 m_log.DebugFormat("Scene: {0} to the west of Scene{1} Offset: {2}. Extents:{3}", 477 m_log.DebugFormat(
373 conn.RegionScene.RegionInfo.RegionName, 478 "[REGION COMBINER MODULE]: Root region {0} is to the west of region {1}, Offset: {2}, Extents: {3}",
374 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); 479 rootConn.RegionScene.RegionInfo.RegionName,
480 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
375 481
376 scene.BordersLocked = true; 482 scene.BordersLocked = true;
377 conn.RegionScene.BordersLocked = true; 483 rootConn.RegionScene.BordersLocked = true;
378 484
379 RegionData ConnectedRegion = new RegionData(); 485 RegionData ConnectedRegion = new RegionData();
380 ConnectedRegion.Offset = offset; 486 ConnectedRegion.Offset = offset;
381 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID; 487 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
382 ConnectedRegion.RegionScene = scene; 488 ConnectedRegion.RegionScene = scene;
383 conn.ConnectedRegions.Add(ConnectedRegion); 489 rootConn.ConnectedRegions.Add(ConnectedRegion);
384 490
385 // Inform root region Physics about the extents of this region 491 // Inform root region Physics about the extents of this region
386 conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); 492 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
387 493
388 // Inform Child region that it needs to forward it's terrain to the root region 494 // Inform Child region that it needs to forward it's terrain to the root region
389 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); 495 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
390 496
391 // Extend the borders as appropriate 497 // Extend the borders as appropriate
392 lock (conn.RegionScene.EastBorders) 498 lock (rootConn.RegionScene.EastBorders)
393 conn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize; 499 rootConn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize;
394 500
395 lock (conn.RegionScene.NorthBorders) 501 lock (rootConn.RegionScene.NorthBorders)
396 conn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize; 502 rootConn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
397 503
398 lock (conn.RegionScene.SouthBorders) 504 lock (rootConn.RegionScene.SouthBorders)
399 conn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize; 505 rootConn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
400 506
401 lock (scene.WestBorders) 507 lock (scene.WestBorders)
402 { 508 {
403 509 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
404
405 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - conn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
406 510
407 // Trigger auto teleport to root region 511 // Trigger auto teleport to root region
408 scene.WestBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 512 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
409 scene.WestBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 513 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
410 } 514 }
411 515
412 // Reset Terrain.. since terrain loads before we get here, we need to load 516 // Reset Terrain.. since terrain loads before we get here, we need to load
@@ -415,56 +519,58 @@ namespace OpenSim.Region.RegionCombinerModule
415 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); 519 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
416 520
417 // Unlock borders 521 // Unlock borders
418 conn.RegionScene.BordersLocked = false; 522 rootConn.RegionScene.BordersLocked = false;
419 scene.BordersLocked = false; 523 scene.BordersLocked = false;
420 524
421 // Create a client event forwarder and add this region's events to the root region. 525 // Create a client event forwarder and add this region's events to the root region.
422 if (conn.ClientEventForwarder != null) 526 if (rootConn.ClientEventForwarder != null)
423 conn.ClientEventForwarder.AddSceneToEventForwarding(scene); 527 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
424 528
425 return true; 529 return true;
426 } 530 }
427 531
428 private bool DoWorkForOneRegionOverXPlusY(RegionConnections conn, RegionConnections regionConnections, Scene scene) 532 private bool DoWorkForOneRegionOverXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
429 { 533 {
430 Vector3 offset = Vector3.Zero; 534 Vector3 offset = Vector3.Zero;
431 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) - 535 offset.X = newConn.PosX - rootConn.PosX;
432 ((conn.X * (int)Constants.RegionSize))); 536 offset.Y = newConn.PosY - rootConn.PosY;
433 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
434 ((conn.Y * (int)Constants.RegionSize)));
435 537
436 Vector3 extents = Vector3.Zero; 538 Vector3 extents = Vector3.Zero;
437 extents.Y = regionConnections.YEnd + conn.YEnd; 539 extents.Y = newConn.YEnd + rootConn.YEnd;
438 extents.X = conn.XEnd; 540 extents.X = rootConn.XEnd;
439 conn.UpdateExtents(extents); 541 rootConn.UpdateExtents(extents);
440 542
441 scene.BordersLocked = true; 543 scene.BordersLocked = true;
442 conn.RegionScene.BordersLocked = true; 544 rootConn.RegionScene.BordersLocked = true;
443 545
444 RegionData ConnectedRegion = new RegionData(); 546 RegionData ConnectedRegion = new RegionData();
445 ConnectedRegion.Offset = offset; 547 ConnectedRegion.Offset = offset;
446 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID; 548 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
447 ConnectedRegion.RegionScene = scene; 549 ConnectedRegion.RegionScene = scene;
448 conn.ConnectedRegions.Add(ConnectedRegion); 550 rootConn.ConnectedRegions.Add(ConnectedRegion);
551
552 m_log.DebugFormat(
553 "[REGION COMBINER MODULE]: Root region {0} is to the south of region {1}, Offset: {2}, Extents: {3}",
554 rootConn.RegionScene.RegionInfo.RegionName,
555 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
449 556
450 m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}", 557 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
451 conn.RegionScene.RegionInfo.RegionName, 558 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
452 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
453 559
454 conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); 560 lock (rootConn.RegionScene.NorthBorders)
455 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); 561 rootConn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
562
563 lock (rootConn.RegionScene.EastBorders)
564 rootConn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
565
566 lock (rootConn.RegionScene.WestBorders)
567 rootConn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
456 568
457 lock (conn.RegionScene.NorthBorders)
458 conn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
459 lock (conn.RegionScene.EastBorders)
460 conn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
461 lock (conn.RegionScene.WestBorders)
462 conn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
463 lock (scene.SouthBorders) 569 lock (scene.SouthBorders)
464 { 570 {
465 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - conn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south 571 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south
466 scene.SouthBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 572 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
467 scene.SouthBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 573 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
468 } 574 }
469 575
470 // Reset Terrain.. since terrain normally loads first. 576 // Reset Terrain.. since terrain normally loads first.
@@ -473,83 +579,92 @@ namespace OpenSim.Region.RegionCombinerModule
473 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised()); 579 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
474 580
475 scene.BordersLocked = false; 581 scene.BordersLocked = false;
476 conn.RegionScene.BordersLocked = false; 582 rootConn.RegionScene.BordersLocked = false;
477 if (conn.ClientEventForwarder != null) 583
478 conn.ClientEventForwarder.AddSceneToEventForwarding(scene); 584 if (rootConn.ClientEventForwarder != null)
585 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
586
479 return true; 587 return true;
480 } 588 }
481 589
482 private bool DoWorkForOneRegionOverPlusXPlusY(RegionConnections conn, RegionConnections regionConnections, Scene scene) 590 private bool DoWorkForOneRegionOverPlusXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
483 { 591 {
484 Vector3 offset = Vector3.Zero; 592 Vector3 offset = Vector3.Zero;
485 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) - 593 offset.X = newConn.PosX - rootConn.PosX;
486 ((conn.X * (int)Constants.RegionSize))); 594 offset.Y = newConn.PosY - rootConn.PosY;
487 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
488 ((conn.Y * (int)Constants.RegionSize)));
489 595
490 Vector3 extents = Vector3.Zero; 596 Vector3 extents = Vector3.Zero;
491 extents.Y = regionConnections.YEnd + conn.YEnd; 597
492 extents.X = regionConnections.XEnd + conn.XEnd; 598 // We do not want to inflate the extents for regions strictly to the NE of the root region, since this
493 conn.UpdateExtents(extents); 599 // would double count regions strictly to the north and east that have already been added.
600// extents.Y = regionConnections.YEnd + conn.YEnd;
601// extents.X = regionConnections.XEnd + conn.XEnd;
602// conn.UpdateExtents(extents);
603
604 extents.Y = rootConn.YEnd;
605 extents.X = rootConn.XEnd;
494 606
495 scene.BordersLocked = true; 607 scene.BordersLocked = true;
496 conn.RegionScene.BordersLocked = true; 608 rootConn.RegionScene.BordersLocked = true;
497 609
498 RegionData ConnectedRegion = new RegionData(); 610 RegionData ConnectedRegion = new RegionData();
499 ConnectedRegion.Offset = offset; 611 ConnectedRegion.Offset = offset;
500 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID; 612 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
501 ConnectedRegion.RegionScene = scene; 613 ConnectedRegion.RegionScene = scene;
502 614
503 conn.ConnectedRegions.Add(ConnectedRegion); 615 rootConn.ConnectedRegions.Add(ConnectedRegion);
616
617 m_log.DebugFormat(
618 "[REGION COMBINER MODULE]: Region {0} is to the southwest of Scene {1}, Offset: {2}, Extents: {3}",
619 rootConn.RegionScene.RegionInfo.RegionName,
620 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
504 621
505 m_log.DebugFormat("Scene: {0} to the NorthEast of Scene{1} Offset: {2}. Extents:{3}", 622 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
506 conn.RegionScene.RegionInfo.RegionName, 623 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
507 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
508 624
509 conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); 625 lock (rootConn.RegionScene.NorthBorders)
510 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero);
511 lock (conn.RegionScene.NorthBorders)
512 { 626 {
513 if (conn.RegionScene.NorthBorders.Count == 1)// && 2) 627 if (rootConn.RegionScene.NorthBorders.Count == 1)// && 2)
514 { 628 {
515 //compound border 629 //compound border
516 // already locked above 630 // already locked above
517 conn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize; 631 rootConn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
518 632
519 lock (conn.RegionScene.EastBorders) 633 lock (rootConn.RegionScene.EastBorders)
520 conn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize; 634 rootConn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
521 lock (conn.RegionScene.WestBorders) 635
522 conn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize; 636 lock (rootConn.RegionScene.WestBorders)
637 rootConn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
523 } 638 }
524 } 639 }
525 640
526 lock (scene.SouthBorders) 641 lock (scene.SouthBorders)
527 { 642 {
528 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - conn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south 643 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south
529 scene.SouthBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 644 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
530 scene.SouthBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 645 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
531 } 646 }
532 647
533 lock (conn.RegionScene.EastBorders) 648 lock (rootConn.RegionScene.EastBorders)
534 { 649 {
535 if (conn.RegionScene.EastBorders.Count == 1)// && conn.RegionScene.EastBorders.Count == 2) 650 if (rootConn.RegionScene.EastBorders.Count == 1)// && conn.RegionScene.EastBorders.Count == 2)
536 { 651 {
537 652
538 conn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize; 653 rootConn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize;
539 lock (conn.RegionScene.NorthBorders)
540 conn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
541 lock (conn.RegionScene.SouthBorders)
542 conn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
543 654
655 lock (rootConn.RegionScene.NorthBorders)
656 rootConn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
544 657
658 lock (rootConn.RegionScene.SouthBorders)
659 rootConn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
545 } 660 }
546 } 661 }
547 662
548 lock (scene.WestBorders) 663 lock (scene.WestBorders)
549 { 664 {
550 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - conn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West 665 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
551 scene.WestBorders[0].TriggerRegionX = conn.RegionScene.RegionInfo.RegionLocX; 666 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
552 scene.WestBorders[0].TriggerRegionY = conn.RegionScene.RegionInfo.RegionLocY; 667 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
553 } 668 }
554 669
555 /* 670 /*
@@ -568,46 +683,50 @@ namespace OpenSim.Region.RegionCombinerModule
568 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); 683 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
569 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised()); 684 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
570 scene.BordersLocked = false; 685 scene.BordersLocked = false;
571 conn.RegionScene.BordersLocked = false; 686 rootConn.RegionScene.BordersLocked = false;
572 687
573 if (conn.ClientEventForwarder != null) 688 if (rootConn.ClientEventForwarder != null)
574 conn.ClientEventForwarder.AddSceneToEventForwarding(scene); 689 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
575 690
576 return true; 691 return true;
577 692
578 //scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents); 693 //scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents);
579
580 } 694 }
581 695
582 private void DoWorkForRootRegion(RegionConnections regionConnections, Scene scene) 696 private void DoWorkForRootRegion(RegionConnections rootConn, Scene scene)
583 { 697 {
698 m_log.DebugFormat("[REGION COMBINER MODULE]: Adding root region {0}", scene.RegionInfo.RegionName);
699
584 RegionData rdata = new RegionData(); 700 RegionData rdata = new RegionData();
585 rdata.Offset = Vector3.Zero; 701 rdata.Offset = Vector3.Zero;
586 rdata.RegionId = scene.RegionInfo.originRegionID; 702 rdata.RegionId = scene.RegionInfo.originRegionID;
587 rdata.RegionScene = scene; 703 rdata.RegionScene = scene;
588 // save it's land channel 704 // save it's land channel
589 regionConnections.RegionLandChannel = scene.LandChannel; 705 rootConn.RegionLandChannel = scene.LandChannel;
590 706
591 // Substitue our landchannel 707 // Substitue our landchannel
592 RegionCombinerLargeLandChannel lnd = new RegionCombinerLargeLandChannel(rdata, scene.LandChannel, 708 RegionCombinerLargeLandChannel lnd = new RegionCombinerLargeLandChannel(rdata, scene.LandChannel,
593 regionConnections.ConnectedRegions); 709 rootConn.ConnectedRegions);
710
594 scene.LandChannel = lnd; 711 scene.LandChannel = lnd;
712
595 // Forward the permissions modules of each of the connected regions to the root region 713 // Forward the permissions modules of each of the connected regions to the root region
596 lock (m_regions) 714 lock (m_regions)
597 { 715 {
598 foreach (RegionData r in regionConnections.ConnectedRegions) 716 foreach (RegionData r in rootConn.ConnectedRegions)
599 { 717 {
600 ForwardPermissionRequests(regionConnections, r.RegionScene); 718 ForwardPermissionRequests(rootConn, r.RegionScene);
601 } 719 }
602 }
603 // Create the root region's Client Event Forwarder
604 regionConnections.ClientEventForwarder = new RegionCombinerClientEventForwarder(regionConnections);
605 720
606 // Sets up the CoarseLocationUpdate forwarder for this root region 721 // Create the root region's Client Event Forwarder
607 scene.EventManager.OnNewPresence += SetCourseLocationDelegate; 722 rootConn.ClientEventForwarder = new RegionCombinerClientEventForwarder(rootConn);
608 723
609 // Adds this root region to a dictionary of regions that are connectable 724 // Sets up the CoarseLocationUpdate forwarder for this root region
610 m_regions.Add(scene.RegionInfo.originRegionID, regionConnections); 725 scene.EventManager.OnNewPresence += SetCourseLocationDelegate;
726
727 // Adds this root region to a dictionary of regions that are connectable
728 m_regions.Add(scene.RegionInfo.originRegionID, rootConn);
729 }
611 } 730 }
612 731
613 private void SetCourseLocationDelegate(ScenePresence presence) 732 private void SetCourseLocationDelegate(ScenePresence presence)
@@ -864,6 +983,7 @@ namespace OpenSim.Region.RegionCombinerModule
864 return true; 983 return true;
865 } 984 }
866 } 985 }
986
867 oborder = null; 987 oborder = null;
868 return false; 988 return false;
869 } 989 }
@@ -873,14 +993,19 @@ namespace OpenSim.Region.RegionCombinerModule
873 pPosition = pPosition/(int) Constants.RegionSize; 993 pPosition = pPosition/(int) Constants.RegionSize;
874 int OffsetX = (int) pPosition.X; 994 int OffsetX = (int) pPosition.X;
875 int OffsetY = (int) pPosition.Y; 995 int OffsetY = (int) pPosition.Y;
876 foreach (RegionConnections regConn in m_regions.Values) 996
997 lock (m_regions)
877 { 998 {
878 foreach (RegionData reg in regConn.ConnectedRegions) 999 foreach (RegionConnections regConn in m_regions.Values)
879 { 1000 {
880 if (reg.Offset.X == OffsetX && reg.Offset.Y == OffsetY) 1001 foreach (RegionData reg in regConn.ConnectedRegions)
881 return reg; 1002 {
1003 if (reg.Offset.X == OffsetX && reg.Offset.Y == OffsetY)
1004 return reg;
1005 }
882 } 1006 }
883 } 1007 }
1008
884 return new RegionData(); 1009 return new RegionData();
885 } 1010 }
886 1011
@@ -936,18 +1061,17 @@ namespace OpenSim.Region.RegionCombinerModule
936 } 1061 }
937 1062
938 #region console commands 1063 #region console commands
1064
939 public void FixPhantoms(string module, string[] cmdparams) 1065 public void FixPhantoms(string module, string[] cmdparams)
940 { 1066 {
941 List<Scene> scenes = new List<Scene>(m_startingScenes.Values); 1067 List<Scene> scenes = new List<Scene>(m_startingScenes.Values);
1068
942 foreach (Scene s in scenes) 1069 foreach (Scene s in scenes)
943 { 1070 {
944 s.ForEachSOG(delegate(SceneObjectGroup e) 1071 s.ForEachSOG(so => so.AbsolutePosition = so.AbsolutePosition);
945 {
946 e.AbsolutePosition = e.AbsolutePosition;
947 }
948 );
949 } 1072 }
950 } 1073 }
1074
951 #endregion 1075 #endregion
952 } 1076 }
953} 1077}