aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Scene.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-08-17 18:59:58 +0000
committerTeravus Ovares2008-08-17 18:59:58 +0000
commit0683a07081802105cbc40ca9d75c26e135342f3e (patch)
tree93a4fd544dab170d8b91c1c3c36bdaf936908ee3 /OpenSim/Region/Environment/Scenes/Scene.cs
parentAdd the IInventoryModule interface and a sample method call (diff)
downloadopensim-SC_OLD-0683a07081802105cbc40ca9d75c26e135342f3e.zip
opensim-SC_OLD-0683a07081802105cbc40ca9d75c26e135342f3e.tar.gz
opensim-SC_OLD-0683a07081802105cbc40ca9d75c26e135342f3e.tar.bz2
opensim-SC_OLD-0683a07081802105cbc40ca9d75c26e135342f3e.tar.xz
* Turned on the MapImageModule as opposed to the code in Scene for generating the map image. Copied the code in Scene into the MapImageModule, made a few tweaks to get it to work with the module's interface.
* Refactored a few things in Scene to make maptile saving easier to understand. * Added comments to describe the 'clever code' assetcache update without the gridasset being updated so as to lessen possible confusion in patches in the future. * If the MapImageModule isn't loaded, default to the code in Scene still.
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Scene.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs166
1 files changed, 69 insertions, 97 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index e060f3d..e8a8a78 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -1023,6 +1023,8 @@ namespace OpenSim.Region.Environment.Scenes
1023 1023
1024 if (terrain == null) 1024 if (terrain == null)
1025 { 1025 {
1026 #region Fallback default maptile generation
1027
1026 int tc = System.Environment.TickCount; 1028 int tc = System.Environment.TickCount;
1027 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain"); 1029 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain");
1028 Bitmap mapbmp = new Bitmap(256, 256); 1030 Bitmap mapbmp = new Bitmap(256, 256);
@@ -1053,13 +1055,13 @@ namespace OpenSim.Region.Environment.Scenes
1053 } 1055 }
1054 1056
1055 float mid = (high + low) * 0.5f; 1057 float mid = (high + low) * 0.5f;
1056 1058
1057 // temporary initializer 1059 // temporary initializer
1058 float hfvalue = (float)m_regInfo.RegionSettings.WaterHeight; 1060 float hfvalue = (float)m_regInfo.RegionSettings.WaterHeight;
1059 float hfvaluecompare = hfvalue; 1061 float hfvaluecompare = hfvalue;
1060 float hfdiff = hfvalue; 1062 float hfdiff = hfvalue;
1061 int hfdiffi = 0; 1063 int hfdiffi = 0;
1062 1064
1063 1065
1064 for (int x = 0; x < 256; x++) 1066 for (int x = 0; x < 256; x++)
1065 { 1067 {
@@ -1088,7 +1090,7 @@ namespace OpenSim.Region.Environment.Scenes
1088 1090
1089 if (heightvalue > (float)m_regInfo.RegionSettings.WaterHeight) 1091 if (heightvalue > (float)m_regInfo.RegionSettings.WaterHeight)
1090 { 1092 {
1091 1093
1092 // scale height value 1094 // scale height value
1093 heightvalue = low + mid * (heightvalue - low) / mid; 1095 heightvalue = low + mid * (heightvalue - low) / mid;
1094 1096
@@ -1115,7 +1117,7 @@ namespace OpenSim.Region.Environment.Scenes
1115 { 1117 {
1116 hfvalue = (float)hm[x, y]; 1118 hfvalue = (float)hm[x, y];
1117 hfvaluecompare = (float)hm[x - 1, y - 1]; 1119 hfvaluecompare = (float)hm[x - 1, y - 1];
1118 1120
1119 if (Single.IsInfinity(hfvalue) || Single.IsNaN(hfvalue)) 1121 if (Single.IsInfinity(hfvalue) || Single.IsNaN(hfvalue))
1120 hfvalue = 0; 1122 hfvalue = 0;
1121 1123
@@ -1133,7 +1135,7 @@ namespace OpenSim.Region.Environment.Scenes
1133 // We have to desaturate and blacken the land at the same time 1135 // We have to desaturate and blacken the land at the same time
1134 // we use floats, colors use bytes, so shrink are space down to 1136 // we use floats, colors use bytes, so shrink are space down to
1135 // 0-255 1137 // 0-255
1136 1138
1137 1139
1138 try 1140 try
1139 { 1141 {
@@ -1148,7 +1150,7 @@ namespace OpenSim.Region.Environment.Scenes
1148 m_log.Debug("[MAPTILE]: Shadow failed at value: " + hfdiff.ToString()); 1150 m_log.Debug("[MAPTILE]: Shadow failed at value: " + hfdiff.ToString());
1149 ShadowDebugContinue = false; 1151 ShadowDebugContinue = false;
1150 } 1152 }
1151 1153
1152 if (ShadowDebugContinue) 1154 if (ShadowDebugContinue)
1153 { 1155 {
1154 if ((256 - y) - 1 > 0) 1156 if ((256 - y) - 1 > 0)
@@ -1164,13 +1166,13 @@ namespace OpenSim.Region.Environment.Scenes
1164 mapbmp.SetPixel(x - 1, (256 - y) - 1, Shade); 1166 mapbmp.SetPixel(x - 1, (256 - y) - 1, Shade);
1165 } 1167 }
1166 } 1168 }
1167 1169
1168 1170
1169 } 1171 }
1170 1172
1171 } 1173 }
1172 1174
1173 1175
1174 1176
1175 1177
1176 } 1178 }
@@ -1178,7 +1180,7 @@ namespace OpenSim.Region.Environment.Scenes
1178 { 1180 {
1179 if (!terraincorruptedwarningsaid) 1181 if (!terraincorruptedwarningsaid)
1180 { 1182 {
1181 m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level",RegionInfo.RegionName); 1183 m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", RegionInfo.RegionName);
1182 terraincorruptedwarningsaid = true; 1184 terraincorruptedwarningsaid = true;
1183 } 1185 }
1184 Color black = Color.Black; 1186 Color black = Color.Black;
@@ -1262,7 +1264,7 @@ namespace OpenSim.Region.Environment.Scenes
1262 if (part == null) 1264 if (part == null)
1263 continue; 1265 continue;
1264 1266
1265 1267
1266 // Draw if the object is at least 1 meter wide in any direction 1268 // Draw if the object is at least 1 meter wide in any direction
1267 if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) 1269 if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f)
1268 { 1270 {
@@ -1278,8 +1280,8 @@ namespace OpenSim.Region.Environment.Scenes
1278 1280
1279 if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree) 1281 if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree)
1280 continue; // eliminates trees from this since we don't really have a good tree representation 1282 continue; // eliminates trees from this since we don't really have a good tree representation
1281 // if you want tree blocks on the map comment the above line and uncomment the below line 1283 // if you want tree blocks on the map comment the above line and uncomment the below line
1282 //mapdotspot = Color.PaleGreen; 1284 //mapdotspot = Color.PaleGreen;
1283 1285
1284 if (part.Shape.Textures == null) 1286 if (part.Shape.Textures == null)
1285 continue; 1287 continue;
@@ -1410,106 +1412,76 @@ namespace OpenSim.Region.Environment.Scenes
1410 return; 1412 return;
1411 } 1413 }
1412 1414
1413 LLUUID lastMapRegionUUID = m_regInfo.lastMapUUID; 1415 LazySaveGeneratedMaptile(data,temporary);
1414 1416
1415 int lastMapRefresh = 0; 1417 #endregion
1416 int twoDays = 172800; 1418 }
1417 int RefreshSeconds = twoDays; 1419 else
1418 1420 {
1419 try 1421 // Use the module to generate the maptile.
1420 { 1422 byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png");
1421 lastMapRefresh = Convert.ToInt32(m_regInfo.lastMapRefresh); 1423 if (data != null)
1422 }
1423 catch (ArgumentException)
1424 {
1425 }
1426 catch (FormatException)
1427 {
1428 }
1429 catch (OverflowException)
1430 { 1424 {
1425 LazySaveGeneratedMaptile(data,temporary);
1431 } 1426 }
1427 }
1428 }
1429 public void LazySaveGeneratedMaptile(byte[] data, bool temporary)
1430 {
1431 // Overwrites the local Asset cache with new maptile data
1432 // Assets are single write, this causes the asset server to ignore this update,
1433 // but the local asset cache does not
1432 1434
1433 LLUUID TerrainImageLLUUID = LLUUID.Random(); 1435 // this is on purpose! The net result of this is the region always has the most up to date
1436 // map tile while protecting the (grid) asset database from bloat caused by a new asset each
1437 // time a mapimage is generated!
1438
1439 LLUUID lastMapRegionUUID = m_regInfo.lastMapUUID;
1434 1440
1435 if (lastMapRegionUUID == LLUUID.Zero || (lastMapRefresh + RefreshSeconds) < Util.UnixTimeSinceEpoch()) 1441 int lastMapRefresh = 0;
1436 { 1442 int twoDays = 172800;
1437 m_regInfo.SaveLastMapUUID(TerrainImageLLUUID); 1443 int RefreshSeconds = twoDays;
1438 1444
1439 m_log.Warn("[MAPTILE]: STORING MAPTILE IMAGE"); 1445 try
1440 //Extra protection.. probably not needed. 1446 {
1441 } 1447 lastMapRefresh = Convert.ToInt32(m_regInfo.lastMapRefresh);
1442 else 1448 }
1443 { 1449 catch (ArgumentException)
1444 TerrainImageLLUUID = lastMapRegionUUID; 1450 {
1445 m_log.Warn("[MAPTILE]: REUSING OLD MAPTILE IMAGE ID"); 1451 }
1446 } 1452 catch (FormatException)
1453 {
1454 }
1455 catch (OverflowException)
1456 {
1457 }
1447 1458
1448 m_regInfo.RegionSettings.TerrainImageID = TerrainImageLLUUID; 1459 LLUUID TerrainImageLLUUID = LLUUID.Random();
1449 1460
1450 AssetBase asset = new AssetBase(); 1461 if (lastMapRegionUUID == LLUUID.Zero || (lastMapRefresh + RefreshSeconds) < Util.UnixTimeSinceEpoch())
1451 asset.FullID = m_regInfo.RegionSettings.TerrainImageID; 1462 {
1452 asset.Data = data; 1463 m_regInfo.SaveLastMapUUID(TerrainImageLLUUID);
1453 asset.Name = "terrainImage_" + m_regInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString();
1454 asset.Description = RegionInfo.RegionName;
1455 1464
1456 asset.Type = 0; 1465 m_log.Warn("[MAPTILE]: STORING MAPTILE IMAGE");
1457 asset.Temporary = temporary;
1458 AssetCache.AddAsset(asset);
1459 } 1466 }
1460 else 1467 else
1461 { 1468 {
1462 byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png"); 1469 TerrainImageLLUUID = lastMapRegionUUID;
1463 if (data != null) 1470 m_log.Warn("[MAPTILE]: REUSING OLD MAPTILE IMAGE ID");
1464 { 1471 }
1465 LLUUID lastMapRegionUUID = m_regInfo.lastMapUUID;
1466
1467 int lastMapRefresh = 0;
1468 int twoDays = 172800;
1469 int RefreshSeconds = twoDays;
1470
1471 try
1472 {
1473 lastMapRefresh = Convert.ToInt32(m_regInfo.lastMapRefresh);
1474 }
1475 catch (ArgumentException)
1476 {
1477 }
1478 catch (FormatException)
1479 {
1480 }
1481 catch (OverflowException)
1482 {
1483 }
1484
1485 LLUUID TerrainImageLLUUID = LLUUID.Random();
1486
1487 if (lastMapRegionUUID == LLUUID.Zero || (lastMapRefresh + RefreshSeconds) < Util.UnixTimeSinceEpoch())
1488 {
1489 m_regInfo.SaveLastMapUUID(TerrainImageLLUUID);
1490 1472
1491 //m_log.Warn(terrainImageID); 1473 m_regInfo.RegionSettings.TerrainImageID = TerrainImageLLUUID;
1492 //Extra protection.. probably not needed.
1493 }
1494 else
1495 {
1496 TerrainImageLLUUID = lastMapRegionUUID;
1497 }
1498 1474
1499 m_regInfo.RegionSettings.TerrainImageID = TerrainImageLLUUID; 1475 AssetBase asset = new AssetBase();
1476 asset.FullID = m_regInfo.RegionSettings.TerrainImageID;
1477 asset.Data = data;
1478 asset.Name = "terrainImage_" + m_regInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString();
1479 asset.Description = RegionInfo.RegionName;
1500 1480
1501 AssetBase asset = new AssetBase(); 1481 asset.Type = 0;
1502 asset.FullID = m_regInfo.RegionSettings.TerrainImageID; 1482 asset.Temporary = temporary;
1503 asset.Data = data; 1483 AssetCache.AddAsset(asset);
1504 asset.Name = "terrainImage_" + m_regInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString();
1505 asset.Description = RegionInfo.RegionName;
1506 asset.Type = 0;
1507 asset.Temporary = temporary;
1508 AssetCache.AddAsset(asset);
1509 }
1510 }
1511 } 1484 }
1512
1513 #endregion 1485 #endregion
1514 1486
1515 #region Load Land 1487 #region Load Land