From cf61c74e90324e07cb4b15f9c597fef00c047c75 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 24 Mar 2012 02:16:44 +0000
Subject: Give feedback when "terrain save-tile" is not successfully invoked.
---
.../CoreModules/World/Terrain/ITerrainLoader.cs | 15 +++++
.../CoreModules/World/Terrain/TerrainModule.cs | 67 ++++++++++++----------
2 files changed, 52 insertions(+), 30 deletions(-)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs
index 7237f90..d407617 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs
@@ -38,6 +38,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain
ITerrainChannel LoadStream(Stream stream);
void SaveFile(string filename, ITerrainChannel map);
void SaveStream(Stream stream, ITerrainChannel map);
+
+ ///
+ /// Save a number of map tiles to a single big image file.
+ ///
+ ///
+ /// If the image file already exists then the tiles saved will replace those already in the file - other tiles
+ /// will be untouched.
+ ///
+ /// The terrain file to save
+ /// The map x co-ordinate at which to begin the save.
+ /// The may y co-ordinate at which to begin the save.
+ /// The number of tiles to save along the X axis.
+ /// The number of tiles to save along the Y axis.
+ /// The width of a map tile.
+ /// The height of a map tile.
void SaveFile(ITerrainChannel map, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY);
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 9cd8f2b..7c5ea29 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -561,49 +561,56 @@ namespace OpenSim.Region.CoreModules.World.Terrain
}
///
- /// Saves the terrain to a larger terrain file.
+ /// Save a number of map tiles to a single big image file.
///
+ ///
+ /// If the image file already exists then the tiles saved will replace those already in the file - other tiles
+ /// will be untouched.
+ ///
/// The terrain file to save
- /// The width of the file in units
- /// The height of the file in units
- /// Where to begin our slice
- /// Where to begin our slice
+ /// The number of tiles to save along the X axis.
+ /// The number of tiles to save along the Y axis.
+ /// The map x co-ordinate at which to begin the save.
+ /// The may y co-ordinate at which to begin the save.
public void SaveToFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
{
int offsetX = (int)m_scene.RegionInfo.RegionLocX - fileStartX;
int offsetY = (int)m_scene.RegionInfo.RegionLocY - fileStartY;
- if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight)
+ if (offsetX < 0 || offsetX >= fileWidth || offsetY < 0 || offsetY >= fileHeight)
{
- // this region is included in the tile request
- foreach (KeyValuePair loader in m_loaders)
+ MainConsole.Instance.OutputFormat(
+ "ERROR: file width + minimum X tile and file height + minimum Y tile must incorporate the current region at ({0},{1}). File width {2} from {3} and file height {4} from {5} does not.",
+ m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, fileWidth, fileStartX, fileHeight, fileStartY);
+
+ return;
+ }
+
+ // this region is included in the tile request
+ foreach (KeyValuePair loader in m_loaders)
+ {
+ if (filename.EndsWith(loader.Key))
{
- if (filename.EndsWith(loader.Key))
+ lock (m_scene)
{
- lock (m_scene)
- {
- loader.Value.SaveFile(m_channel, filename, offsetX, offsetY,
- fileWidth, fileHeight,
- (int)Constants.RegionSize,
- (int)Constants.RegionSize);
-
- m_log.InfoFormat("[TERRAIN]: Saved terrain from {0} to {1}", m_scene.RegionInfo.RegionName, filename);
- }
-
- return;
+ loader.Value.SaveFile(m_channel, filename, offsetX, offsetY,
+ fileWidth, fileHeight,
+ (int)Constants.RegionSize,
+ (int)Constants.RegionSize);
+
+ MainConsole.Instance.OutputFormat(
+ "Saved terrain from ({0},{1}) to ({2},{3}) from {4} to {5}",
+ fileStartX, fileStartY, fileStartX + fileWidth - 1, fileStartY + fileHeight - 1,
+ m_scene.RegionInfo.RegionName, filename);
}
+
+ return;
}
-
- m_log.ErrorFormat(
- "[TERRAIN]: Could not save terrain from {0} to {1}. Valid file extensions are {2}",
- m_scene.RegionInfo.RegionName, filename, m_supportedFileExtensions);
}
-// else
-// {
-// m_log.ErrorFormat(
-// "[TERRAIN]: Could not save terrain from {0} to {1}. {2} {3} {4} {5} {6} {7}",
-// m_scene.RegionInfo.RegionName, filename, fileWidth, fileHeight, fileStartX, fileStartY, offsetX, offsetY);
-// }
+
+ MainConsole.Instance.OutputFormat(
+ "ERROR: Could not save terrain from {0} to {1}. Valid file extensions are {2}",
+ m_scene.RegionInfo.RegionName, filename, m_supportedFileExtensions);
}
///
--
cgit v1.1
From f53c6b25940a51fce208b3dae21fad49ab8d1efe Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 24 Mar 2012 02:30:21 +0000
Subject: Use system provided temporary file in "terrain save-tile" to avoid
problems with drive letters on windows
Thanks to Garmin Kawaguichi for picking up on this and providing an initial solution (which I adapted).
---
.../CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index 21a9999..58925fd 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -132,13 +132,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
{
// We need to do this because:
// "Saving the image to the same file it was constructed from is not allowed and throws an exception."
- string tempName = offsetX + "_ " + offsetY + "_" + filename;
+ string tempName = Path.GetTempFileName();
Bitmap entireBitmap = null;
Bitmap thisBitmap = null;
if (File.Exists(filename))
{
- File.Copy(filename, tempName);
+ File.Copy(filename, tempName, true);
entireBitmap = new Bitmap(tempName);
if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY)
{
@@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
}
thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
- Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
+// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
for (int x = 0; x < regionSizeX; x++)
for (int y = 0; y < regionSizeY; y++)
entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
--
cgit v1.1
From f03c3c062e7829309d76ac76d5d2b2e7bc8b62dc Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 24 Mar 2012 02:41:45 +0000
Subject: Hack example on to "terrain save-tile" extended help.
Thanks to Garmin Kawaguichi for the initially suggested text.
---
OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'OpenSim/Region/CoreModules')
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 7c5ea29..17e9737 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -1199,6 +1199,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
"Integer");
saveToTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file",
"Integer");
+ saveToTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first tile on the file\n"
+ + "= Example =\n"
+ + "To save a PNG file for a set of map tiles 2 regions wide and 3 regions high from map co-ordinate (9910,10234)\n"
+ + " # terrain save-tile ST06.png 2 3 9910 10234\n",
+ "Integer");
+
// Terrain adjustments
Command fillRegionCommand =
new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value.");
--
cgit v1.1