diff options
Diffstat (limited to '')
7 files changed, 132 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs index d6fa093..21a9999 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs | |||
@@ -124,6 +124,52 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
124 | colours.Save(stream, ImageFormat.Png); | 124 | colours.Save(stream, ImageFormat.Png); |
125 | } | 125 | } |
126 | 126 | ||
127 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, | ||
128 | int offsetX, int offsetY, | ||
129 | int fileWidth, int fileHeight, | ||
130 | int regionSizeX, int regionSizeY) | ||
131 | |||
132 | { | ||
133 | // We need to do this because: | ||
134 | // "Saving the image to the same file it was constructed from is not allowed and throws an exception." | ||
135 | string tempName = offsetX + "_ " + offsetY + "_" + filename; | ||
136 | |||
137 | Bitmap entireBitmap = null; | ||
138 | Bitmap thisBitmap = null; | ||
139 | if (File.Exists(filename)) | ||
140 | { | ||
141 | File.Copy(filename, tempName); | ||
142 | entireBitmap = new Bitmap(tempName); | ||
143 | if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY) | ||
144 | { | ||
145 | // old file, let's overwrite it | ||
146 | entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); | ||
147 | } | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); | ||
152 | } | ||
153 | |||
154 | thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); | ||
155 | Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); | ||
156 | for (int x = 0; x < regionSizeX; x++) | ||
157 | for (int y = 0; y < regionSizeY; y++) | ||
158 | entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); | ||
159 | |||
160 | Save(entireBitmap, filename); | ||
161 | thisBitmap.Dispose(); | ||
162 | entireBitmap.Dispose(); | ||
163 | |||
164 | if (File.Exists(tempName)) | ||
165 | File.Delete(tempName); | ||
166 | } | ||
167 | |||
168 | protected virtual void Save(Bitmap bmp, string filename) | ||
169 | { | ||
170 | bmp.Save(filename, ImageFormat.Png); | ||
171 | } | ||
172 | |||
127 | #endregion | 173 | #endregion |
128 | 174 | ||
129 | public override string ToString() | 175 | public override string ToString() |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs index 8667607..1a0d8ec 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs | |||
@@ -76,6 +76,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
76 | colours.Save(stream, ImageFormat.Jpeg); | 76 | colours.Save(stream, ImageFormat.Jpeg); |
77 | } | 77 | } |
78 | 78 | ||
79 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, | ||
80 | int offsetX, int offsetY, | ||
81 | int fileWidth, int fileHeight, | ||
82 | int regionSizeX, int regionSizeY) | ||
83 | { | ||
84 | throw new System.Exception("Not Implemented"); | ||
85 | } | ||
86 | |||
79 | #endregion | 87 | #endregion |
80 | 88 | ||
81 | public override string ToString() | 89 | public override string ToString() |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs index a70ef13..fad7641 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs | |||
@@ -240,6 +240,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
240 | get { return ".raw"; } | 240 | get { return ".raw"; } |
241 | } | 241 | } |
242 | 242 | ||
243 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, | ||
244 | int offsetX, int offsetY, | ||
245 | int fileWidth, int fileHeight, | ||
246 | int regionSizeX, int regionSizeY) | ||
247 | { | ||
248 | throw new System.Exception("Not Implemented"); | ||
249 | } | ||
250 | |||
243 | #endregion | 251 | #endregion |
244 | 252 | ||
245 | public override string ToString() | 253 | public override string ToString() |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs index 3c76665..ba073ca 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs | |||
@@ -160,6 +160,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
160 | bs.Close(); | 160 | bs.Close(); |
161 | } | 161 | } |
162 | 162 | ||
163 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, | ||
164 | int offsetX, int offsetY, | ||
165 | int fileWidth, int fileHeight, | ||
166 | int regionSizeX, int regionSizeY) | ||
167 | { | ||
168 | throw new System.Exception("Not Implemented"); | ||
169 | } | ||
163 | #endregion | 170 | #endregion |
164 | 171 | ||
165 | public override string ToString() | 172 | public override string ToString() |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs index 2919897..2f37d9d 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs | |||
@@ -308,6 +308,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
308 | get { return ".ter"; } | 308 | get { return ".ter"; } |
309 | } | 309 | } |
310 | 310 | ||
311 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, | ||
312 | int offsetX, int offsetY, | ||
313 | int fileWidth, int fileHeight, | ||
314 | int regionSizeX, int regionSizeY) | ||
315 | { | ||
316 | throw new System.Exception("Not Implemented"); | ||
317 | } | ||
318 | |||
311 | #endregion | 319 | #endregion |
312 | 320 | ||
313 | public override string ToString() | 321 | public override string ToString() |
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs index 7403281..7237f90 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs | |||
@@ -38,5 +38,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
38 | ITerrainChannel LoadStream(Stream stream); | 38 | ITerrainChannel LoadStream(Stream stream); |
39 | void SaveFile(string filename, ITerrainChannel map); | 39 | void SaveFile(string filename, ITerrainChannel map); |
40 | void SaveStream(Stream stream, ITerrainChannel map); | 40 | void SaveStream(Stream stream, ITerrainChannel map); |
41 | void SaveFile(ITerrainChannel map, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY); | ||
41 | } | 42 | } |
42 | } \ No newline at end of file | 43 | } \ 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 8a79d78..9c7b2fa 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -541,6 +541,39 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
541 | } | 541 | } |
542 | 542 | ||
543 | /// <summary> | 543 | /// <summary> |
544 | /// Saves the terrain to a larger terrain file. | ||
545 | /// </summary> | ||
546 | /// <param name="filename">The terrain file to save</param> | ||
547 | /// <param name="fileWidth">The width of the file in units</param> | ||
548 | /// <param name="fileHeight">The height of the file in units</param> | ||
549 | /// <param name="fileStartX">Where to begin our slice</param> | ||
550 | /// <param name="fileStartY">Where to begin our slice</param> | ||
551 | public void SaveToFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) | ||
552 | { | ||
553 | int offsetX = (int)m_scene.RegionInfo.RegionLocX - fileStartX; | ||
554 | int offsetY = (int)m_scene.RegionInfo.RegionLocY - fileStartY; | ||
555 | |||
556 | if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight) | ||
557 | { | ||
558 | // this region is included in the tile request | ||
559 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
560 | { | ||
561 | if (filename.EndsWith(loader.Key)) | ||
562 | { | ||
563 | lock (m_scene) | ||
564 | { | ||
565 | loader.Value.SaveFile(m_channel, filename, offsetX, offsetY, | ||
566 | fileWidth, fileHeight, | ||
567 | (int)Constants.RegionSize, | ||
568 | (int)Constants.RegionSize); | ||
569 | } | ||
570 | return; | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | |||
576 | /// <summary> | ||
544 | /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections | 577 | /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections |
545 | /// </summary> | 578 | /// </summary> |
546 | private void EventManager_OnTerrainTick() | 579 | private void EventManager_OnTerrainTick() |
@@ -860,6 +893,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
860 | SaveToFile((string) args[0]); | 893 | SaveToFile((string) args[0]); |
861 | } | 894 | } |
862 | 895 | ||
896 | private void InterfaceSaveTileFile(Object[] args) | ||
897 | { | ||
898 | SaveToFile((string)args[0], | ||
899 | (int)args[1], | ||
900 | (int)args[2], | ||
901 | (int)args[3], | ||
902 | (int)args[4]); | ||
903 | } | ||
904 | |||
863 | private void InterfaceBakeTerrain(Object[] args) | 905 | private void InterfaceBakeTerrain(Object[] args) |
864 | { | 906 | { |
865 | UpdateRevertMap(); | 907 | UpdateRevertMap(); |
@@ -1115,6 +1157,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
1115 | loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", | 1157 | loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", |
1116 | "Integer"); | 1158 | "Integer"); |
1117 | 1159 | ||
1160 | Command saveToTileCommand = | ||
1161 | new Command("save-tile", CommandIntentions.COMMAND_HAZARDOUS, InterfaceSaveTileFile, "Saves the current heightmap to the larger file."); | ||
1162 | saveToTileCommand.AddArgument("filename", | ||
1163 | "The file you wish to save to, the file extension determines the loader to be used. Supported extensions include: " + | ||
1164 | supportedFileExtensions, "String"); | ||
1165 | saveToTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer"); | ||
1166 | saveToTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer"); | ||
1167 | saveToTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file", | ||
1168 | "Integer"); | ||
1169 | saveToTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", | ||
1170 | "Integer"); | ||
1118 | // Terrain adjustments | 1171 | // Terrain adjustments |
1119 | Command fillRegionCommand = | 1172 | Command fillRegionCommand = |
1120 | new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); | 1173 | new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); |
@@ -1166,6 +1219,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
1166 | m_commander.RegisterCommand("load", loadFromFileCommand); | 1219 | m_commander.RegisterCommand("load", loadFromFileCommand); |
1167 | m_commander.RegisterCommand("load-tile", loadFromTileCommand); | 1220 | m_commander.RegisterCommand("load-tile", loadFromTileCommand); |
1168 | m_commander.RegisterCommand("save", saveToFileCommand); | 1221 | m_commander.RegisterCommand("save", saveToFileCommand); |
1222 | m_commander.RegisterCommand("save-tile", saveToTileCommand); | ||
1169 | m_commander.RegisterCommand("fill", fillRegionCommand); | 1223 | m_commander.RegisterCommand("fill", fillRegionCommand); |
1170 | m_commander.RegisterCommand("elevate", elevateCommand); | 1224 | m_commander.RegisterCommand("elevate", elevateCommand); |
1171 | m_commander.RegisterCommand("lower", lowerCommand); | 1225 | m_commander.RegisterCommand("lower", lowerCommand); |