* refactor: Move LazySaveGeneratedMapTile from scene to WorldMapModule

0.6.3-post-fixes
Justin Clarke Casey 2009-02-13 17:40:52 +00:00
parent 3b147f814f
commit 92232663e4
2 changed files with 65 additions and 57 deletions

View File

@ -50,7 +50,7 @@ using OSDMap=OpenMetaverse.StructuredData.OSDMap;
namespace OpenSim.Region.CoreModules.World.WorldMap namespace OpenSim.Region.CoreModules.World.WorldMap
{ {
public class WorldMapModule : IRegionModule public class WorldMapModule : IRegionModule, IWorldMapModule
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -90,6 +90,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
m_scene = scene; m_scene = scene;
m_scene.RegisterModuleInterface<IWorldMapModule>(this);
m_scene.AddCommand( m_scene.AddCommand(
this, "export-map", this, "export-map",
"export-map [<path>]", "export-map [<path>]",
@ -936,6 +938,64 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
return responsemap; 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) private void MakeRootAgent(ScenePresence avatar)
{ {
// You may ask, why this is in a threadpool to start with.. // You may ask, why this is in a threadpool to start with..

View File

@ -1129,64 +1129,12 @@ namespace OpenSim.Region.Framework.Scenes
byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png"); byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png");
if (data != null) if (data != null)
LazySaveGeneratedMaptile(data, temporary);
}
public void LazySaveGeneratedMaptile(byte[] data, bool temporary)
{ {
// Overwrites the local Asset cache with new maptile data IWorldMapModule mapModule = RequestModuleInterface<IWorldMapModule>();
// 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 if (mapModule != null)
// map tile while protecting the (grid) asset database from bloat caused by a new asset each mapModule.LazySaveGeneratedMaptile(data, temporary);
// 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)
{
}
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 #endregion