RegionCombinerModule.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Client;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Region.Physics.Manager;
  39. using Mono.Addins;
  40. namespace OpenSim.Region.RegionCombinerModule
  41. {
  42. public class RegionCombinerModule : ISharedRegionModule, IRegionCombinerModule
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private static string LogHeader = "[REGION COMBINER MODULE]";
  46. public string Name
  47. {
  48. get { return "RegionCombinerModule"; }
  49. }
  50. public Type ReplaceableInterface
  51. {
  52. get { return null; }
  53. }
  54. /// <summary>
  55. /// Is this module enabled?
  56. /// </summary>
  57. private bool m_combineContiguousRegions = false;
  58. /// <summary>
  59. /// This holds the root regions for the megaregions.
  60. /// </summary>
  61. /// <remarks>
  62. /// Usually there is only ever one megaregion (and hence only one entry here).
  63. /// </remarks>
  64. private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>();
  65. /// <summary>
  66. /// The scenes that comprise the megaregion.
  67. /// </summary>
  68. private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>();
  69. public void Initialise(IConfigSource source)
  70. {
  71. IConfig myConfig = source.Configs["Startup"];
  72. m_combineContiguousRegions = myConfig.GetBoolean("CombineContiguousRegions", false);
  73. MainConsole.Instance.Commands.AddCommand(
  74. "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms",
  75. "Fixes phantom objects after an import to a megaregion or a change from a megaregion back to normal regions",
  76. FixPhantoms);
  77. }
  78. public void Close()
  79. {
  80. }
  81. public void AddRegion(Scene scene)
  82. {
  83. if (m_combineContiguousRegions)
  84. scene.RegisterModuleInterface<IRegionCombinerModule>(this);
  85. }
  86. public void RemoveRegion(Scene scene)
  87. {
  88. lock (m_startingScenes)
  89. m_startingScenes.Remove(scene.RegionInfo.originRegionID);
  90. }
  91. public void RegionLoaded(Scene scene)
  92. {
  93. lock (m_startingScenes)
  94. m_startingScenes.Add(scene.RegionInfo.originRegionID, scene);
  95. if (m_combineContiguousRegions)
  96. {
  97. RegionLoadedDoWork(scene);
  98. scene.EventManager.OnNewPresence += NewPresence;
  99. }
  100. }
  101. public bool IsRootForMegaregion(UUID regionId)
  102. {
  103. lock (m_regions)
  104. return m_regions.ContainsKey(regionId);
  105. }
  106. public Vector2 GetSizeOfMegaregion(UUID regionId)
  107. {
  108. lock (m_regions)
  109. {
  110. if (m_regions.ContainsKey(regionId))
  111. {
  112. RegionConnections rootConn = m_regions[regionId];
  113. return new Vector2((float)rootConn.XEnd, (float)rootConn.YEnd);
  114. }
  115. }
  116. throw new Exception(string.Format("Region with id {0} not found", regionId));
  117. }
  118. // Test to see if this postiion (relative to the region) is within the area covered
  119. // by this megaregion.
  120. public bool PositionIsInMegaregion(UUID currentRegion, int xx, int yy)
  121. {
  122. bool ret = false;
  123. if (xx < 0 || yy < 0)
  124. return ret;
  125. foreach (RegionConnections rootRegion in m_regions.Values)
  126. {
  127. if (currentRegion == rootRegion.RegionId)
  128. {
  129. // The caller is in the root region so this is an easy test
  130. if (xx < rootRegion.XEnd && yy < rootRegion.YEnd)
  131. {
  132. ret = true;
  133. }
  134. break;
  135. }
  136. else
  137. {
  138. // Maybe the caller is in one of the sub-regions
  139. foreach (RegionData childRegion in rootRegion.ConnectedRegions)
  140. {
  141. if (currentRegion == childRegion.RegionId)
  142. {
  143. // This is a child. Diddle the offsets and check if in
  144. Vector3 positionInMegaregion = childRegion.Offset;
  145. positionInMegaregion.X += xx;
  146. positionInMegaregion.Y += yy;
  147. if (positionInMegaregion.X < rootRegion.XEnd && positionInMegaregion.Y < rootRegion.YEnd)
  148. {
  149. ret = true;
  150. }
  151. break;
  152. }
  153. }
  154. }
  155. }
  156. return ret;
  157. }
  158. private void NewPresence(ScenePresence presence)
  159. {
  160. if (presence.IsChildAgent)
  161. {
  162. byte[] throttleData;
  163. try
  164. {
  165. throttleData = presence.ControllingClient.GetThrottlesPacked(1);
  166. }
  167. catch (NotImplementedException)
  168. {
  169. return;
  170. }
  171. if (throttleData == null)
  172. return;
  173. if (throttleData.Length == 0)
  174. return;
  175. if (throttleData.Length != 28)
  176. return;
  177. byte[] adjData;
  178. int pos = 0;
  179. if (!BitConverter.IsLittleEndian)
  180. {
  181. byte[] newData = new byte[7 * 4];
  182. Buffer.BlockCopy(throttleData, 0, newData, 0, 7 * 4);
  183. for (int i = 0; i < 7; i++)
  184. Array.Reverse(newData, i * 4, 4);
  185. adjData = newData;
  186. }
  187. else
  188. {
  189. adjData = throttleData;
  190. }
  191. // 0.125f converts from bits to bytes
  192. int resend = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
  193. int land = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
  194. int wind = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
  195. int cloud = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
  196. int task = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
  197. int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
  198. int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
  199. // State is a subcategory of task that we allocate a percentage to
  200. //int total = resend + land + wind + cloud + task + texture + asset;
  201. byte[] data = new byte[7 * 4];
  202. int ii = 0;
  203. Buffer.BlockCopy(Utils.FloatToBytes(resend), 0, data, ii, 4); ii += 4;
  204. Buffer.BlockCopy(Utils.FloatToBytes(land * 50), 0, data, ii, 4); ii += 4;
  205. Buffer.BlockCopy(Utils.FloatToBytes(wind), 0, data, ii, 4); ii += 4;
  206. Buffer.BlockCopy(Utils.FloatToBytes(cloud), 0, data, ii, 4); ii += 4;
  207. Buffer.BlockCopy(Utils.FloatToBytes(task), 0, data, ii, 4); ii += 4;
  208. Buffer.BlockCopy(Utils.FloatToBytes(texture), 0, data, ii, 4); ii += 4;
  209. Buffer.BlockCopy(Utils.FloatToBytes(asset), 0, data, ii, 4);
  210. try
  211. {
  212. presence.ControllingClient.SetChildAgentThrottle(data);
  213. }
  214. catch (NotImplementedException)
  215. {
  216. return;
  217. }
  218. }
  219. }
  220. private void RegionLoadedDoWork(Scene scene)
  221. {
  222. /*
  223. // For testing on a single instance
  224. if (scene.RegionInfo.RegionLocX == 1004 && scene.RegionInfo.RegionLocY == 1000)
  225. return;
  226. //
  227. */
  228. RegionConnections newConn = new RegionConnections();
  229. newConn.ConnectedRegions = new List<RegionData>();
  230. newConn.RegionScene = scene;
  231. newConn.RegionLandChannel = scene.LandChannel;
  232. newConn.RegionId = scene.RegionInfo.originRegionID;
  233. newConn.X = scene.RegionInfo.RegionLocX;
  234. newConn.Y = scene.RegionInfo.RegionLocY;
  235. newConn.XEnd = scene.RegionInfo.RegionSizeX;
  236. newConn.YEnd = scene.RegionInfo.RegionSizeX;
  237. lock (m_regions)
  238. {
  239. bool connectedYN = false;
  240. foreach (RegionConnections rootConn in m_regions.Values)
  241. {
  242. #region commented
  243. /*
  244. // If we're one region over +x +y
  245. //xxy
  246. //xxx
  247. //xxx
  248. if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd
  249. == (regionConnections.X * (int)Constants.RegionSize))
  250. && (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
  251. == (regionConnections.Y * (int)Constants.RegionSize)))
  252. {
  253. Vector3 offset = Vector3.Zero;
  254. offset.X = (((regionConnections.X * (int) Constants.RegionSize)) -
  255. ((conn.X * (int) Constants.RegionSize)));
  256. offset.Y = (((regionConnections.Y * (int) Constants.RegionSize)) -
  257. ((conn.Y * (int) Constants.RegionSize)));
  258. Vector3 extents = Vector3.Zero;
  259. extents.Y = regionConnections.YEnd + conn.YEnd;
  260. extents.X = conn.XEnd + conn.XEnd;
  261. m_log.DebugFormat("Scene: {0} to the northwest of Scene{1}. Offset: {2}. Extents:{3}",
  262. conn.RegionScene.RegionInfo.RegionName,
  263. regionConnections.RegionScene.RegionInfo.RegionName,
  264. offset, extents);
  265. scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
  266. connectedYN = true;
  267. break;
  268. }
  269. */
  270. /*
  271. //If we're one region over x +y
  272. //xxx
  273. //xxx
  274. //xyx
  275. if ((((int)conn.X * (int)Constants.RegionSize)
  276. == (regionConnections.X * (int)Constants.RegionSize))
  277. && (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
  278. == (regionConnections.Y * (int)Constants.RegionSize)))
  279. {
  280. Vector3 offset = Vector3.Zero;
  281. offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
  282. ((conn.X * (int)Constants.RegionSize)));
  283. offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
  284. ((conn.Y * (int)Constants.RegionSize)));
  285. Vector3 extents = Vector3.Zero;
  286. extents.Y = regionConnections.YEnd + conn.YEnd;
  287. extents.X = conn.XEnd;
  288. m_log.DebugFormat("Scene: {0} to the north of Scene{1}. Offset: {2}. Extents:{3}",
  289. conn.RegionScene.RegionInfo.RegionName,
  290. regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
  291. scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
  292. connectedYN = true;
  293. break;
  294. }
  295. */
  296. /*
  297. // If we're one region over -x +y
  298. //xxx
  299. //xxx
  300. //yxx
  301. if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
  302. == (regionConnections.X * (int)Constants.RegionSize))
  303. && (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
  304. == (regionConnections.Y * (int)Constants.RegionSize)))
  305. {
  306. Vector3 offset = Vector3.Zero;
  307. offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
  308. ((conn.X * (int)Constants.RegionSize)));
  309. offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
  310. ((conn.Y * (int)Constants.RegionSize)));
  311. Vector3 extents = Vector3.Zero;
  312. extents.Y = regionConnections.YEnd + conn.YEnd;
  313. extents.X = conn.XEnd + conn.XEnd;
  314. m_log.DebugFormat("Scene: {0} to the northeast of Scene. Offset: {2}. Extents:{3}",
  315. conn.RegionScene.RegionInfo.RegionName,
  316. regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
  317. scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
  318. connectedYN = true;
  319. break;
  320. }
  321. */
  322. /*
  323. // If we're one region over -x y
  324. //xxx
  325. //yxx
  326. //xxx
  327. if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
  328. == (regionConnections.X * (int)Constants.RegionSize))
  329. && (((int)conn.Y * (int)Constants.RegionSize)
  330. == (regionConnections.Y * (int)Constants.RegionSize)))
  331. {
  332. Vector3 offset = Vector3.Zero;
  333. offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
  334. ((conn.X * (int)Constants.RegionSize)));
  335. offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
  336. ((conn.Y * (int)Constants.RegionSize)));
  337. Vector3 extents = Vector3.Zero;
  338. extents.Y = regionConnections.YEnd;
  339. extents.X = conn.XEnd + conn.XEnd;
  340. m_log.DebugFormat("Scene: {0} to the east of Scene{1} Offset: {2}. Extents:{3}",
  341. conn.RegionScene.RegionInfo.RegionName,
  342. regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
  343. scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
  344. connectedYN = true;
  345. break;
  346. }
  347. */
  348. /*
  349. // If we're one region over -x -y
  350. //yxx
  351. //xxx
  352. //xxx
  353. if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
  354. == (regionConnections.X * (int)Constants.RegionSize))
  355. && (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
  356. == (regionConnections.Y * (int)Constants.RegionSize)))
  357. {
  358. Vector3 offset = Vector3.Zero;
  359. offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
  360. ((conn.X * (int)Constants.RegionSize)));
  361. offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
  362. ((conn.Y * (int)Constants.RegionSize)));
  363. Vector3 extents = Vector3.Zero;
  364. extents.Y = regionConnections.YEnd + conn.YEnd;
  365. extents.X = conn.XEnd + conn.XEnd;
  366. m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}",
  367. conn.RegionScene.RegionInfo.RegionName,
  368. regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
  369. scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
  370. connectedYN = true;
  371. break;
  372. }
  373. */
  374. #endregion
  375. // Check to see if this new region is adjacent to the root region.
  376. // Note that we expect the regions to be combined from the root region outward
  377. // thus the requirement for the ordering in the configuration files.
  378. // If we're one region over +x y (i.e. root region is to the west)
  379. //xxx
  380. //xxy
  381. //xxx
  382. if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY >= newConn.PosY)
  383. {
  384. connectedYN = DoWorkForOneRegionOverPlusXY(rootConn, newConn, scene);
  385. break;
  386. }
  387. // If we're one region over x +y (i.e. root region is to the south)
  388. //xyx
  389. //xxx
  390. //xxx
  391. if (rootConn.PosX >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
  392. {
  393. connectedYN = DoWorkForOneRegionOverPlusXY(rootConn, newConn, scene);
  394. break;
  395. }
  396. // If we're one region over +x +y (i.e. root region is to the south-west)
  397. //xxy
  398. //xxx
  399. //xxx
  400. if (rootConn.PosX + rootConn.XEnd >= newConn.PosX && rootConn.PosY + rootConn.YEnd >= newConn.PosY)
  401. {
  402. connectedYN = DoWorkForOneRegionOverPlusXY(rootConn, newConn, scene);
  403. break;
  404. }
  405. }
  406. // If !connectYN means that this region is a root region
  407. if (!connectedYN)
  408. {
  409. DoWorkForRootRegion(newConn, scene);
  410. }
  411. }
  412. }
  413. private bool DoWorkForOneRegionOverPlusXY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
  414. {
  415. // Offset (in meters) from the base of this region to the base of the root region.
  416. Vector3 offset = Vector3.Zero;
  417. offset.X = newConn.PosX - rootConn.PosX;
  418. offset.Y = newConn.PosY - rootConn.PosY;
  419. // The new total size of the region (in meters)
  420. // We just extend the X and Y dimensions so the extent might temporarily include areas without regions.
  421. Vector3 extents = Vector3.Zero;
  422. extents.X = Math.Max(rootConn.XEnd, offset.X + newConn.RegionScene.RegionInfo.RegionSizeX);
  423. extents.Y = Math.Max(rootConn.YEnd, offset.Y + newConn.RegionScene.RegionInfo.RegionSizeY);
  424. rootConn.UpdateExtents(extents);
  425. m_log.DebugFormat(
  426. "[REGION COMBINER MODULE]: Root region {0} is to the west of region {1}, Offset: {2}, Extents: {3}",
  427. rootConn.RegionScene.RegionInfo.RegionName,
  428. newConn.RegionScene.RegionInfo.RegionName, offset, extents);
  429. RegionData ConnectedRegion = new RegionData();
  430. ConnectedRegion.Offset = offset;
  431. ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
  432. ConnectedRegion.RegionScene = scene;
  433. rootConn.ConnectedRegions.Add(ConnectedRegion);
  434. // Inform root region Physics about the extents of this region
  435. rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
  436. // Inform Child region that it needs to forward it's terrain to the root region
  437. scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
  438. // Reset Terrain.. since terrain loads before we get here, we need to load
  439. // it again so it loads in the root region
  440. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  441. // Create a client event forwarder and add this region's events to the root region.
  442. if (rootConn.ClientEventForwarder != null)
  443. rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
  444. return true;
  445. }
  446. /*
  447. * 20140215 radams1: The border stuff was removed and the addition of regions to the mega-regions
  448. * was generalized. These functions are not needed for the generalized solution but left for reference.
  449. private bool DoWorkForOneRegionOverXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
  450. {
  451. Vector3 offset = Vector3.Zero;
  452. offset.X = newConn.PosX - rootConn.PosX;
  453. offset.Y = newConn.PosY - rootConn.PosY;
  454. Vector3 extents = Vector3.Zero;
  455. extents.Y = newConn.YEnd + rootConn.YEnd;
  456. extents.X = rootConn.XEnd;
  457. rootConn.UpdateExtents(extents);
  458. RegionData ConnectedRegion = new RegionData();
  459. ConnectedRegion.Offset = offset;
  460. ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
  461. ConnectedRegion.RegionScene = scene;
  462. rootConn.ConnectedRegions.Add(ConnectedRegion);
  463. m_log.DebugFormat(
  464. "[REGION COMBINER MODULE]: Root region {0} is to the south of region {1}, Offset: {2}, Extents: {3}",
  465. rootConn.RegionScene.RegionInfo.RegionName,
  466. newConn.RegionScene.RegionInfo.RegionName, offset, extents);
  467. rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
  468. scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
  469. // Reset Terrain.. since terrain normally loads first.
  470. //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
  471. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  472. //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
  473. if (rootConn.ClientEventForwarder != null)
  474. rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
  475. return true;
  476. }
  477. private bool DoWorkForOneRegionOverPlusXPlusY(RegionConnections rootConn, RegionConnections newConn, Scene scene)
  478. {
  479. Vector3 offset = Vector3.Zero;
  480. offset.X = newConn.PosX - rootConn.PosX;
  481. offset.Y = newConn.PosY - rootConn.PosY;
  482. Vector3 extents = Vector3.Zero;
  483. // We do not want to inflate the extents for regions strictly to the NE of the root region, since this
  484. // would double count regions strictly to the north and east that have already been added.
  485. // extents.Y = regionConnections.YEnd + conn.YEnd;
  486. // extents.X = regionConnections.XEnd + conn.XEnd;
  487. // conn.UpdateExtents(extents);
  488. extents.Y = rootConn.YEnd;
  489. extents.X = rootConn.XEnd;
  490. RegionData ConnectedRegion = new RegionData();
  491. ConnectedRegion.Offset = offset;
  492. ConnectedRegion.RegionId = scene.RegionInfo.originRegionID;
  493. ConnectedRegion.RegionScene = scene;
  494. rootConn.ConnectedRegions.Add(ConnectedRegion);
  495. m_log.DebugFormat(
  496. "[REGION COMBINER MODULE]: Region {0} is to the southwest of Scene {1}, Offset: {2}, Extents: {3}",
  497. rootConn.RegionScene.RegionInfo.RegionName,
  498. newConn.RegionScene.RegionInfo.RegionName, offset, extents);
  499. rootConn.RegionScene.PhysicsScene.Combine(null, Vector3.Zero, extents);
  500. scene.PhysicsScene.Combine(rootConn.RegionScene.PhysicsScene, offset, Vector3.Zero);
  501. // Reset Terrain.. since terrain normally loads first.
  502. //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
  503. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  504. //conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
  505. if (rootConn.ClientEventForwarder != null)
  506. rootConn.ClientEventForwarder.AddSceneToEventForwarding(scene);
  507. return true;
  508. //scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents);
  509. }
  510. */
  511. private void DoWorkForRootRegion(RegionConnections rootConn, Scene scene)
  512. {
  513. m_log.DebugFormat("[REGION COMBINER MODULE]: Adding root region {0}", scene.RegionInfo.RegionName);
  514. RegionData rdata = new RegionData();
  515. rdata.Offset = Vector3.Zero;
  516. rdata.RegionId = scene.RegionInfo.originRegionID;
  517. rdata.RegionScene = scene;
  518. // save it's land channel
  519. rootConn.RegionLandChannel = scene.LandChannel;
  520. // Substitue our landchannel
  521. RegionCombinerLargeLandChannel lnd = new RegionCombinerLargeLandChannel(rdata, scene.LandChannel,
  522. rootConn.ConnectedRegions);
  523. scene.LandChannel = lnd;
  524. // Forward the permissions modules of each of the connected regions to the root region
  525. lock (m_regions)
  526. {
  527. foreach (RegionData r in rootConn.ConnectedRegions)
  528. {
  529. ForwardPermissionRequests(rootConn, r.RegionScene);
  530. }
  531. // Create the root region's Client Event Forwarder
  532. rootConn.ClientEventForwarder = new RegionCombinerClientEventForwarder(rootConn);
  533. // Sets up the CoarseLocationUpdate forwarder for this root region
  534. scene.EventManager.OnNewPresence += SetCoarseLocationDelegate;
  535. // Adds this root region to a dictionary of regions that are connectable
  536. m_regions.Add(scene.RegionInfo.originRegionID, rootConn);
  537. }
  538. }
  539. private void SetCoarseLocationDelegate(ScenePresence presence)
  540. {
  541. presence.SetSendCoarseLocationMethod(SendCoarseLocationUpdates);
  542. }
  543. // This delegate was refactored for non-combined regions.
  544. // This combined region version will not use the pre-compiled lists of locations and ids
  545. private void SendCoarseLocationUpdates(UUID sceneId, ScenePresence presence, List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
  546. {
  547. RegionConnections connectiondata = null;
  548. lock (m_regions)
  549. {
  550. if (m_regions.ContainsKey(sceneId))
  551. connectiondata = m_regions[sceneId];
  552. else
  553. return;
  554. }
  555. List<Vector3> CoarseLocations = new List<Vector3>();
  556. List<UUID> AvatarUUIDs = new List<UUID>();
  557. connectiondata.RegionScene.ForEachRootScenePresence(delegate(ScenePresence sp)
  558. {
  559. if (sp.UUID != presence.UUID)
  560. {
  561. CoarseLocations.Add(sp.AbsolutePosition);
  562. AvatarUUIDs.Add(sp.UUID);
  563. }
  564. });
  565. DistributeCoarseLocationUpdates(CoarseLocations, AvatarUUIDs, connectiondata, presence);
  566. }
  567. private void DistributeCoarseLocationUpdates(List<Vector3> locations, List<UUID> uuids,
  568. RegionConnections connectiondata, ScenePresence rootPresence)
  569. {
  570. RegionData[] rdata = connectiondata.ConnectedRegions.ToArray();
  571. //List<IClientAPI> clients = new List<IClientAPI>();
  572. Dictionary<Vector2, RegionCoarseLocationStruct> updates = new Dictionary<Vector2, RegionCoarseLocationStruct>();
  573. // Root Region entry
  574. RegionCoarseLocationStruct rootupdatedata = new RegionCoarseLocationStruct();
  575. rootupdatedata.Locations = new List<Vector3>();
  576. rootupdatedata.Uuids = new List<UUID>();
  577. rootupdatedata.Offset = Vector2.Zero;
  578. rootupdatedata.UserAPI = rootPresence.ControllingClient;
  579. if (rootupdatedata.UserAPI != null)
  580. updates.Add(Vector2.Zero, rootupdatedata);
  581. //Each Region needs an entry or we will end up with dead minimap dots
  582. foreach (RegionData regiondata in rdata)
  583. {
  584. Vector2 offset = new Vector2(regiondata.Offset.X, regiondata.Offset.Y);
  585. RegionCoarseLocationStruct updatedata = new RegionCoarseLocationStruct();
  586. updatedata.Locations = new List<Vector3>();
  587. updatedata.Uuids = new List<UUID>();
  588. updatedata.Offset = offset;
  589. if (offset == Vector2.Zero)
  590. updatedata.UserAPI = rootPresence.ControllingClient;
  591. else
  592. updatedata.UserAPI = LocateUsersChildAgentIClientAPI(offset, rootPresence.UUID, rdata);
  593. if (updatedata.UserAPI != null)
  594. updates.Add(offset, updatedata);
  595. }
  596. // go over the locations and assign them to an IClientAPI
  597. for (int i = 0; i < locations.Count; i++)
  598. //{locations[i]/(int) Constants.RegionSize;
  599. {
  600. Vector3 pPosition = new Vector3((int)locations[i].X / (int)Constants.RegionSize,
  601. (int)locations[i].Y / (int)Constants.RegionSize, locations[i].Z);
  602. Vector2 offset = new Vector2(pPosition.X*(int) Constants.RegionSize,
  603. pPosition.Y*(int) Constants.RegionSize);
  604. if (!updates.ContainsKey(offset))
  605. {
  606. // This shouldn't happen
  607. RegionCoarseLocationStruct updatedata = new RegionCoarseLocationStruct();
  608. updatedata.Locations = new List<Vector3>();
  609. updatedata.Uuids = new List<UUID>();
  610. updatedata.Offset = offset;
  611. if (offset == Vector2.Zero)
  612. updatedata.UserAPI = rootPresence.ControllingClient;
  613. else
  614. updatedata.UserAPI = LocateUsersChildAgentIClientAPI(offset, rootPresence.UUID, rdata);
  615. updates.Add(offset,updatedata);
  616. }
  617. updates[offset].Locations.Add(locations[i]);
  618. updates[offset].Uuids.Add(uuids[i]);
  619. }
  620. // Send out the CoarseLocationupdates from their respective client connection based on where the avatar is
  621. foreach (Vector2 offset in updates.Keys)
  622. {
  623. if (updates[offset].UserAPI != null)
  624. {
  625. updates[offset].UserAPI.SendCoarseLocationUpdate(updates[offset].Uuids,updates[offset].Locations);
  626. }
  627. }
  628. }
  629. /// <summary>
  630. /// Locates a the Client of a particular region in an Array of RegionData based on offset
  631. /// </summary>
  632. /// <param name="offset"></param>
  633. /// <param name="uUID"></param>
  634. /// <param name="rdata"></param>
  635. /// <returns>IClientAPI or null</returns>
  636. private IClientAPI LocateUsersChildAgentIClientAPI(Vector2 offset, UUID uUID, RegionData[] rdata)
  637. {
  638. IClientAPI returnclient = null;
  639. foreach (RegionData r in rdata)
  640. {
  641. if (r.Offset.X == offset.X && r.Offset.Y == offset.Y)
  642. {
  643. return r.RegionScene.SceneGraph.GetControllingClient(uUID);
  644. }
  645. }
  646. return returnclient;
  647. }
  648. public void PostInitialise()
  649. {
  650. }
  651. // /// <summary>
  652. // /// TODO:
  653. // /// </summary>
  654. // /// <param name="rdata"></param>
  655. // public void UnCombineRegion(RegionData rdata)
  656. // {
  657. // lock (m_regions)
  658. // {
  659. // if (m_regions.ContainsKey(rdata.RegionId))
  660. // {
  661. // // uncombine root region and virtual regions
  662. // }
  663. // else
  664. // {
  665. // foreach (RegionConnections r in m_regions.Values)
  666. // {
  667. // foreach (RegionData rd in r.ConnectedRegions)
  668. // {
  669. // if (rd.RegionId == rdata.RegionId)
  670. // {
  671. // // uncombine virtual region
  672. // }
  673. // }
  674. // }
  675. // }
  676. // }
  677. // }
  678. public void ForwardPermissionRequests(RegionConnections BigRegion, Scene VirtualRegion)
  679. {
  680. if (BigRegion.PermissionModule == null)
  681. BigRegion.PermissionModule = new RegionCombinerPermissionModule(BigRegion.RegionScene);
  682. VirtualRegion.Permissions.OnBypassPermissions += BigRegion.PermissionModule.BypassPermissions;
  683. VirtualRegion.Permissions.OnSetBypassPermissions += BigRegion.PermissionModule.SetBypassPermissions;
  684. VirtualRegion.Permissions.OnPropagatePermissions += BigRegion.PermissionModule.PropagatePermissions;
  685. VirtualRegion.Permissions.OnGenerateClientFlags += BigRegion.PermissionModule.GenerateClientFlags;
  686. VirtualRegion.Permissions.OnAbandonParcel += BigRegion.PermissionModule.CanAbandonParcel;
  687. VirtualRegion.Permissions.OnReclaimParcel += BigRegion.PermissionModule.CanReclaimParcel;
  688. VirtualRegion.Permissions.OnDeedParcel += BigRegion.PermissionModule.CanDeedParcel;
  689. VirtualRegion.Permissions.OnDeedObject += BigRegion.PermissionModule.CanDeedObject;
  690. VirtualRegion.Permissions.OnIsGod += BigRegion.PermissionModule.IsGod;
  691. VirtualRegion.Permissions.OnDuplicateObject += BigRegion.PermissionModule.CanDuplicateObject;
  692. VirtualRegion.Permissions.OnDeleteObject += BigRegion.PermissionModule.CanDeleteObject; //MAYBE FULLY IMPLEMENTED
  693. VirtualRegion.Permissions.OnEditObject += BigRegion.PermissionModule.CanEditObject; //MAYBE FULLY IMPLEMENTED
  694. VirtualRegion.Permissions.OnEditParcelProperties += BigRegion.PermissionModule.CanEditParcelProperties; //MAYBE FULLY IMPLEMENTED
  695. VirtualRegion.Permissions.OnInstantMessage += BigRegion.PermissionModule.CanInstantMessage;
  696. VirtualRegion.Permissions.OnInventoryTransfer += BigRegion.PermissionModule.CanInventoryTransfer; //NOT YET IMPLEMENTED
  697. VirtualRegion.Permissions.OnIssueEstateCommand += BigRegion.PermissionModule.CanIssueEstateCommand; //FULLY IMPLEMENTED
  698. VirtualRegion.Permissions.OnMoveObject += BigRegion.PermissionModule.CanMoveObject; //MAYBE FULLY IMPLEMENTED
  699. VirtualRegion.Permissions.OnObjectEntry += BigRegion.PermissionModule.CanObjectEntry;
  700. VirtualRegion.Permissions.OnReturnObjects += BigRegion.PermissionModule.CanReturnObjects; //NOT YET IMPLEMENTED
  701. VirtualRegion.Permissions.OnRezObject += BigRegion.PermissionModule.CanRezObject; //MAYBE FULLY IMPLEMENTED
  702. VirtualRegion.Permissions.OnRunConsoleCommand += BigRegion.PermissionModule.CanRunConsoleCommand;
  703. VirtualRegion.Permissions.OnRunScript += BigRegion.PermissionModule.CanRunScript; //NOT YET IMPLEMENTED
  704. VirtualRegion.Permissions.OnCompileScript += BigRegion.PermissionModule.CanCompileScript;
  705. VirtualRegion.Permissions.OnSellParcel += BigRegion.PermissionModule.CanSellParcel;
  706. VirtualRegion.Permissions.OnTakeObject += BigRegion.PermissionModule.CanTakeObject;
  707. VirtualRegion.Permissions.OnTakeCopyObject += BigRegion.PermissionModule.CanTakeCopyObject;
  708. VirtualRegion.Permissions.OnTerraformLand += BigRegion.PermissionModule.CanTerraformLand;
  709. VirtualRegion.Permissions.OnLinkObject += BigRegion.PermissionModule.CanLinkObject; //NOT YET IMPLEMENTED
  710. VirtualRegion.Permissions.OnDelinkObject += BigRegion.PermissionModule.CanDelinkObject; //NOT YET IMPLEMENTED
  711. VirtualRegion.Permissions.OnBuyLand += BigRegion.PermissionModule.CanBuyLand; //NOT YET IMPLEMENTED
  712. VirtualRegion.Permissions.OnViewNotecard += BigRegion.PermissionModule.CanViewNotecard; //NOT YET IMPLEMENTED
  713. VirtualRegion.Permissions.OnViewScript += BigRegion.PermissionModule.CanViewScript; //NOT YET IMPLEMENTED
  714. VirtualRegion.Permissions.OnEditNotecard += BigRegion.PermissionModule.CanEditNotecard; //NOT YET IMPLEMENTED
  715. VirtualRegion.Permissions.OnEditScript += BigRegion.PermissionModule.CanEditScript; //NOT YET IMPLEMENTED
  716. VirtualRegion.Permissions.OnCreateObjectInventory += BigRegion.PermissionModule.CanCreateObjectInventory; //NOT IMPLEMENTED HERE
  717. VirtualRegion.Permissions.OnEditObjectInventory += BigRegion.PermissionModule.CanEditObjectInventory;//MAYBE FULLY IMPLEMENTED
  718. VirtualRegion.Permissions.OnCopyObjectInventory += BigRegion.PermissionModule.CanCopyObjectInventory; //NOT YET IMPLEMENTED
  719. VirtualRegion.Permissions.OnDeleteObjectInventory += BigRegion.PermissionModule.CanDeleteObjectInventory; //NOT YET IMPLEMENTED
  720. VirtualRegion.Permissions.OnResetScript += BigRegion.PermissionModule.CanResetScript;
  721. VirtualRegion.Permissions.OnCreateUserInventory += BigRegion.PermissionModule.CanCreateUserInventory; //NOT YET IMPLEMENTED
  722. VirtualRegion.Permissions.OnCopyUserInventory += BigRegion.PermissionModule.CanCopyUserInventory; //NOT YET IMPLEMENTED
  723. VirtualRegion.Permissions.OnEditUserInventory += BigRegion.PermissionModule.CanEditUserInventory; //NOT YET IMPLEMENTED
  724. VirtualRegion.Permissions.OnDeleteUserInventory += BigRegion.PermissionModule.CanDeleteUserInventory; //NOT YET IMPLEMENTED
  725. VirtualRegion.Permissions.OnTeleport += BigRegion.PermissionModule.CanTeleport; //NOT YET IMPLEMENTED
  726. }
  727. #region console commands
  728. public void FixPhantoms(string module, string[] cmdparams)
  729. {
  730. List<Scene> scenes = new List<Scene>(m_startingScenes.Values);
  731. foreach (Scene s in scenes)
  732. {
  733. MainConsole.Instance.OutputFormat("Fixing phantoms for {0}", s.RegionInfo.RegionName);
  734. s.ForEachSOG(so => so.AbsolutePosition = so.AbsolutePosition);
  735. }
  736. }
  737. #endregion
  738. }
  739. }