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.cs1076
1 files changed, 0 insertions, 1076 deletions
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
deleted file mode 100644
index 905540d..0000000
--- a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs
+++ /dev/null
@@ -1,1076 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Client;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Framework.Console;
39using OpenSim.Region.Physics.Manager;
40using Mono.Addins;
41
42namespace OpenSim.Region.RegionCombinerModule
43{
44 public class RegionCombinerModule : ISharedRegionModule, IRegionCombinerModule
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 public string Name
49 {
50 get { return "RegionCombinerModule"; }
51 }
52
53 public Type ReplaceableInterface
54 {
55 get { return null; }
56 }
57
58 /// <summary>
59 /// Is this module enabled?
60 /// </summary>
61 private bool m_combineContiguousRegions = false;
62
63 /// <summary>
64 /// This holds the root regions for the megaregions.
65 /// </summary>
66 /// <remarks>
67 /// Usually there is only ever one megaregion (and hence only one entry here).
68 /// </remarks>
69 private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>();
70
71 /// <summary>
72 /// The scenes that comprise the megaregion.
73 /// </summary>
74 private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>();
75
76 public void Initialise(IConfigSource source)
77 {
78 IConfig myConfig = source.Configs["Startup"];
79 m_combineContiguousRegions = myConfig.GetBoolean("CombineContiguousRegions", false);
80
81 MainConsole.Instance.Commands.AddCommand(
82 "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms",
83 "Fixes phantom objects after an import to a megaregion or a change from a megaregion back to normal regions",
84 FixPhantoms);
85 }
86
87 public void Close()
88 {
89 }
90
91 public void AddRegion(Scene scene)
92 {
93 if (m_combineContiguousRegions)
94 scene.RegisterModuleInterface<IRegionCombinerModule>(this);
95 }
96
97 public void RemoveRegion(Scene scene)
98 {
99 lock (m_startingScenes)
100 m_startingScenes.Remove(scene.RegionInfo.originRegionID);
101 }
102
103 public void RegionLoaded(Scene scene)
104 {
105 lock (m_startingScenes)
106 m_startingScenes.Add(scene.RegionInfo.originRegionID, scene);
107
108 if (m_combineContiguousRegions)
109 {
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 }
213
214 private void RegionLoadedDoWork(Scene scene)
215 {
216/*
217 // For testing on a single instance
218 if (scene.RegionInfo.RegionLocX == 1004 && scene.RegionInfo.RegionLocY == 1000)
219 return;
220 //
221*/
222
223 // Give each region a standard set of non-infinite borders
224 Border northBorder = new Border();
225 northBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<---
226 northBorder.CrossDirection = Cardinals.N;
227 scene.NorthBorders[0] = northBorder;
228
229 Border southBorder = new Border();
230 southBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //--->
231 southBorder.CrossDirection = Cardinals.S;
232 scene.SouthBorders[0] = southBorder;
233
234 Border eastBorder = new Border();
235 eastBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<---
236 eastBorder.CrossDirection = Cardinals.E;
237 scene.EastBorders[0] = eastBorder;
238
239 Border westBorder = new Border();
240 westBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //--->
241 westBorder.CrossDirection = Cardinals.W;
242 scene.WestBorders[0] = westBorder;
243
244 RegionConnections newConn = new RegionConnections();
245 newConn.ConnectedRegions = new List<RegionData>();
246 newConn.RegionScene = scene;
247 newConn.RegionLandChannel = scene.LandChannel;
248 newConn.RegionId = scene.RegionInfo.originRegionID;
249 newConn.X = scene.RegionInfo.RegionLocX;
250 newConn.Y = scene.RegionInfo.RegionLocY;
251 newConn.XEnd = (int)Constants.RegionSize;
252 newConn.YEnd = (int)Constants.RegionSize;
253
254 lock (m_regions)
255 {
256 bool connectedYN = false;
257
258 foreach (RegionConnections rootConn in m_regions.Values)
259 {
260 #region commented
261 /*
262 // If we're one region over +x +y
263 //xxy
264 //xxx
265 //xxx
266 if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd
267 == (regionConnections.X * (int)Constants.RegionSize))
268 && (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
269 == (regionConnections.Y * (int)Constants.RegionSize)))
270 {
271 Vector3 offset = Vector3.Zero;
272 offset.X = (((regionConnections.X * (int) Constants.RegionSize)) -
273 ((conn.X * (int) Constants.RegionSize)));
274 offset.Y = (((regionConnections.Y * (int) Constants.RegionSize)) -
275 ((conn.Y * (int) Constants.RegionSize)));
276
277 Vector3 extents = Vector3.Zero;
278 extents.Y = regionConnections.YEnd + conn.YEnd;
279 extents.X = conn.XEnd + conn.XEnd;
280
281 m_log.DebugFormat("Scene: {0} to the northwest of Scene{1}. Offset: {2}. Extents:{3}",
282 conn.RegionScene.RegionInfo.RegionName,
283 regionConnections.RegionScene.RegionInfo.RegionName,
284 offset, extents);
285
286 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
287
288 connectedYN = true;
289 break;
290 }
291 */
292
293 /*
294 //If we're one region over x +y
295 //xxx
296 //xxx
297 //xyx
298 if ((((int)conn.X * (int)Constants.RegionSize)
299 == (regionConnections.X * (int)Constants.RegionSize))
300 && (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
301 == (regionConnections.Y * (int)Constants.RegionSize)))
302 {
303 Vector3 offset = Vector3.Zero;
304 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
305 ((conn.X * (int)Constants.RegionSize)));
306 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
307 ((conn.Y * (int)Constants.RegionSize)));
308
309 Vector3 extents = Vector3.Zero;
310 extents.Y = regionConnections.YEnd + conn.YEnd;
311 extents.X = conn.XEnd;
312
313 m_log.DebugFormat("Scene: {0} to the north of Scene{1}. Offset: {2}. Extents:{3}",
314 conn.RegionScene.RegionInfo.RegionName,
315 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
316
317 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
318 connectedYN = true;
319 break;
320 }
321 */
322
323 /*
324 // If we're one region over -x +y
325 //xxx
326 //xxx
327 //yxx
328 if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
329 == (regionConnections.X * (int)Constants.RegionSize))
330 && (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
331 == (regionConnections.Y * (int)Constants.RegionSize)))
332 {
333 Vector3 offset = Vector3.Zero;
334 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
335 ((conn.X * (int)Constants.RegionSize)));
336 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
337 ((conn.Y * (int)Constants.RegionSize)));
338
339 Vector3 extents = Vector3.Zero;
340 extents.Y = regionConnections.YEnd + conn.YEnd;
341 extents.X = conn.XEnd + conn.XEnd;
342
343 m_log.DebugFormat("Scene: {0} to the northeast of Scene. Offset: {2}. Extents:{3}",
344 conn.RegionScene.RegionInfo.RegionName,
345 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
346
347 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
348
349
350 connectedYN = true;
351 break;
352 }
353 */
354
355 /*
356 // If we're one region over -x y
357 //xxx
358 //yxx
359 //xxx
360 if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
361 == (regionConnections.X * (int)Constants.RegionSize))
362 && (((int)conn.Y * (int)Constants.RegionSize)
363 == (regionConnections.Y * (int)Constants.RegionSize)))
364 {
365 Vector3 offset = Vector3.Zero;
366 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
367 ((conn.X * (int)Constants.RegionSize)));
368 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
369 ((conn.Y * (int)Constants.RegionSize)));
370
371 Vector3 extents = Vector3.Zero;
372 extents.Y = regionConnections.YEnd;
373 extents.X = conn.XEnd + conn.XEnd;
374
375 m_log.DebugFormat("Scene: {0} to the east of Scene{1} Offset: {2}. Extents:{3}",
376 conn.RegionScene.RegionInfo.RegionName,
377 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
378
379 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
380
381 connectedYN = true;
382 break;
383 }
384 */
385
386 /*
387 // If we're one region over -x -y
388 //yxx
389 //xxx
390 //xxx
391 if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
392 == (regionConnections.X * (int)Constants.RegionSize))
393 && (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
394 == (regionConnections.Y * (int)Constants.RegionSize)))
395 {
396 Vector3 offset = Vector3.Zero;
397 offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
398 ((conn.X * (int)Constants.RegionSize)));
399 offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
400 ((conn.Y * (int)Constants.RegionSize)));
401
402 Vector3 extents = Vector3.Zero;
403 extents.Y = regionConnections.YEnd + conn.YEnd;
404 extents.X = conn.XEnd + conn.XEnd;
405
406 m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}",
407 conn.RegionScene.RegionInfo.RegionName,
408 regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
409
410 scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
411
412 connectedYN = true;
413 break;
414 }
415 */
416 #endregion
417
418 // If we're one region over +x y
419 //xxx
420 //xxy
421 //xxx
422
423 if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY >= newConn.PosY)
424 {
425 connectedYN = DoWorkForOneRegionOverPlusXY(rootConn, newConn, scene);
426 break;
427 }
428
429 // If we're one region over x +y
430 //xyx
431 //xxx
432 //xxx
433 if (rootConn.PosX >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
434 {
435 connectedYN = DoWorkForOneRegionOverXPlusY(rootConn, newConn, scene);
436 break;
437 }
438
439 // If we're one region over +x +y
440 //xxy
441 //xxx
442 //xxx
443 if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
444 {
445 connectedYN = DoWorkForOneRegionOverPlusXPlusY(rootConn, newConn, scene);
446 break;
447
448 }
449 }
450
451 // If !connectYN means that this region is a root region
452 if (!connectedYN)
453 {
454 DoWorkForRootRegion(newConn, scene);
455 }
456 }
457
458 // Set up infinite borders around the entire AABB of the combined ConnectedRegions
459 AdjustLargeRegionBounds();
460 }
461
462 private bool DoWorkForOneRegionOverPlusXY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
463 {
464 Vector3 offset = Vector3.Zero;
465 offset.X = newConn.PosX - rootConn.PosX;
466 offset.Y = newConn.PosY - rootConn.PosY;
467
468 Vector3 extents = Vector3.Zero;
469 extents.Y = rootConn.YEnd;
470 extents.X = rootConn.XEnd + newConn.XEnd;
471
472 rootConn.UpdateExtents(extents);
473
474 m_log.DebugFormat(
475 "[REGION COMBINER MODULE]: Root region {0} is to the west of region {1}, Offset: {2}, Extents: {3}",
476 rootConn.RegionScene.RegionInfo.RegionName,
477 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
478
479 scene.BordersLocked = true;
480 rootConn.RegionScene.BordersLocked = true;
481
482 RegionData ConnectedRegion = new RegionData();
483 ConnectedRegion.Offset = offset;
484 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
485 ConnectedRegion.RegionScene = scene;
486 rootConn.ConnectedRegions.Add(ConnectedRegion);
487
488 // Inform root region Physics about the extents of this region
489 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
490
491 // Inform Child region that it needs to forward it's terrain to the root region
492 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
493
494 // Extend the borders as appropriate
495 lock (rootConn.RegionScene.EastBorders)
496 rootConn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize;
497
498 lock (rootConn.RegionScene.NorthBorders)
499 rootConn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
500
501 lock (rootConn.RegionScene.SouthBorders)
502 rootConn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
503
504 lock (scene.WestBorders)
505 {
506 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
507
508 // Trigger auto teleport to root region
509 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
510 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
511 }
512
513 // Reset Terrain.. since terrain loads before we get here, we need to load
514 // it again so it loads in the root region
515
516 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
517
518 // Unlock borders
519 rootConn.RegionScene.BordersLocked = false;
520 scene.BordersLocked = false;
521
522 // Create a client event forwarder and add this region's events to the root region.
523 if (rootConn.ClientEventForwarder != null)
524 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
525
526 return true;
527 }
528
529 private bool DoWorkForOneRegionOverXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
530 {
531 Vector3 offset = Vector3.Zero;
532 offset.X = newConn.PosX - rootConn.PosX;
533 offset.Y = newConn.PosY - rootConn.PosY;
534
535 Vector3 extents = Vector3.Zero;
536 extents.Y = newConn.YEnd + rootConn.YEnd;
537 extents.X = rootConn.XEnd;
538 rootConn.UpdateExtents(extents);
539
540 scene.BordersLocked = true;
541 rootConn.RegionScene.BordersLocked = true;
542
543 RegionData ConnectedRegion = new RegionData();
544 ConnectedRegion.Offset = offset;
545 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
546 ConnectedRegion.RegionScene = scene;
547 rootConn.ConnectedRegions.Add(ConnectedRegion);
548
549 m_log.DebugFormat(
550 "[REGION COMBINER MODULE]: Root region {0} is to the south of region {1}, Offset: {2}, Extents: {3}",
551 rootConn.RegionScene.RegionInfo.RegionName,
552 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
553
554 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
555 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
556
557 lock (rootConn.RegionScene.NorthBorders)
558 rootConn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
559
560 lock (rootConn.RegionScene.EastBorders)
561 rootConn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
562
563 lock (rootConn.RegionScene.WestBorders)
564 rootConn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
565
566 lock (scene.SouthBorders)
567 {
568 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south
569 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
570 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
571 }
572
573 // Reset Terrain.. since terrain normally loads first.
574 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
575 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
576 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
577
578 scene.BordersLocked = false;
579 rootConn.RegionScene.BordersLocked = false;
580
581 if (rootConn.ClientEventForwarder != null)
582 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
583
584 return true;
585 }
586
587 private bool DoWorkForOneRegionOverPlusXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
588 {
589 Vector3 offset = Vector3.Zero;
590 offset.X = newConn.PosX - rootConn.PosX;
591 offset.Y = newConn.PosY - rootConn.PosY;
592
593 Vector3 extents = Vector3.Zero;
594
595 // We do not want to inflate the extents for regions strictly to the NE of the root region, since this
596 // would double count regions strictly to the north and east that have already been added.
597// extents.Y = regionConnections.YEnd + conn.YEnd;
598// extents.X = regionConnections.XEnd + conn.XEnd;
599// conn.UpdateExtents(extents);
600
601 extents.Y = rootConn.YEnd;
602 extents.X = rootConn.XEnd;
603
604 scene.BordersLocked = true;
605 rootConn.RegionScene.BordersLocked = true;
606
607 RegionData ConnectedRegion = new RegionData();
608 ConnectedRegion.Offset = offset;
609 ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
610 ConnectedRegion.RegionScene = scene;
611
612 rootConn.ConnectedRegions.Add(ConnectedRegion);
613
614 m_log.DebugFormat(
615 "[REGION COMBINER MODULE]: Region {0} is to the southwest of Scene {1}, Offset: {2}, Extents: {3}",
616 rootConn.RegionScene.RegionInfo.RegionName,
617 newConn.RegionScene.RegionInfo.RegionName, offset, extents);
618
619 rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
620 scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
621
622 lock (rootConn.RegionScene.NorthBorders)
623 {
624 if (rootConn.RegionScene.NorthBorders.Count == 1)// && 2)
625 {
626 //compound border
627 // already locked above
628 rootConn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
629
630 lock (rootConn.RegionScene.EastBorders)
631 rootConn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
632
633 lock (rootConn.RegionScene.WestBorders)
634 rootConn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
635 }
636 }
637
638 lock (scene.SouthBorders)
639 {
640 scene.SouthBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocY - rootConn.RegionScene.RegionInfo.RegionLocY) * (int)Constants.RegionSize); //auto teleport south
641 scene.SouthBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
642 scene.SouthBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
643 }
644
645 lock (rootConn.RegionScene.EastBorders)
646 {
647 if (rootConn.RegionScene.EastBorders.Count == 1)// && conn.RegionScene.EastBorders.Count == 2)
648 {
649
650 rootConn.RegionScene.EastBorders[0].BorderLine.Z += (int)Constants.RegionSize;
651
652 lock (rootConn.RegionScene.NorthBorders)
653 rootConn.RegionScene.NorthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
654
655 lock (rootConn.RegionScene.SouthBorders)
656 rootConn.RegionScene.SouthBorders[0].BorderLine.Y += (int)Constants.RegionSize;
657 }
658 }
659
660 lock (scene.WestBorders)
661 {
662 scene.WestBorders[0].BorderLine.Z = (int)((scene.RegionInfo.RegionLocX - rootConn.RegionScene.RegionInfo.RegionLocX) * (int)Constants.RegionSize); //auto teleport West
663 scene.WestBorders[0].TriggerRegionX = rootConn.RegionScene.RegionInfo.RegionLocX;
664 scene.WestBorders[0].TriggerRegionY = rootConn.RegionScene.RegionInfo.RegionLocY;
665 }
666
667 /*
668 else
669 {
670 conn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
671 conn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
672 conn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
673 scene.SouthBorders[0].BorderLine.Z += (int)Constants.RegionSize; //auto teleport south
674 }
675 */
676
677
678 // Reset Terrain.. since terrain normally loads first.
679 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
680 scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
681 //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
682 scene.BordersLocked = false;
683 rootConn.RegionScene.BordersLocked = false;
684
685 if (rootConn.ClientEventForwarder != null)
686 rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
687
688 return true;
689
690 //scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents);
691 }
692
693 private void DoWorkForRootRegion(RegionConnections rootConn, Scene scene)
694 {
695 m_log.DebugFormat("[REGION COMBINER MODULE]: Adding root region {0}", scene.RegionInfo.RegionName);
696
697 RegionData rdata = new RegionData();
698 rdata.Offset = Vector3.Zero;
699 rdata.RegionId = scene.RegionInfo.originRegionID;
700 rdata.RegionScene = scene;
701 // save it's land channel
702 rootConn.RegionLandChannel = scene.LandChannel;
703
704 // Substitue our landchannel
705 RegionCombinerLargeLandChannel lnd = new RegionCombinerLargeLandChannel(rdata, scene.LandChannel,
706 rootConn.ConnectedRegions);
707
708 scene.LandChannel = lnd;
709
710 // Forward the permissions modules of each of the connected regions to the root region
711 lock (m_regions)
712 {
713 foreach (RegionData r in rootConn.ConnectedRegions)
714 {
715 ForwardPermissionRequests(rootConn, r.RegionScene);
716 }
717
718 // Create the root region's Client Event Forwarder
719 rootConn.ClientEventForwarder = new RegionCombinerClientEventForwarder(rootConn);
720
721 // Sets up the CoarseLocationUpdate forwarder for this root region
722 scene.EventManager.OnNewPresence += SetCoarseLocationDelegate;
723
724 // Adds this root region to a dictionary of regions that are connectable
725 m_regions.Add(scene.RegionInfo.originRegionID, rootConn);
726 }
727 }
728
729 private void SetCoarseLocationDelegate(ScenePresence presence)
730 {
731 presence.SetSendCoarseLocationMethod(SendCoarseLocationUpdates);
732 }
733
734 // This delegate was refactored for non-combined regions.
735 // This combined region version will not use the pre-compiled lists of locations and ids
736 private void SendCoarseLocationUpdates(UUID sceneId, ScenePresence presence, List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
737 {
738 RegionConnections connectiondata = null;
739 lock (m_regions)
740 {
741 if (m_regions.ContainsKey(sceneId))
742 connectiondata = m_regions[sceneId];
743 else
744 return;
745 }
746
747 List<Vector3> CoarseLocations = new List<Vector3>();
748 List<UUID> AvatarUUIDs = new List<UUID>();
749
750 connectiondata.RegionScene.ForEachRootScenePresence(delegate(ScenePresence sp)
751 {
752 if (sp.UUID != presence.UUID)
753 {
754 CoarseLocations.Add(sp.AbsolutePosition);
755 AvatarUUIDs.Add(sp.UUID);
756 }
757 });
758
759 DistributeCoarseLocationUpdates(CoarseLocations, AvatarUUIDs, connectiondata, presence);
760 }
761
762 private void DistributeCoarseLocationUpdates(List<Vector3> locations, List<UUID> uuids,
763 RegionConnections connectiondata, ScenePresence rootPresence)
764 {
765 RegionData[] rdata = connectiondata.ConnectedRegions.ToArray();
766 //List<IClientAPI> clients = new List<IClientAPI>();
767 Dictionary<Vector2, RegionCoarseLocationStruct> updates = new Dictionary<Vector2, RegionCoarseLocationStruct>();
768
769 // Root Region entry
770 RegionCoarseLocationStruct rootupdatedata = new RegionCoarseLocationStruct();
771 rootupdatedata.Locations = new List<Vector3>();
772 rootupdatedata.Uuids = new List<UUID>();
773 rootupdatedata.Offset = Vector2.Zero;
774
775 rootupdatedata.UserAPI = rootPresence.ControllingClient;
776
777 if (rootupdatedata.UserAPI != null)
778 updates.Add(Vector2.Zero, rootupdatedata);
779
780 //Each Region needs an entry or we will end up with dead minimap dots
781 foreach (RegionData regiondata in rdata)
782 {
783 Vector2 offset = new Vector2(regiondata.Offset.X, regiondata.Offset.Y);
784 RegionCoarseLocationStruct updatedata = new RegionCoarseLocationStruct();
785 updatedata.Locations = new List<Vector3>();
786 updatedata.Uuids = new List<UUID>();
787 updatedata.Offset = offset;
788
789 if (offset == Vector2.Zero)
790 updatedata.UserAPI = rootPresence.ControllingClient;
791 else
792 updatedata.UserAPI = LocateUsersChildAgentIClientAPI(offset, rootPresence.UUID, rdata);
793
794 if (updatedata.UserAPI != null)
795 updates.Add(offset, updatedata);
796 }
797
798 // go over the locations and assign them to an IClientAPI
799 for (int i = 0; i < locations.Count; i++)
800 //{locations[i]/(int) Constants.RegionSize;
801 {
802 Vector3 pPosition = new Vector3((int)locations[i].X / (int)Constants.RegionSize,
803 (int)locations[i].Y / (int)Constants.RegionSize, locations[i].Z);
804 Vector2 offset = new Vector2(pPosition.X*(int) Constants.RegionSize,
805 pPosition.Y*(int) Constants.RegionSize);
806
807 if (!updates.ContainsKey(offset))
808 {
809 // This shouldn't happen
810 RegionCoarseLocationStruct updatedata = new RegionCoarseLocationStruct();
811 updatedata.Locations = new List<Vector3>();
812 updatedata.Uuids = new List<UUID>();
813 updatedata.Offset = offset;
814
815 if (offset == Vector2.Zero)
816 updatedata.UserAPI = rootPresence.ControllingClient;
817 else
818 updatedata.UserAPI = LocateUsersChildAgentIClientAPI(offset, rootPresence.UUID, rdata);
819
820 updates.Add(offset,updatedata);
821 }
822
823 updates[offset].Locations.Add(locations[i]);
824 updates[offset].Uuids.Add(uuids[i]);
825 }
826
827 // Send out the CoarseLocationupdates from their respective client connection based on where the avatar is
828 foreach (Vector2 offset in updates.Keys)
829 {
830 if (updates[offset].UserAPI != null)
831 {
832 updates[offset].UserAPI.SendCoarseLocationUpdate(updates[offset].Uuids,updates[offset].Locations);
833 }
834 }
835 }
836
837 /// <summary>
838 /// Locates a the Client of a particular region in an Array of RegionData based on offset
839 /// </summary>
840 /// <param name="offset"></param>
841 /// <param name="uUID"></param>
842 /// <param name="rdata"></param>
843 /// <returns>IClientAPI or null</returns>
844 private IClientAPI LocateUsersChildAgentIClientAPI(Vector2 offset, UUID uUID, RegionData[] rdata)
845 {
846 IClientAPI returnclient = null;
847 foreach (RegionData r in rdata)
848 {
849 if (r.Offset.X == offset.X && r.Offset.Y == offset.Y)
850 {
851 return r.RegionScene.SceneGraph.GetControllingClient(uUID);
852 }
853 }
854
855 return returnclient;
856 }
857
858 public void PostInitialise()
859 {
860 }
861
862// /// <summary>
863// /// TODO:
864// /// </summary>
865// /// <param name="rdata"></param>
866// public void UnCombineRegion(RegionData rdata)
867// {
868// lock (m_regions)
869// {
870// if (m_regions.ContainsKey(rdata.RegionId))
871// {
872// // uncombine root region and virtual regions
873// }
874// else
875// {
876// foreach (RegionConnections r in m_regions.Values)
877// {
878// foreach (RegionData rd in r.ConnectedRegions)
879// {
880// if (rd.RegionId == rdata.RegionId)
881// {
882// // uncombine virtual region
883// }
884// }
885// }
886// }
887// }
888// }
889
890 // Create a set of infinite borders around the whole aabb of the combined island.
891 private void AdjustLargeRegionBounds()
892 {
893 lock (m_regions)
894 {
895 foreach (RegionConnections rconn in m_regions.Values)
896 {
897 Vector3 offset = Vector3.Zero;
898 rconn.RegionScene.BordersLocked = true;
899 foreach (RegionData rdata in rconn.ConnectedRegions)
900 {
901 if (rdata.Offset.X > offset.X) offset.X = rdata.Offset.X;
902 if (rdata.Offset.Y > offset.Y) offset.Y = rdata.Offset.Y;
903 }
904
905 lock (rconn.RegionScene.NorthBorders)
906 {
907 Border northBorder = null;
908 // If we don't already have an infinite border, create one.
909 if (!TryGetInfiniteBorder(rconn.RegionScene.NorthBorders, out northBorder))
910 {
911 northBorder = new Border();
912 rconn.RegionScene.NorthBorders.Add(northBorder);
913 }
914
915 northBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue,
916 offset.Y + (int) Constants.RegionSize); //<---
917 northBorder.CrossDirection = Cardinals.N;
918 }
919
920 lock (rconn.RegionScene.SouthBorders)
921 {
922 Border southBorder = null;
923 // If we don't already have an infinite border, create one.
924 if (!TryGetInfiniteBorder(rconn.RegionScene.SouthBorders, out southBorder))
925 {
926 southBorder = new Border();
927 rconn.RegionScene.SouthBorders.Add(southBorder);
928 }
929 southBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, 0); //--->
930 southBorder.CrossDirection = Cardinals.S;
931 }
932
933 lock (rconn.RegionScene.EastBorders)
934 {
935 Border eastBorder = null;
936 // If we don't already have an infinite border, create one.
937 if (!TryGetInfiniteBorder(rconn.RegionScene.EastBorders, out eastBorder))
938 {
939 eastBorder = new Border();
940 rconn.RegionScene.EastBorders.Add(eastBorder);
941 }
942 eastBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, offset.X + (int)Constants.RegionSize);
943 //<---
944 eastBorder.CrossDirection = Cardinals.E;
945 }
946
947 lock (rconn.RegionScene.WestBorders)
948 {
949 Border westBorder = null;
950 // If we don't already have an infinite border, create one.
951 if (!TryGetInfiniteBorder(rconn.RegionScene.WestBorders, out westBorder))
952 {
953 westBorder = new Border();
954 rconn.RegionScene.WestBorders.Add(westBorder);
955
956 }
957 westBorder.BorderLine = new Vector3(float.MinValue, float.MaxValue, 0); //--->
958 westBorder.CrossDirection = Cardinals.W;
959 }
960
961 rconn.RegionScene.BordersLocked = false;
962 }
963 }
964 }
965
966 /// <summary>
967 /// Try and get an Infinite border out of a listT of borders
968 /// </summary>
969 /// <param name="borders"></param>
970 /// <param name="oborder"></param>
971 /// <returns></returns>
972 public static bool TryGetInfiniteBorder(List<Border> borders, out Border oborder)
973 {
974 // Warning! Should be locked before getting here!
975 foreach (Border b in borders)
976 {
977 if (b.BorderLine.X == float.MinValue && b.BorderLine.Y == float.MaxValue)
978 {
979 oborder = b;
980 return true;
981 }
982 }
983
984 oborder = null;
985 return false;
986 }
987
988 public RegionData GetRegionFromPosition(Vector3 pPosition)
989 {
990 pPosition = pPosition/(int) Constants.RegionSize;
991 int OffsetX = (int) pPosition.X;
992 int OffsetY = (int) pPosition.Y;
993
994 lock (m_regions)
995 {
996 foreach (RegionConnections regConn in m_regions.Values)
997 {
998 foreach (RegionData reg in regConn.ConnectedRegions)
999 {
1000 if (reg.Offset.X == OffsetX && reg.Offset.Y == OffsetY)
1001 return reg;
1002 }
1003 }
1004 }
1005
1006 return new RegionData();
1007 }
1008
1009 public void ForwardPermissionRequests(RegionConnections BigRegion, Scene VirtualRegion)
1010 {
1011 if (BigRegion.PermissionModule == null)
1012 BigRegion.PermissionModule = new RegionCombinerPermissionModule(BigRegion.RegionScene);
1013
1014 VirtualRegion.Permissions.OnBypassPermissions += BigRegion.PermissionModule.BypassPermissions;
1015 VirtualRegion.Permissions.OnSetBypassPermissions += BigRegion.PermissionModule.SetBypassPermissions;
1016 VirtualRegion.Permissions.OnPropagatePermissions += BigRegion.PermissionModule.PropagatePermissions;
1017 VirtualRegion.Permissions.OnGenerateClientFlags += BigRegion.PermissionModule.GenerateClientFlags;
1018 VirtualRegion.Permissions.OnAbandonParcel += BigRegion.PermissionModule.CanAbandonParcel;
1019 VirtualRegion.Permissions.OnReclaimParcel += BigRegion.PermissionModule.CanReclaimParcel;
1020 VirtualRegion.Permissions.OnDeedParcel += BigRegion.PermissionModule.CanDeedParcel;
1021 VirtualRegion.Permissions.OnDeedObject += BigRegion.PermissionModule.CanDeedObject;
1022 VirtualRegion.Permissions.OnIsGod += BigRegion.PermissionModule.IsGod;
1023 VirtualRegion.Permissions.OnDuplicateObject += BigRegion.PermissionModule.CanDuplicateObject;
1024 VirtualRegion.Permissions.OnDeleteObject += BigRegion.PermissionModule.CanDeleteObject; //MAYBE FULLY IMPLEMENTED
1025 VirtualRegion.Permissions.OnEditObject += BigRegion.PermissionModule.CanEditObject; //MAYBE FULLY IMPLEMENTED
1026 VirtualRegion.Permissions.OnEditParcelProperties += BigRegion.PermissionModule.CanEditParcelProperties; //MAYBE FULLY IMPLEMENTED
1027 VirtualRegion.Permissions.OnInstantMessage += BigRegion.PermissionModule.CanInstantMessage;
1028 VirtualRegion.Permissions.OnInventoryTransfer += BigRegion.PermissionModule.CanInventoryTransfer; //NOT YET IMPLEMENTED
1029 VirtualRegion.Permissions.OnIssueEstateCommand += BigRegion.PermissionModule.CanIssueEstateCommand; //FULLY IMPLEMENTED
1030 VirtualRegion.Permissions.OnMoveObject += BigRegion.PermissionModule.CanMoveObject; //MAYBE FULLY IMPLEMENTED
1031 VirtualRegion.Permissions.OnObjectEntry += BigRegion.PermissionModule.CanObjectEntry;
1032 VirtualRegion.Permissions.OnReturnObjects += BigRegion.PermissionModule.CanReturnObjects; //NOT YET IMPLEMENTED
1033 VirtualRegion.Permissions.OnRezObject += BigRegion.PermissionModule.CanRezObject; //MAYBE FULLY IMPLEMENTED
1034 VirtualRegion.Permissions.OnRunConsoleCommand += BigRegion.PermissionModule.CanRunConsoleCommand;
1035 VirtualRegion.Permissions.OnRunScript += BigRegion.PermissionModule.CanRunScript; //NOT YET IMPLEMENTED
1036 VirtualRegion.Permissions.OnCompileScript += BigRegion.PermissionModule.CanCompileScript;
1037 VirtualRegion.Permissions.OnSellParcel += BigRegion.PermissionModule.CanSellParcel;
1038 VirtualRegion.Permissions.OnTakeObject += BigRegion.PermissionModule.CanTakeObject;
1039 VirtualRegion.Permissions.OnTakeCopyObject += BigRegion.PermissionModule.CanTakeCopyObject;
1040 VirtualRegion.Permissions.OnTerraformLand += BigRegion.PermissionModule.CanTerraformLand;
1041 VirtualRegion.Permissions.OnLinkObject += BigRegion.PermissionModule.CanLinkObject; //NOT YET IMPLEMENTED
1042 VirtualRegion.Permissions.OnDelinkObject += BigRegion.PermissionModule.CanDelinkObject; //NOT YET IMPLEMENTED
1043 VirtualRegion.Permissions.OnBuyLand += BigRegion.PermissionModule.CanBuyLand; //NOT YET IMPLEMENTED
1044 VirtualRegion.Permissions.OnViewNotecard += BigRegion.PermissionModule.CanViewNotecard; //NOT YET IMPLEMENTED
1045 VirtualRegion.Permissions.OnViewScript += BigRegion.PermissionModule.CanViewScript; //NOT YET IMPLEMENTED
1046 VirtualRegion.Permissions.OnEditNotecard += BigRegion.PermissionModule.CanEditNotecard; //NOT YET IMPLEMENTED
1047 VirtualRegion.Permissions.OnEditScript += BigRegion.PermissionModule.CanEditScript; //NOT YET IMPLEMENTED
1048 VirtualRegion.Permissions.OnCreateObjectInventory += BigRegion.PermissionModule.CanCreateObjectInventory; //NOT IMPLEMENTED HERE
1049 VirtualRegion.Permissions.OnEditObjectInventory += BigRegion.PermissionModule.CanEditObjectInventory;//MAYBE FULLY IMPLEMENTED
1050 VirtualRegion.Permissions.OnCopyObjectInventory += BigRegion.PermissionModule.CanCopyObjectInventory; //NOT YET IMPLEMENTED
1051 VirtualRegion.Permissions.OnDeleteObjectInventory += BigRegion.PermissionModule.CanDeleteObjectInventory; //NOT YET IMPLEMENTED
1052 VirtualRegion.Permissions.OnResetScript += BigRegion.PermissionModule.CanResetScript;
1053 VirtualRegion.Permissions.OnCreateUserInventory += BigRegion.PermissionModule.CanCreateUserInventory; //NOT YET IMPLEMENTED
1054 VirtualRegion.Permissions.OnCopyUserInventory += BigRegion.PermissionModule.CanCopyUserInventory; //NOT YET IMPLEMENTED
1055 VirtualRegion.Permissions.OnEditUserInventory += BigRegion.PermissionModule.CanEditUserInventory; //NOT YET IMPLEMENTED
1056 VirtualRegion.Permissions.OnDeleteUserInventory += BigRegion.PermissionModule.CanDeleteUserInventory; //NOT YET IMPLEMENTED
1057 VirtualRegion.Permissions.OnTeleport += BigRegion.PermissionModule.CanTeleport; //NOT YET IMPLEMENTED
1058 }
1059
1060 #region console commands
1061
1062 public void FixPhantoms(string module, string[] cmdparams)
1063 {
1064 List<Scene> scenes = new List<Scene>(m_startingScenes.Values);
1065
1066 foreach (Scene s in scenes)
1067 {
1068 MainConsole.Instance.OutputFormat("Fixing phantoms for {0}", s.RegionInfo.RegionName);
1069
1070 s.ForEachSOG(so => so.AbsolutePosition = so.AbsolutePosition);
1071 }
1072 }
1073
1074 #endregion
1075 }
1076}