From 92232663e4878d5a1f74489ba9fcfd418a10990e Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 13 Feb 2009 17:40:52 +0000 Subject: * refactor: Move LazySaveGeneratedMapTile from scene to WorldMapModule --- .../CoreModules/World/WorldMap/WorldMapModule.cs | 62 +++++++++++++++++++++- OpenSim/Region/Framework/Scenes/Scene.cs | 60 ++------------------- 2 files changed, 65 insertions(+), 57 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index 9f5277b..9355374 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -50,7 +50,7 @@ using OSDMap=OpenMetaverse.StructuredData.OSDMap; namespace OpenSim.Region.CoreModules.World.WorldMap { - public class WorldMapModule : IRegionModule + public class WorldMapModule : IRegionModule, IWorldMapModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -89,6 +89,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap return; m_scene = scene; + + m_scene.RegisterModuleInterface(this); m_scene.AddCommand( this, "export-map", @@ -935,6 +937,64 @@ namespace OpenSim.Region.CoreModules.World.WorldMap } return responsemap; } + + public void LazySaveGeneratedMaptile(byte[] data, bool temporary) + { + // Overwrites the local Asset cache with new maptile data + // Assets are single write, this causes the asset server to ignore this update, + // but the local asset cache does not + + // this is on purpose! The net result of this is the region always has the most up to date + // map tile while protecting the (grid) asset database from bloat caused by a new asset each + // time a mapimage is generated! + + UUID lastMapRegionUUID = m_scene.RegionInfo.lastMapUUID; + + int lastMapRefresh = 0; + int twoDays = 172800; + int RefreshSeconds = twoDays; + + try + { + lastMapRefresh = Convert.ToInt32(m_scene.RegionInfo.lastMapRefresh); + } + catch (ArgumentException) + { + } + catch (FormatException) + { + } + catch (OverflowException) + { + } + + UUID TerrainImageUUID = UUID.Random(); + + if (lastMapRegionUUID == UUID.Zero || (lastMapRefresh + RefreshSeconds) < Util.UnixTimeSinceEpoch()) + { + m_scene.RegionInfo.SaveLastMapUUID(TerrainImageUUID); + + m_log.Debug("[MAPTILE]: STORING MAPTILE IMAGE"); + } + else + { + TerrainImageUUID = lastMapRegionUUID; + m_log.Debug("[MAPTILE]: REUSING OLD MAPTILE IMAGE ID"); + } + + m_scene.RegionInfo.RegionSettings.TerrainImageID = TerrainImageUUID; + + AssetBase asset = new AssetBase(); + asset.Metadata.FullID = m_scene.RegionInfo.RegionSettings.TerrainImageID; + asset.Data = data; + asset.Metadata.Name + = "terrainImage_" + m_scene.RegionInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString(); + asset.Metadata.Description = m_scene.RegionInfo.RegionName; + + asset.Metadata.Type = 0; + asset.Metadata.Temporary = temporary; + m_scene.CommsManager.AssetCache.AddAsset(asset); + } private void MakeRootAgent(ScenePresence avatar) { diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ebf5a06..9cf181b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1129,64 +1129,12 @@ namespace OpenSim.Region.Framework.Scenes byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png"); if (data != null) - LazySaveGeneratedMaptile(data, temporary); - } - - public void LazySaveGeneratedMaptile(byte[] data, bool temporary) - { - // Overwrites the local Asset cache with new maptile data - // Assets are single write, this causes the asset server to ignore this update, - // but the local asset cache does not - - // this is on purpose! The net result of this is the region always has the most up to date - // map tile while protecting the (grid) asset database from bloat caused by a new asset each - // time a mapimage is generated! - - UUID lastMapRegionUUID = m_regInfo.lastMapUUID; - - int lastMapRefresh = 0; - int twoDays = 172800; - int RefreshSeconds = twoDays; - - try - { - lastMapRefresh = Convert.ToInt32(m_regInfo.lastMapRefresh); - } - catch (ArgumentException) { + IWorldMapModule mapModule = RequestModuleInterface(); + + if (mapModule != null) + mapModule.LazySaveGeneratedMaptile(data, temporary); } - catch (FormatException) - { - } - catch (OverflowException) - { - } - - UUID TerrainImageUUID = UUID.Random(); - - if (lastMapRegionUUID == UUID.Zero || (lastMapRefresh + RefreshSeconds) < Util.UnixTimeSinceEpoch()) - { - m_regInfo.SaveLastMapUUID(TerrainImageUUID); - - m_log.Warn("[MAPTILE]: STORING MAPTILE IMAGE"); - } - else - { - TerrainImageUUID = lastMapRegionUUID; - m_log.Warn("[MAPTILE]: REUSING OLD MAPTILE IMAGE ID"); - } - - m_regInfo.RegionSettings.TerrainImageID = TerrainImageUUID; - - AssetBase asset = new AssetBase(); - asset.Metadata.FullID = m_regInfo.RegionSettings.TerrainImageID; - asset.Data = data; - asset.Metadata.Name = "terrainImage_" + m_regInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString(); - asset.Metadata.Description = RegionInfo.RegionName; - - asset.Metadata.Type = 0; - asset.Metadata.Temporary = temporary; - AssetCache.AddAsset(asset); } #endregion -- cgit v1.1