diff options
Diffstat (limited to 'OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs')
-rw-r--r-- | OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs | 134 |
1 files changed, 122 insertions, 12 deletions
diff --git a/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs b/OpenSim/Region/RegionCombinerModule/RegionCombinerModule.cs index d8d9554..fadc30d 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")] |
44 | namespace OpenSim.Region.RegionCombinerModule | 44 | namespace 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 | ||
61 | /// <summary> | ||
62 | /// This holds the root regions for the megaregions. | ||
63 | /// </summary> | ||
64 | /// <remarks> | ||
65 | /// Usually there is only ever one megaregion (and hence only one entry here). | ||
66 | /// </remarks> | ||
62 | private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>(); | 67 | private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>(); |
68 | |||
69 | /// <summary> | ||
70 | /// Is this module enabled? | ||
71 | /// </summary> | ||
63 | private bool enabledYN = false; | 72 | private bool enabledYN = false; |
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,95 @@ 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 sceneId) | ||
117 | { | ||
118 | lock (m_regions) | ||
119 | return m_regions.ContainsKey(sceneId); | ||
120 | } | ||
121 | |||
122 | private void NewPresence(ScenePresence presence) | ||
123 | { | ||
124 | if (presence.IsChildAgent) | ||
125 | { | ||
126 | byte[] throttleData; | ||
127 | |||
128 | try | ||
129 | { | ||
130 | throttleData = presence.ControllingClient.GetThrottlesPacked(1); | ||
131 | } | ||
132 | catch (NotImplementedException) | ||
133 | { | ||
134 | return; | ||
135 | } | ||
136 | |||
137 | if (throttleData == null) | ||
138 | return; | ||
139 | |||
140 | if (throttleData.Length == 0) | ||
141 | return; | ||
142 | |||
143 | if (throttleData.Length != 28) | ||
144 | return; | ||
145 | |||
146 | byte[] adjData; | ||
147 | int pos = 0; | ||
148 | |||
149 | if (!BitConverter.IsLittleEndian) | ||
150 | { | ||
151 | byte[] newData = new byte[7 * 4]; | ||
152 | Buffer.BlockCopy(throttleData, 0, newData, 0, 7 * 4); | ||
153 | |||
154 | for (int i = 0; i < 7; i++) | ||
155 | Array.Reverse(newData, i * 4, 4); | ||
156 | |||
157 | adjData = newData; | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | adjData = throttleData; | ||
162 | } | ||
163 | |||
164 | // 0.125f converts from bits to bytes | ||
165 | int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | ||
166 | int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | ||
167 | int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | ||
168 | int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | ||
169 | int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | ||
170 | int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; | ||
171 | int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); | ||
172 | // State is a subcategory of task that we allocate a percentage to | ||
173 | |||
174 | |||
175 | //int total = resend + land + wind + cloud + task + texture + asset; | ||
176 | |||
177 | byte[] data = new byte[7 * 4]; | ||
178 | int ii = 0; | ||
179 | |||
180 | Buffer.BlockCopy(Utils.FloatToBytes(resend), 0, data, ii, 4); ii += 4; | ||
181 | Buffer.BlockCopy(Utils.FloatToBytes(land * 50), 0, data, ii, 4); ii += 4; | ||
182 | Buffer.BlockCopy(Utils.FloatToBytes(wind), 0, data, ii, 4); ii += 4; | ||
183 | Buffer.BlockCopy(Utils.FloatToBytes(cloud), 0, data, ii, 4); ii += 4; | ||
184 | Buffer.BlockCopy(Utils.FloatToBytes(task), 0, data, ii, 4); ii += 4; | ||
185 | Buffer.BlockCopy(Utils.FloatToBytes(texture), 0, data, ii, 4); ii += 4; | ||
186 | Buffer.BlockCopy(Utils.FloatToBytes(asset), 0, data, ii, 4); | ||
187 | |||
188 | try | ||
189 | { | ||
190 | presence.ControllingClient.SetChildAgentThrottle(data); | ||
191 | } | ||
192 | catch (NotImplementedException) | ||
193 | { | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | } | ||
93 | } | 198 | } |
94 | 199 | ||
95 | private void RegionLoadedDoWork(Scene scene) | 200 | private void RegionLoadedDoWork(Scene scene) |
@@ -348,9 +453,9 @@ namespace OpenSim.Region.RegionCombinerModule | |||
348 | if (!connectedYN) | 453 | if (!connectedYN) |
349 | { | 454 | { |
350 | DoWorkForRootRegion(regionConnections, scene); | 455 | DoWorkForRootRegion(regionConnections, scene); |
351 | |||
352 | } | 456 | } |
353 | } | 457 | } |
458 | |||
354 | // Set up infinite borders around the entire AABB of the combined ConnectedRegions | 459 | // Set up infinite borders around the entire AABB of the combined ConnectedRegions |
355 | AdjustLargeRegionBounds(); | 460 | AdjustLargeRegionBounds(); |
356 | } | 461 | } |
@@ -369,9 +474,10 @@ namespace OpenSim.Region.RegionCombinerModule | |||
369 | 474 | ||
370 | conn.UpdateExtents(extents); | 475 | conn.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]: Scene {0} to the west of Scene {1}, Offset: {2}, Extents: {3}", |
374 | regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); | 479 | conn.RegionScene.RegionInfo.RegionName, |
480 | regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); | ||
375 | 481 | ||
376 | scene.BordersLocked = true; | 482 | scene.BordersLocked = true; |
377 | conn.RegionScene.BordersLocked = true; | 483 | conn.RegionScene.BordersLocked = true; |
@@ -447,9 +553,10 @@ namespace OpenSim.Region.RegionCombinerModule | |||
447 | ConnectedRegion.RegionScene = scene; | 553 | ConnectedRegion.RegionScene = scene; |
448 | conn.ConnectedRegions.Add(ConnectedRegion); | 554 | conn.ConnectedRegions.Add(ConnectedRegion); |
449 | 555 | ||
450 | m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}", | 556 | m_log.DebugFormat( |
451 | conn.RegionScene.RegionInfo.RegionName, | 557 | "[REGION COMBINER MODULE]: Scene: {0} to the northeast of Scene {1}, Offset: {2}, Extents: {3}", |
452 | regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); | 558 | conn.RegionScene.RegionInfo.RegionName, |
559 | regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); | ||
453 | 560 | ||
454 | conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); | 561 | conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); |
455 | scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); | 562 | scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); |
@@ -502,9 +609,10 @@ namespace OpenSim.Region.RegionCombinerModule | |||
502 | 609 | ||
503 | conn.ConnectedRegions.Add(ConnectedRegion); | 610 | conn.ConnectedRegions.Add(ConnectedRegion); |
504 | 611 | ||
505 | m_log.DebugFormat("Scene: {0} to the NorthEast of Scene{1} Offset: {2}. Extents:{3}", | 612 | m_log.DebugFormat( |
506 | conn.RegionScene.RegionInfo.RegionName, | 613 | "[REGION COMBINER MODULE]: Scene: {0} to the NorthEast of Scene {1}, Offset: {2}, Extents: {3}", |
507 | regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); | 614 | conn.RegionScene.RegionInfo.RegionName, |
615 | regionConnections.RegionScene.RegionInfo.RegionName, offset, extents); | ||
508 | 616 | ||
509 | conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); | 617 | conn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents); |
510 | scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); | 618 | scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero); |
@@ -581,6 +689,8 @@ namespace OpenSim.Region.RegionCombinerModule | |||
581 | 689 | ||
582 | private void DoWorkForRootRegion(RegionConnections regionConnections, Scene scene) | 690 | private void DoWorkForRootRegion(RegionConnections regionConnections, Scene scene) |
583 | { | 691 | { |
692 | m_log.DebugFormat("[REGION COMBINER MODULE]: Adding root region {0}", scene.RegionInfo.RegionName); | ||
693 | |||
584 | RegionData rdata = new RegionData(); | 694 | RegionData rdata = new RegionData(); |
585 | rdata.Offset = Vector3.Zero; | 695 | rdata.Offset = Vector3.Zero; |
586 | rdata.RegionId = scene.RegionInfo.originRegionID; | 696 | rdata.RegionId = scene.RegionInfo.originRegionID; |