diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World')
9 files changed, 775 insertions, 104 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index 3238a81..fd8f546 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs | |||
@@ -217,22 +217,20 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
217 | m_scene.DeleteAllSceneObjects(); | 217 | m_scene.DeleteAllSceneObjects(); |
218 | } | 218 | } |
219 | 219 | ||
220 | // Try to retain the original creator/owner/lastowner if their uuid is present on this grid | 220 | LoadParcels(serialisedParcels); |
221 | // otherwise, use the master avatar uuid instead | 221 | LoadObjects(serialisedSceneObjects); |
222 | 222 | ||
223 | // Reload serialized parcels | 223 | m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive"); |
224 | m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count); | ||
225 | List<LandData> landData = new List<LandData>(); | ||
226 | foreach (string serialisedParcel in serialisedParcels) | ||
227 | { | ||
228 | LandData parcel = LandDataSerializer.Deserialize(serialisedParcel); | ||
229 | if (!ResolveUserUuid(parcel.OwnerID)) | ||
230 | parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; | ||
231 | landData.Add(parcel); | ||
232 | } | ||
233 | m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData); | ||
234 | m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count); | ||
235 | 224 | ||
225 | m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage); | ||
226 | } | ||
227 | |||
228 | /// <summary> | ||
229 | /// Load serialized scene objects. | ||
230 | /// </summary> | ||
231 | /// <param name="serialisedSceneObjects"></param> | ||
232 | protected void LoadObjects(List<string> serialisedSceneObjects) | ||
233 | { | ||
236 | // Reload serialized prims | 234 | // Reload serialized prims |
237 | m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); | 235 | m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); |
238 | 236 | ||
@@ -262,6 +260,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
262 | // to the same scene (when this is possible). | 260 | // to the same scene (when this is possible). |
263 | sceneObject.ResetIDs(); | 261 | sceneObject.ResetIDs(); |
264 | 262 | ||
263 | // Try to retain the original creator/owner/lastowner if their uuid is present on this grid | ||
264 | // or creator data is present. Otherwise, use the estate owner instead. | ||
265 | foreach (SceneObjectPart part in sceneObject.Parts) | 265 | foreach (SceneObjectPart part in sceneObject.Parts) |
266 | { | 266 | { |
267 | if (part.CreatorData == null || part.CreatorData == string.Empty) | 267 | if (part.CreatorData == null || part.CreatorData == string.Empty) |
@@ -318,11 +318,36 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
318 | int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount; | 318 | int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount; |
319 | 319 | ||
320 | if (ignoredObjects > 0) | 320 | if (ignoredObjects > 0) |
321 | m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene", ignoredObjects); | 321 | m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene", ignoredObjects); |
322 | 322 | } | |
323 | m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive"); | 323 | |
324 | 324 | /// <summary> | |
325 | m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage); | 325 | /// Load serialized parcels. |
326 | /// </summary> | ||
327 | /// <param name="serialisedParcels"></param> | ||
328 | protected void LoadParcels(List<string> serialisedParcels) | ||
329 | { | ||
330 | // Reload serialized parcels | ||
331 | m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count); | ||
332 | List<LandData> landData = new List<LandData>(); | ||
333 | foreach (string serialisedParcel in serialisedParcels) | ||
334 | { | ||
335 | LandData parcel = LandDataSerializer.Deserialize(serialisedParcel); | ||
336 | if (!ResolveUserUuid(parcel.OwnerID)) | ||
337 | parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; | ||
338 | |||
339 | // m_log.DebugFormat( | ||
340 | // "[ARCHIVER]: Adding parcel {0}, local id {1}, area {2}", | ||
341 | // parcel.Name, parcel.LocalID, parcel.Area); | ||
342 | |||
343 | landData.Add(parcel); | ||
344 | } | ||
345 | |||
346 | if (!m_merge) | ||
347 | m_scene.LandChannel.Clear(false); | ||
348 | |||
349 | m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData); | ||
350 | m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count); | ||
326 | } | 351 | } |
327 | 352 | ||
328 | /// <summary> | 353 | /// <summary> |
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index b0563c5..01f04d9 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs | |||
@@ -555,37 +555,12 @@ namespace OpenSim.Region.CoreModules.World.Estate | |||
555 | 555 | ||
556 | try | 556 | try |
557 | { | 557 | { |
558 | MemoryStream terrainStream = new MemoryStream(terrainData); | ||
559 | terr.LoadFromStream(filename, terrainStream); | ||
560 | terrainStream.Close(); | ||
558 | 561 | ||
559 | string localfilename = "terrain.raw"; | 562 | FileInfo x = new FileInfo(filename); |
560 | 563 | remoteClient.SendAlertMessage("Your terrain was loaded as a " + x.Extension + " file. It may take a few moments to appear."); | |
561 | if (terrainData.Length == 851968) | ||
562 | { | ||
563 | localfilename = Path.Combine(Util.dataDir(),"terrain.raw"); // It's a .LLRAW | ||
564 | } | ||
565 | |||
566 | if (terrainData.Length == 196662) // 24-bit 256x256 Bitmap | ||
567 | localfilename = Path.Combine(Util.dataDir(), "terrain.bmp"); | ||
568 | |||
569 | if (terrainData.Length == 256 * 256 * 4) // It's a .R32 | ||
570 | localfilename = Path.Combine(Util.dataDir(), "terrain.r32"); | ||
571 | |||
572 | if (terrainData.Length == 256 * 256 * 8) // It's a .R64 | ||
573 | localfilename = Path.Combine(Util.dataDir(), "terrain.r64"); | ||
574 | |||
575 | if (File.Exists(localfilename)) | ||
576 | { | ||
577 | File.Delete(localfilename); | ||
578 | } | ||
579 | |||
580 | FileStream input = new FileStream(localfilename, FileMode.CreateNew); | ||
581 | input.Write(terrainData, 0, terrainData.Length); | ||
582 | input.Close(); | ||
583 | |||
584 | FileInfo x = new FileInfo(localfilename); | ||
585 | |||
586 | terr.LoadFromFile(localfilename); | ||
587 | remoteClient.SendAlertMessage("Your terrain was loaded as a ." + x.Extension + " file. It may take a few moments to appear."); | ||
588 | |||
589 | } | 564 | } |
590 | catch (IOException e) | 565 | catch (IOException e) |
591 | { | 566 | { |
diff --git a/OpenSim/Region/CoreModules/World/Land/LandChannel.cs b/OpenSim/Region/CoreModules/World/Land/LandChannel.cs index 9e27ef0..7d990c2 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandChannel.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandChannel.cs | |||
@@ -116,6 +116,12 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
116 | 116 | ||
117 | return new List<ILandObject>(); | 117 | return new List<ILandObject>(); |
118 | } | 118 | } |
119 | |||
120 | public void Clear(bool setupDefaultParcel) | ||
121 | { | ||
122 | if (m_landManagementModule != null) | ||
123 | m_landManagementModule.Clear(setupDefaultParcel); | ||
124 | } | ||
119 | 125 | ||
120 | public List<ILandObject> ParcelsNearPoint(Vector3 position) | 126 | public List<ILandObject> ParcelsNearPoint(Vector3 position) |
121 | { | 127 | { |
diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs index 70767f7..98ba8c3 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs | |||
@@ -298,13 +298,19 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
298 | m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; | 298 | m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; |
299 | m_landIDList.Initialize(); | 299 | m_landIDList.Initialize(); |
300 | } | 300 | } |
301 | 301 | } | |
302 | |||
303 | /// <summary> | ||
304 | /// Create a default parcel that spans the entire region and is owned by the estate owner. | ||
305 | /// </summary> | ||
306 | /// <returns>The parcel created.</returns> | ||
307 | protected ILandObject CreateDefaultParcel() | ||
308 | { | ||
302 | ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene); | 309 | ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene); |
303 | |||
304 | fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize)); | 310 | fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize)); |
305 | fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; | 311 | fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; |
306 | fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); | 312 | fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); |
307 | AddLandObject(fullSimParcel); | 313 | return AddLandObject(fullSimParcel); |
308 | } | 314 | } |
309 | 315 | ||
310 | public List<ILandObject> AllParcels() | 316 | public List<ILandObject> AllParcels() |
@@ -578,15 +584,6 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
578 | } | 584 | } |
579 | 585 | ||
580 | /// <summary> | 586 | /// <summary> |
581 | /// Creates a basic Parcel object without an owner (a zeroed key) | ||
582 | /// </summary> | ||
583 | /// <returns></returns> | ||
584 | public ILandObject CreateBaseLand() | ||
585 | { | ||
586 | return new LandObject(UUID.Zero, false, m_scene); | ||
587 | } | ||
588 | |||
589 | /// <summary> | ||
590 | /// Adds a land object to the stored list and adds them to the landIDList to what they own | 587 | /// Adds a land object to the stored list and adds them to the landIDList to what they own |
591 | /// </summary> | 588 | /// </summary> |
592 | /// <param name="new_land">The land object being added</param> | 589 | /// <param name="new_land">The land object being added</param> |
@@ -645,6 +642,28 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
645 | m_landList.Remove(local_id); | 642 | m_landList.Remove(local_id); |
646 | } | 643 | } |
647 | } | 644 | } |
645 | |||
646 | /// <summary> | ||
647 | /// Clear the scene of all parcels | ||
648 | /// </summary> | ||
649 | public void Clear(bool setupDefaultParcel) | ||
650 | { | ||
651 | lock (m_landList) | ||
652 | { | ||
653 | foreach (ILandObject lo in m_landList.Values) | ||
654 | { | ||
655 | //m_scene.SimulationDataService.RemoveLandObject(lo.LandData.GlobalID); | ||
656 | m_scene.EventManager.TriggerLandObjectRemoved(lo.LandData.GlobalID); | ||
657 | } | ||
658 | |||
659 | m_landList.Clear(); | ||
660 | } | ||
661 | |||
662 | ResetSimLandObjects(); | ||
663 | |||
664 | if (setupDefaultParcel) | ||
665 | CreateDefaultParcel(); | ||
666 | } | ||
648 | 667 | ||
649 | private void performFinalLandJoin(ILandObject master, ILandObject slave) | 668 | private void performFinalLandJoin(ILandObject master, ILandObject slave) |
650 | { | 669 | { |
@@ -690,7 +709,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
690 | int x; | 709 | int x; |
691 | int y; | 710 | int y; |
692 | 711 | ||
693 | if (x_float > Constants.RegionSize || x_float <= 0 || y_float > Constants.RegionSize || y_float <= 0) | 712 | if (x_float >= Constants.RegionSize || x_float < 0 || y_float >= Constants.RegionSize || y_float < 0) |
694 | return null; | 713 | return null; |
695 | 714 | ||
696 | try | 715 | try |
@@ -732,10 +751,10 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
732 | { | 751 | { |
733 | try | 752 | try |
734 | { | 753 | { |
735 | if (m_landList.ContainsKey(m_landIDList[x / 4, y / 4])) | 754 | //if (m_landList.ContainsKey(m_landIDList[x / 4, y / 4])) |
736 | return m_landList[m_landIDList[x / 4, y / 4]]; | 755 | return m_landList[m_landIDList[x / 4, y / 4]]; |
737 | else | 756 | //else |
738 | return null; | 757 | // return null; |
739 | } | 758 | } |
740 | catch (IndexOutOfRangeException) | 759 | catch (IndexOutOfRangeException) |
741 | { | 760 | { |
@@ -1311,7 +1330,6 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1311 | } | 1330 | } |
1312 | } | 1331 | } |
1313 | 1332 | ||
1314 | |||
1315 | void ClientOnParcelDeedToGroup(int parcelLocalID, UUID groupID, IClientAPI remote_client) | 1333 | void ClientOnParcelDeedToGroup(int parcelLocalID, UUID groupID, IClientAPI remote_client) |
1316 | { | 1334 | { |
1317 | ILandObject land; | 1335 | ILandObject land; |
@@ -1327,10 +1345,8 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1327 | { | 1345 | { |
1328 | land.DeedToGroup(groupID); | 1346 | land.DeedToGroup(groupID); |
1329 | } | 1347 | } |
1330 | |||
1331 | } | 1348 | } |
1332 | 1349 | ||
1333 | |||
1334 | #region Land Object From Storage Functions | 1350 | #region Land Object From Storage Functions |
1335 | 1351 | ||
1336 | public void EventManagerOnIncomingLandDataFromStorage(List<LandData> data) | 1352 | public void EventManagerOnIncomingLandDataFromStorage(List<LandData> data) |
@@ -1365,6 +1381,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1365 | public void EventManagerOnNoLandDataFromStorage() | 1381 | public void EventManagerOnNoLandDataFromStorage() |
1366 | { | 1382 | { |
1367 | ResetSimLandObjects(); | 1383 | ResetSimLandObjects(); |
1384 | CreateDefaultParcel(); | ||
1368 | } | 1385 | } |
1369 | 1386 | ||
1370 | #endregion | 1387 | #endregion |
@@ -1622,14 +1639,36 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1622 | 1639 | ||
1623 | protected void InstallInterfaces() | 1640 | protected void InstallInterfaces() |
1624 | { | 1641 | { |
1625 | Command showCommand = | 1642 | Command clearCommand |
1626 | new Command("show", CommandIntentions.COMMAND_STATISTICAL, ShowParcelsCommand, "Shows all parcels on the current region."); | 1643 | = new Command("clear", CommandIntentions.COMMAND_HAZARDOUS, ClearCommand, "Clears all the parcels from the region."); |
1644 | Command showCommand | ||
1645 | = new Command("show", CommandIntentions.COMMAND_STATISTICAL, ShowParcelsCommand, "Shows all parcels on the region."); | ||
1627 | 1646 | ||
1647 | m_commander.RegisterCommand("clear", clearCommand); | ||
1628 | m_commander.RegisterCommand("show", showCommand); | 1648 | m_commander.RegisterCommand("show", showCommand); |
1629 | 1649 | ||
1630 | // Add this to our scene so scripts can call these functions | 1650 | // Add this to our scene so scripts can call these functions |
1631 | m_scene.RegisterModuleCommander(m_commander); | 1651 | m_scene.RegisterModuleCommander(m_commander); |
1632 | } | 1652 | } |
1653 | |||
1654 | protected void ClearCommand(Object[] args) | ||
1655 | { | ||
1656 | string response = MainConsole.Instance.CmdPrompt( | ||
1657 | string.Format( | ||
1658 | "Are you sure that you want to clear all land parcels from {0} (y or n)", | ||
1659 | m_scene.RegionInfo.RegionName), | ||
1660 | "n"); | ||
1661 | |||
1662 | if (response.ToLower() == "y") | ||
1663 | { | ||
1664 | Clear(true); | ||
1665 | MainConsole.Instance.OutputFormat("Cleared all parcels from {0}", m_scene.RegionInfo.RegionName); | ||
1666 | } | ||
1667 | else | ||
1668 | { | ||
1669 | MainConsole.Instance.OutputFormat("Aborting clear of all parcels from {0}", m_scene.RegionInfo.RegionName); | ||
1670 | } | ||
1671 | } | ||
1633 | 1672 | ||
1634 | protected void ShowParcelsCommand(Object[] args) | 1673 | protected void ShowParcelsCommand(Object[] args) |
1635 | { | 1674 | { |
@@ -1637,8 +1676,9 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1637 | 1676 | ||
1638 | report.AppendFormat("Land information for {0}\n", m_scene.RegionInfo.RegionName); | 1677 | report.AppendFormat("Land information for {0}\n", m_scene.RegionInfo.RegionName); |
1639 | report.AppendFormat( | 1678 | report.AppendFormat( |
1640 | "{0,-20} {1,-9} {2,-18} {3,-18} {4,-20}\n", | 1679 | "{0,-20} {1,-10} {2,-9} {3,-18} {4,-18} {5,-20}\n", |
1641 | "Parcel Name", | 1680 | "Parcel Name", |
1681 | "Local ID", | ||
1642 | "Area", | 1682 | "Area", |
1643 | "Starts", | 1683 | "Starts", |
1644 | "Ends", | 1684 | "Ends", |
@@ -1651,12 +1691,12 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
1651 | LandData ld = lo.LandData; | 1691 | LandData ld = lo.LandData; |
1652 | 1692 | ||
1653 | report.AppendFormat( | 1693 | report.AppendFormat( |
1654 | "{0,-20} {1,-9} {2,-18} {3,-18} {4,-20}\n", | 1694 | "{0,-20} {1,-10} {2,-9} {3,-18} {4,-18} {5,-20}\n", |
1655 | ld.Name, ld.Area, lo.StartPoint, lo.EndPoint, m_userManager.GetUserName(ld.OwnerID)); | 1695 | ld.Name, ld.LocalID, ld.Area, lo.StartPoint, lo.EndPoint, m_userManager.GetUserName(ld.OwnerID)); |
1656 | } | 1696 | } |
1657 | } | 1697 | } |
1658 | 1698 | ||
1659 | MainConsole.Instance.Output(report.ToString()); | 1699 | MainConsole.Instance.Output(report.ToString()); |
1660 | } | 1700 | } |
1661 | } | 1701 | } |
1662 | } \ No newline at end of file | 1702 | } \ No newline at end of file |
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index b90e307..46c15ed 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs | |||
@@ -66,6 +66,13 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
66 | 66 | ||
67 | #region ILandObject Members | 67 | #region ILandObject Members |
68 | 68 | ||
69 | public int GetPrimsFree() | ||
70 | { | ||
71 | m_scene.EventManager.TriggerParcelPrimCountUpdate(); | ||
72 | int free = GetSimulatorMaxPrimCount(this) - m_landData.SimwidePrims; | ||
73 | return free; | ||
74 | } | ||
75 | |||
69 | public LandData LandData | 76 | public LandData LandData |
70 | { | 77 | { |
71 | get { return m_landData; } | 78 | get { return m_landData; } |
@@ -141,7 +148,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
141 | /// <returns>Returns true if the piece of land contains the specified point</returns> | 148 | /// <returns>Returns true if the piece of land contains the specified point</returns> |
142 | public bool ContainsPoint(int x, int y) | 149 | public bool ContainsPoint(int x, int y) |
143 | { | 150 | { |
144 | if (x >= 0 && y >= 0 && x <= Constants.RegionSize && y <= Constants.RegionSize) | 151 | if (x >= 0 && y >= 0 && x < Constants.RegionSize && y < Constants.RegionSize) |
145 | { | 152 | { |
146 | return (LandBitmap[x / 4, y / 4] == true); | 153 | return (LandBitmap[x / 4, y / 4] == true); |
147 | } | 154 | } |
@@ -183,7 +190,11 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
183 | else | 190 | else |
184 | { | 191 | { |
185 | // Normal Calculations | 192 | // Normal Calculations |
186 | return (int)Math.Round(((float)LandData.Area / 65536.0f) * (float)m_scene.RegionInfo.ObjectCapacity * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); | 193 | int parcelMax = (int)(((float)LandData.Area / 65536.0f) |
194 | * (float)m_scene.RegionInfo.ObjectCapacity | ||
195 | * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); | ||
196 | // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL! | ||
197 | return parcelMax; | ||
187 | } | 198 | } |
188 | } | 199 | } |
189 | public int GetSimulatorMaxPrimCount(ILandObject thisObject) | 200 | public int GetSimulatorMaxPrimCount(ILandObject thisObject) |
@@ -195,7 +206,9 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
195 | else | 206 | else |
196 | { | 207 | { |
197 | //Normal Calculations | 208 | //Normal Calculations |
198 | return m_scene.RegionInfo.ObjectCapacity; | 209 | int simMax = (int)(((float)LandData.SimwideArea / 65536.0f) |
210 | * (float)m_scene.RegionInfo.ObjectCapacity); | ||
211 | return simMax; | ||
199 | } | 212 | } |
200 | } | 213 | } |
201 | #endregion | 214 | #endregion |
@@ -369,7 +382,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
369 | newData.AuthBuyerID = UUID.Zero; | 382 | newData.AuthBuyerID = UUID.Zero; |
370 | newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); | 383 | newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); |
371 | m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); | 384 | m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); |
372 | 385 | m_scene.EventManager.TriggerParcelPrimCountUpdate(); | |
373 | SendLandUpdateToAvatarsOverMe(true); | 386 | SendLandUpdateToAvatarsOverMe(true); |
374 | } | 387 | } |
375 | 388 | ||
@@ -384,7 +397,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
384 | newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); | 397 | newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); |
385 | 398 | ||
386 | m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); | 399 | m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); |
387 | 400 | m_scene.EventManager.TriggerParcelPrimCountUpdate(); | |
388 | SendLandUpdateToAvatarsOverMe(true); | 401 | SendLandUpdateToAvatarsOverMe(true); |
389 | } | 402 | } |
390 | 403 | ||
@@ -450,6 +463,7 @@ namespace OpenSim.Region.CoreModules.World.Land | |||
450 | 463 | ||
451 | public void SendLandUpdateToClient(bool snap_selection, IClientAPI remote_client) | 464 | public void SendLandUpdateToClient(bool snap_selection, IClientAPI remote_client) |
452 | { | 465 | { |
466 | m_scene.EventManager.TriggerParcelPrimCountUpdate(); | ||
453 | SendLandProperties(0, snap_selection, 0, remote_client); | 467 | SendLandProperties(0, snap_selection, 0, remote_client); |
454 | } | 468 | } |
455 | 469 | ||
diff --git a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs new file mode 100644 index 0000000..34ef67f --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs | |||
@@ -0,0 +1,406 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Diagnostics; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.World.Land | ||
42 | { | ||
43 | public class ParcelCounts | ||
44 | { | ||
45 | public int Owner = 0; | ||
46 | public int Group = 0; | ||
47 | public int Others = 0; | ||
48 | public Dictionary <UUID, int> Users = | ||
49 | new Dictionary <UUID, int>(); | ||
50 | } | ||
51 | |||
52 | public class PrimCountModule : IPrimCountModule, INonSharedRegionModule | ||
53 | { | ||
54 | private static readonly ILog m_log = | ||
55 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | private Scene m_Scene; | ||
58 | private Dictionary<UUID, PrimCounts> m_PrimCounts = | ||
59 | new Dictionary<UUID, PrimCounts>(); | ||
60 | private Dictionary<UUID, UUID> m_OwnerMap = | ||
61 | new Dictionary<UUID, UUID>(); | ||
62 | private Dictionary<UUID, int> m_SimwideCounts = | ||
63 | new Dictionary<UUID, int>(); | ||
64 | private Dictionary<UUID, ParcelCounts> m_ParcelCounts = | ||
65 | new Dictionary<UUID, ParcelCounts>(); | ||
66 | |||
67 | // For now, a simple simwide taint to get this up. Later parcel based | ||
68 | // taint to allow recounting a parcel if only ownership has changed | ||
69 | // without recounting the whole sim. | ||
70 | private bool m_Tainted = true; | ||
71 | private Object m_TaintLock = new Object(); | ||
72 | |||
73 | public Type ReplaceableInterface | ||
74 | { | ||
75 | get { return null; } | ||
76 | } | ||
77 | |||
78 | public void Initialise(IConfigSource source) | ||
79 | { | ||
80 | } | ||
81 | |||
82 | public void AddRegion(Scene scene) | ||
83 | { | ||
84 | m_Scene = scene; | ||
85 | |||
86 | m_Scene.EventManager.OnParcelPrimCountAdd += | ||
87 | OnParcelPrimCountAdd; | ||
88 | m_Scene.EventManager.OnObjectBeingRemovedFromScene += | ||
89 | OnObjectBeingRemovedFromScene; | ||
90 | m_Scene.EventManager.OnParcelPrimCountTainted += | ||
91 | OnParcelPrimCountTainted; | ||
92 | } | ||
93 | |||
94 | public void RegionLoaded(Scene scene) | ||
95 | { | ||
96 | } | ||
97 | |||
98 | public void RemoveRegion(Scene scene) | ||
99 | { | ||
100 | } | ||
101 | |||
102 | public void Close() | ||
103 | { | ||
104 | } | ||
105 | |||
106 | public string Name | ||
107 | { | ||
108 | get { return "PrimCountModule"; } | ||
109 | } | ||
110 | |||
111 | private void OnParcelPrimCountAdd(SceneObjectGroup obj) | ||
112 | { | ||
113 | // If we're tainted already, don't bother to add. The next | ||
114 | // access will cause a recount anyway | ||
115 | lock (m_TaintLock) | ||
116 | { | ||
117 | if (!m_Tainted) | ||
118 | AddObject(obj); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | private void OnObjectBeingRemovedFromScene(SceneObjectGroup obj) | ||
123 | { | ||
124 | // Don't bother to update tainted counts | ||
125 | lock (m_TaintLock) | ||
126 | { | ||
127 | if (!m_Tainted) | ||
128 | RemoveObject(obj); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | private void OnParcelPrimCountTainted() | ||
133 | { | ||
134 | lock (m_TaintLock) | ||
135 | m_Tainted = true; | ||
136 | } | ||
137 | |||
138 | public void TaintPrimCount(ILandObject land) | ||
139 | { | ||
140 | lock (m_TaintLock) | ||
141 | m_Tainted = true; | ||
142 | } | ||
143 | |||
144 | public void TaintPrimCount(int x, int y) | ||
145 | { | ||
146 | lock (m_TaintLock) | ||
147 | m_Tainted = true; | ||
148 | } | ||
149 | |||
150 | public void TaintPrimCount() | ||
151 | { | ||
152 | lock (m_TaintLock) | ||
153 | m_Tainted = true; | ||
154 | } | ||
155 | |||
156 | // NOTE: Call under Taint Lock | ||
157 | private void AddObject(SceneObjectGroup obj) | ||
158 | { | ||
159 | if (obj.IsAttachment) | ||
160 | return; | ||
161 | if (((obj.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)) | ||
162 | return; | ||
163 | |||
164 | Vector3 pos = obj.AbsolutePosition; | ||
165 | ILandObject landObject = m_Scene.LandChannel.GetLandObject(pos.X, pos.Y); | ||
166 | LandData landData = landObject.LandData; | ||
167 | |||
168 | ParcelCounts parcelCounts; | ||
169 | if (m_ParcelCounts.TryGetValue(landData.GlobalID, out parcelCounts)) | ||
170 | { | ||
171 | UUID landOwner = landData.OwnerID; | ||
172 | int partCount = obj.Parts.Length; | ||
173 | |||
174 | m_SimwideCounts[landOwner] += partCount; | ||
175 | if (parcelCounts.Users.ContainsKey(obj.OwnerID)) | ||
176 | parcelCounts.Users[obj.OwnerID] += partCount; | ||
177 | else | ||
178 | parcelCounts.Users[obj.OwnerID] = partCount; | ||
179 | |||
180 | if (landData.IsGroupOwned) | ||
181 | { | ||
182 | if (obj.OwnerID == landData.GroupID) | ||
183 | parcelCounts.Owner += partCount; | ||
184 | else if (obj.GroupID == landData.GroupID) | ||
185 | parcelCounts.Group += partCount; | ||
186 | else | ||
187 | parcelCounts.Others += partCount; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | if (obj.OwnerID == landData.OwnerID) | ||
192 | parcelCounts.Owner += partCount; | ||
193 | else if (obj.GroupID == landData.GroupID) | ||
194 | parcelCounts.Group += partCount; | ||
195 | else | ||
196 | parcelCounts.Others += partCount; | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | |||
201 | // NOTE: Call under Taint Lock | ||
202 | private void RemoveObject(SceneObjectGroup obj) | ||
203 | { | ||
204 | } | ||
205 | |||
206 | public IPrimCounts GetPrimCounts(UUID parcelID) | ||
207 | { | ||
208 | PrimCounts primCounts; | ||
209 | |||
210 | lock (m_PrimCounts) | ||
211 | { | ||
212 | if (m_PrimCounts.TryGetValue(parcelID, out primCounts)) | ||
213 | return primCounts; | ||
214 | |||
215 | primCounts = new PrimCounts(parcelID, this); | ||
216 | m_PrimCounts[parcelID] = primCounts; | ||
217 | } | ||
218 | return primCounts; | ||
219 | } | ||
220 | |||
221 | public int GetOwnerCount(UUID parcelID) | ||
222 | { | ||
223 | lock (m_TaintLock) | ||
224 | { | ||
225 | if (m_Tainted) | ||
226 | Recount(); | ||
227 | |||
228 | ParcelCounts counts; | ||
229 | if (m_ParcelCounts.TryGetValue(parcelID, out counts)) | ||
230 | return counts.Owner; | ||
231 | } | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | public int GetGroupCount(UUID parcelID) | ||
236 | { | ||
237 | lock (m_TaintLock) | ||
238 | { | ||
239 | if (m_Tainted) | ||
240 | Recount(); | ||
241 | |||
242 | ParcelCounts counts; | ||
243 | if (m_ParcelCounts.TryGetValue(parcelID, out counts)) | ||
244 | return counts.Group; | ||
245 | } | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | public int GetOthersCount(UUID parcelID) | ||
250 | { | ||
251 | lock (m_TaintLock) | ||
252 | { | ||
253 | if (m_Tainted) | ||
254 | Recount(); | ||
255 | |||
256 | ParcelCounts counts; | ||
257 | if (m_ParcelCounts.TryGetValue(parcelID, out counts)) | ||
258 | return counts.Others; | ||
259 | } | ||
260 | return 0; | ||
261 | } | ||
262 | |||
263 | public int GetSimulatorCount(UUID parcelID) | ||
264 | { | ||
265 | lock (m_TaintLock) | ||
266 | { | ||
267 | if (m_Tainted) | ||
268 | Recount(); | ||
269 | |||
270 | UUID owner; | ||
271 | if (m_OwnerMap.TryGetValue(parcelID, out owner)) | ||
272 | { | ||
273 | int val; | ||
274 | if (m_SimwideCounts.TryGetValue(owner, out val)) | ||
275 | return val; | ||
276 | } | ||
277 | } | ||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | public int GetUserCount(UUID parcelID, UUID userID) | ||
282 | { | ||
283 | lock (m_TaintLock) | ||
284 | { | ||
285 | if (m_Tainted) | ||
286 | Recount(); | ||
287 | |||
288 | ParcelCounts counts; | ||
289 | if (m_ParcelCounts.TryGetValue(parcelID, out counts)) | ||
290 | { | ||
291 | int val; | ||
292 | if (counts.Users.TryGetValue(userID, out val)) | ||
293 | return val; | ||
294 | } | ||
295 | } | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | // NOTE: This method MUST be called while holding the taint lock! | ||
300 | private void Recount() | ||
301 | { | ||
302 | m_OwnerMap.Clear(); | ||
303 | m_SimwideCounts.Clear(); | ||
304 | m_ParcelCounts.Clear(); | ||
305 | |||
306 | List<ILandObject> land = m_Scene.LandChannel.AllParcels(); | ||
307 | |||
308 | foreach (ILandObject l in land) | ||
309 | { | ||
310 | LandData landData = l.LandData; | ||
311 | |||
312 | m_OwnerMap[landData.GlobalID] = landData.OwnerID; | ||
313 | m_SimwideCounts[landData.OwnerID] = 0; | ||
314 | m_ParcelCounts[landData.GlobalID] = new ParcelCounts(); | ||
315 | } | ||
316 | |||
317 | m_Scene.ForEachSOG(AddObject); | ||
318 | |||
319 | List<UUID> primcountKeys = new List<UUID>(m_PrimCounts.Keys); | ||
320 | foreach (UUID k in primcountKeys) | ||
321 | { | ||
322 | if (!m_OwnerMap.ContainsKey(k)) | ||
323 | m_PrimCounts.Remove(k); | ||
324 | } | ||
325 | m_Tainted = false; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | public class PrimCounts : IPrimCounts | ||
330 | { | ||
331 | private PrimCountModule m_Parent; | ||
332 | private UUID m_ParcelID; | ||
333 | private UserPrimCounts m_UserPrimCounts; | ||
334 | |||
335 | public PrimCounts (UUID parcelID, PrimCountModule parent) | ||
336 | { | ||
337 | m_ParcelID = parcelID; | ||
338 | m_Parent = parent; | ||
339 | |||
340 | m_UserPrimCounts = new UserPrimCounts(this); | ||
341 | } | ||
342 | |||
343 | public int Owner | ||
344 | { | ||
345 | get | ||
346 | { | ||
347 | return m_Parent.GetOwnerCount(m_ParcelID); | ||
348 | } | ||
349 | } | ||
350 | |||
351 | public int Group | ||
352 | { | ||
353 | get | ||
354 | { | ||
355 | return m_Parent.GetGroupCount(m_ParcelID); | ||
356 | } | ||
357 | } | ||
358 | |||
359 | public int Others | ||
360 | { | ||
361 | get | ||
362 | { | ||
363 | return m_Parent.GetOthersCount(m_ParcelID); | ||
364 | } | ||
365 | } | ||
366 | |||
367 | public int Simulator | ||
368 | { | ||
369 | get | ||
370 | { | ||
371 | return m_Parent.GetSimulatorCount(m_ParcelID); | ||
372 | } | ||
373 | } | ||
374 | |||
375 | public IUserPrimCounts Users | ||
376 | { | ||
377 | get | ||
378 | { | ||
379 | return m_UserPrimCounts; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | public int GetUserCount(UUID userID) | ||
384 | { | ||
385 | return m_Parent.GetUserCount(m_ParcelID, userID); | ||
386 | } | ||
387 | } | ||
388 | |||
389 | public class UserPrimCounts : IUserPrimCounts | ||
390 | { | ||
391 | private PrimCounts m_Parent; | ||
392 | |||
393 | public UserPrimCounts(PrimCounts parent) | ||
394 | { | ||
395 | m_Parent = parent; | ||
396 | } | ||
397 | |||
398 | public int this[UUID userID] | ||
399 | { | ||
400 | get | ||
401 | { | ||
402 | return m_Parent.GetUserCount(userID); | ||
403 | } | ||
404 | } | ||
405 | } | ||
406 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs index c65aa6a..ab6a598 100644 --- a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs +++ b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs | |||
@@ -45,8 +45,8 @@ namespace OpenSim.Region.CoreModules.World.Region | |||
45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RestartModule")] | 45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RestartModule")] |
46 | public class RestartModule : INonSharedRegionModule, IRestartModule | 46 | public class RestartModule : INonSharedRegionModule, IRestartModule |
47 | { | 47 | { |
48 | private static readonly ILog m_log = | 48 | // private static readonly ILog m_log = |
49 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 50 | ||
51 | protected Scene m_Scene; | 51 | protected Scene m_Scene; |
52 | protected Timer m_CountdownTimer = null; | 52 | protected Timer m_CountdownTimer = null; |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs index 3ee20ae..2919897 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs | |||
@@ -30,6 +30,7 @@ using System.IO; | |||
30 | using System.Text; | 30 | using System.Text; |
31 | using OpenSim.Region.Framework.Interfaces; | 31 | using OpenSim.Region.Framework.Interfaces; |
32 | using OpenSim.Region.Framework.Scenes; | 32 | using OpenSim.Region.Framework.Scenes; |
33 | using OpenSim.Framework; | ||
33 | 34 | ||
34 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | 35 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders |
35 | { | 36 | { |
@@ -53,17 +54,120 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
53 | return retval; | 54 | return retval; |
54 | } | 55 | } |
55 | 56 | ||
57 | public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) | ||
58 | { | ||
59 | TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); | ||
60 | |||
61 | FileInfo file = new FileInfo(filename); | ||
62 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
63 | BinaryReader bs = new BinaryReader(s); | ||
64 | |||
65 | bool eof = false; | ||
66 | |||
67 | int fileXPoints = 0; | ||
68 | int fileYPoints = 0; | ||
69 | |||
70 | // Terragen file | ||
71 | while (eof == false) | ||
72 | { | ||
73 | string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4)); | ||
74 | switch (tmp) | ||
75 | { | ||
76 | case "SIZE": | ||
77 | fileXPoints = bs.ReadInt16() + 1; | ||
78 | fileYPoints = fileXPoints; | ||
79 | bs.ReadInt16(); | ||
80 | break; | ||
81 | case "XPTS": | ||
82 | fileXPoints = bs.ReadInt16(); | ||
83 | bs.ReadInt16(); | ||
84 | break; | ||
85 | case "YPTS": | ||
86 | fileYPoints = bs.ReadInt16(); | ||
87 | bs.ReadInt16(); | ||
88 | break; | ||
89 | case "ALTW": | ||
90 | eof = true; | ||
91 | Int16 heightScale = bs.ReadInt16(); | ||
92 | Int16 baseHeight = bs.ReadInt16(); | ||
93 | |||
94 | int currFileYOffset = 0; | ||
95 | |||
96 | // if our region isn't on the first X section of the areas to be landscaped, then | ||
97 | // advance to our section of the file | ||
98 | while (currFileYOffset < offsetY) | ||
99 | { | ||
100 | // read a whole strip of regions | ||
101 | int heightsToRead = sectionHeight * fileXPoints; | ||
102 | bs.ReadBytes(heightsToRead * 2); // because the shorts are 2 bytes in the file | ||
103 | currFileYOffset++; | ||
104 | } | ||
105 | |||
106 | for (int y = 0; y < sectionHeight; y++) | ||
107 | { | ||
108 | int currFileXOffset = 0; | ||
109 | |||
110 | // if our region isn't the first X section of the areas to be landscaped, then | ||
111 | // advance the stream to the X start pos of our section in the file | ||
112 | // i.e. eat X upto where we start | ||
113 | while (currFileXOffset < offsetX) | ||
114 | { | ||
115 | bs.ReadBytes(sectionWidth * 2); // 2 bytes = short | ||
116 | currFileXOffset++; | ||
117 | } | ||
118 | |||
119 | // got to our X offset, so write our regions X line | ||
120 | for (int x = 0; x < sectionWidth; x++) | ||
121 | { | ||
122 | // Read a strip and continue | ||
123 | retval[x, y] = baseHeight + bs.ReadInt16() * (double)heightScale / 65536.0; | ||
124 | } | ||
125 | // record that we wrote it | ||
126 | currFileXOffset++; | ||
127 | |||
128 | // if our region isn't the last X section of the areas to be landscaped, then | ||
129 | // advance the stream to the end of this Y column | ||
130 | while (currFileXOffset < fileWidth) | ||
131 | { | ||
132 | // eat the next regions x line | ||
133 | bs.ReadBytes(sectionWidth * 2); // 2 bytes = short | ||
134 | currFileXOffset++; | ||
135 | } | ||
136 | //eat the last additional point | ||
137 | bs.ReadInt16(); | ||
138 | } | ||
139 | |||
140 | |||
141 | break; | ||
142 | default: | ||
143 | bs.ReadInt32(); | ||
144 | break; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | bs.Close(); | ||
149 | s.Close(); | ||
150 | |||
151 | return retval; | ||
152 | } | ||
153 | |||
56 | public ITerrainChannel LoadStream(Stream s) | 154 | public ITerrainChannel LoadStream(Stream s) |
57 | { | 155 | { |
58 | TerrainChannel retval = new TerrainChannel(); | 156 | |
157 | int w = (int)Constants.RegionSize; | ||
158 | int h = (int)Constants.RegionSize; | ||
159 | |||
160 | TerrainChannel retval = new TerrainChannel(w, h); | ||
59 | 161 | ||
60 | BinaryReader bs = new BinaryReader(s); | 162 | BinaryReader bs = new BinaryReader(s); |
61 | 163 | ||
62 | bool eof = false; | 164 | bool eof = false; |
63 | if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") | 165 | if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") |
64 | { | 166 | { |
65 | int w = 256; | 167 | |
66 | int h = 256; | 168 | int fileWidth = w; |
169 | int fileHeight = h; | ||
170 | |||
67 | 171 | ||
68 | // Terragen file | 172 | // Terragen file |
69 | while (eof == false) | 173 | while (eof == false) |
@@ -73,30 +177,27 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
73 | { | 177 | { |
74 | case "SIZE": | 178 | case "SIZE": |
75 | int sztmp = bs.ReadInt16() + 1; | 179 | int sztmp = bs.ReadInt16() + 1; |
76 | w = sztmp; | 180 | fileWidth = sztmp; |
77 | h = sztmp; | 181 | fileHeight = sztmp; |
78 | bs.ReadInt16(); | 182 | bs.ReadInt16(); |
79 | break; | 183 | break; |
80 | case "XPTS": | 184 | case "XPTS": |
81 | w = bs.ReadInt16(); | 185 | fileWidth = bs.ReadInt16(); |
82 | bs.ReadInt16(); | 186 | bs.ReadInt16(); |
83 | break; | 187 | break; |
84 | case "YPTS": | 188 | case "YPTS": |
85 | h = bs.ReadInt16(); | 189 | fileHeight = bs.ReadInt16(); |
86 | bs.ReadInt16(); | 190 | bs.ReadInt16(); |
87 | break; | 191 | break; |
88 | case "ALTW": | 192 | case "ALTW": |
89 | eof = true; | 193 | eof = true; |
90 | Int16 heightScale = bs.ReadInt16(); | 194 | Int16 heightScale = bs.ReadInt16(); |
91 | Int16 baseHeight = bs.ReadInt16(); | 195 | Int16 baseHeight = bs.ReadInt16(); |
92 | retval = new TerrainChannel(w, h); | 196 | for (int y = 0; y < h; y++) |
93 | int x; | ||
94 | for (x = 0; x < w; x++) | ||
95 | { | 197 | { |
96 | int y; | 198 | for (int x = 0; x < w; x++) |
97 | for (y = 0; y < h; y++) | ||
98 | { | 199 | { |
99 | retval[x, y] = baseHeight + bs.ReadInt16() * (double) heightScale / 65536.0; | 200 | retval[x, y] = baseHeight + bs.ReadInt16() * (double)heightScale / 65536.0; |
100 | } | 201 | } |
101 | } | 202 | } |
102 | break; | 203 | break; |
@@ -114,12 +215,92 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
114 | 215 | ||
115 | public void SaveFile(string filename, ITerrainChannel map) | 216 | public void SaveFile(string filename, ITerrainChannel map) |
116 | { | 217 | { |
117 | throw new NotImplementedException(); | 218 | FileInfo file = new FileInfo(filename); |
219 | FileStream s = file.Open(FileMode.Create, FileAccess.Write); | ||
220 | SaveStream(s, map); | ||
221 | |||
222 | s.Close(); | ||
118 | } | 223 | } |
119 | 224 | ||
120 | public void SaveStream(Stream stream, ITerrainChannel map) | 225 | public void SaveStream(Stream stream, ITerrainChannel map) |
121 | { | 226 | { |
122 | throw new NotImplementedException(); | 227 | BinaryWriter bs = new BinaryWriter(stream); |
228 | |||
229 | //find the max and min heights on the map | ||
230 | double heightMax = map[0,0]; | ||
231 | double heightMin = map[0,0]; | ||
232 | |||
233 | for (int y = 0; y < map.Height; y++) | ||
234 | { | ||
235 | for (int x = 0; x < map.Width; x++) | ||
236 | { | ||
237 | double current = map[x,y]; | ||
238 | if (heightMax < current) | ||
239 | heightMax = current; | ||
240 | if (heightMin > current) | ||
241 | heightMin = current; | ||
242 | } | ||
243 | } | ||
244 | |||
245 | double baseHeight = Math.Floor( (heightMax + heightMin) / 2d ); | ||
246 | |||
247 | double horizontalScale = Math.Ceiling((heightMax - heightMin)); | ||
248 | |||
249 | // if we are completely flat add 1cm range to avoid NaN divisions | ||
250 | if (horizontalScale < 0.01d) | ||
251 | horizontalScale = 0.01d; | ||
252 | |||
253 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | ||
254 | |||
255 | bs.Write(enc.GetBytes("TERRAGENTERRAIN ")); | ||
256 | |||
257 | bs.Write(enc.GetBytes("SIZE")); | ||
258 | bs.Write(Convert.ToInt16(Constants.RegionSize)); | ||
259 | bs.Write(Convert.ToInt16(0)); // necessary padding | ||
260 | |||
261 | //The XPTS and YPTS chunks are not needed for square regions | ||
262 | //but L3DT won't load the terrain file properly without them. | ||
263 | bs.Write(enc.GetBytes("XPTS")); | ||
264 | bs.Write(Convert.ToInt16(Constants.RegionSize)); | ||
265 | bs.Write(Convert.ToInt16(0)); // necessary padding | ||
266 | |||
267 | bs.Write(enc.GetBytes("YPTS")); | ||
268 | bs.Write(Convert.ToInt16(Constants.RegionSize)); | ||
269 | bs.Write(Convert.ToInt16(0)); // necessary padding | ||
270 | |||
271 | bs.Write(enc.GetBytes("SCAL")); | ||
272 | bs.Write(ToLittleEndian(1f)); //we're going to say that 1 terrain unit is 1 metre | ||
273 | bs.Write(ToLittleEndian(1f)); | ||
274 | bs.Write(ToLittleEndian(1f)); | ||
275 | |||
276 | // as we are square and not projected on a sphere then the other | ||
277 | // header blocks are not required | ||
278 | |||
279 | // now write the elevation data | ||
280 | bs.Write(enc.GetBytes("ALTW")); | ||
281 | bs.Write(Convert.ToInt16(horizontalScale)); // range between max and min | ||
282 | bs.Write(Convert.ToInt16(baseHeight)); // base height or mid point | ||
283 | |||
284 | for (int y = 0; y < map.Height; y++) | ||
285 | { | ||
286 | for (int x = 0; x < map.Width; x++) | ||
287 | { | ||
288 | float elevation = (float)((map[x,y] - baseHeight) * 65536 ) / (float)horizontalScale; // see LoadStream for inverse | ||
289 | |||
290 | // clamp rounding issues | ||
291 | if (elevation > Int16.MaxValue) | ||
292 | elevation = Int16.MaxValue; | ||
293 | else if (elevation < Int16.MinValue) | ||
294 | elevation = Int16.MinValue; | ||
295 | |||
296 | bs.Write(Convert.ToInt16(elevation)); | ||
297 | } | ||
298 | } | ||
299 | |||
300 | //This is only necessary for older versions of Terragen. | ||
301 | bs.Write(enc.GetBytes("EOF ")); | ||
302 | |||
303 | bs.Close(); | ||
123 | } | 304 | } |
124 | 305 | ||
125 | public string FileExtension | 306 | public string FileExtension |
@@ -127,16 +308,34 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
127 | get { return ".ter"; } | 308 | get { return ".ter"; } |
128 | } | 309 | } |
129 | 310 | ||
130 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
131 | { | ||
132 | throw new NotImplementedException(); | ||
133 | } | ||
134 | |||
135 | #endregion | 311 | #endregion |
136 | 312 | ||
137 | public override string ToString() | 313 | public override string ToString() |
138 | { | 314 | { |
139 | return "Terragen"; | 315 | return "Terragen"; |
140 | } | 316 | } |
317 | |||
318 | /// <summary> | ||
319 | /// terragen SCAL floats need to be written intel ordered regardless of | ||
320 | /// big or little endian system | ||
321 | /// </summary> | ||
322 | /// <param name="number"></param> | ||
323 | /// <returns></returns> | ||
324 | private byte[] ToLittleEndian( float number) | ||
325 | { | ||
326 | byte[] retVal = BitConverter.GetBytes(number); | ||
327 | if (BitConverter.IsLittleEndian == false) | ||
328 | { | ||
329 | byte[] tmp = new byte[4]; | ||
330 | for (int i = 0; i < 4; i++) | ||
331 | { | ||
332 | tmp[i] = retVal[3 - i]; | ||
333 | } | ||
334 | retVal = tmp; | ||
335 | |||
336 | } | ||
337 | return retVal ; | ||
338 | } | ||
339 | |||
141 | } | 340 | } |
142 | } | 341 | } |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index 25d73c2..8a79d78 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -131,7 +131,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
131 | m_scene.EventManager.OnNewClient += EventManager_OnNewClient; | 131 | m_scene.EventManager.OnNewClient += EventManager_OnNewClient; |
132 | m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | 132 | m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; |
133 | m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; | 133 | m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; |
134 | InstallInterfaces(); | ||
135 | } | 134 | } |
136 | 135 | ||
137 | InstallDefaultEffects(); | 136 | InstallDefaultEffects(); |
@@ -140,6 +139,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
140 | 139 | ||
141 | public void RegionLoaded(Scene scene) | 140 | public void RegionLoaded(Scene scene) |
142 | { | 141 | { |
142 | //Do this here to give file loaders time to initialize and | ||
143 | //register their supported file extensions and file formats. | ||
144 | InstallInterfaces(); | ||
143 | } | 145 | } |
144 | 146 | ||
145 | public void RemoveRegion(Scene scene) | 147 | public void RemoveRegion(Scene scene) |
@@ -1082,8 +1084,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
1082 | { | 1084 | { |
1083 | // Load / Save | 1085 | // Load / Save |
1084 | string supportedFileExtensions = ""; | 1086 | string supportedFileExtensions = ""; |
1087 | string supportedFilesSeparator = ""; | ||
1085 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | 1088 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) |
1086 | supportedFileExtensions += " " + loader.Key + " (" + loader.Value + ")"; | 1089 | { |
1090 | supportedFileExtensions += supportedFilesSeparator + loader.Key + " (" + loader.Value + ")"; | ||
1091 | supportedFilesSeparator = ", "; | ||
1092 | } | ||
1087 | 1093 | ||
1088 | Command loadFromFileCommand = | 1094 | Command loadFromFileCommand = |
1089 | new Command("load", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadFile, "Loads a terrain from a specified file."); | 1095 | new Command("load", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadFile, "Loads a terrain from a specified file."); |