From aa9d3f7aed59d2ed9ff54e858e8211555b34cefd Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Wed, 6 Feb 2008 20:47:08 +0000
Subject: * Allow terrain load-tile for RAW files * Patch from Sophie Lee
[webmage] - IBM. Thanks very much!
---
.../Region/Terrain.BasicTerrain/TerrainEngine.cs | 58 +++++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
index 248549e..13e3d42 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
@@ -609,6 +609,10 @@ namespace OpenSim.Region.Terrain
LoadFromFileF32(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
break;
+ case "raw":
+ LoadFromFileSLRAW(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
+ Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
+ break;
case "img":
LoadFromFileIMG(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
@@ -962,6 +966,58 @@ namespace OpenSim.Region.Terrain
}
///
+ /// Loads a section of a larger heightmap (RAW)
+ ///
+ /// File to load
+ /// Size of the file
+ /// Size of the file
+ /// Where do the region coords start for this terrain?
+ /// Where do the region coords start for this terrain?
+ public void LoadFromFileSLRAW(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY)
+ {
+ // TODO: Mutex fails to release readlock on folder! --> only one file can be loaded into sim
+ //fileIOLock.WaitOne();
+ //try
+ //{
+ int sectionToLoadX = ((offsetX - lowerboundX)*w);
+ int sectionToLoadY = ((offsetY - lowerboundY)*h);
+
+ double[,] tempMap = new double[dimensionX,dimensionY];
+
+ FileInfo file = new FileInfo(filename);
+ FileStream s = file.Open(FileMode.Open, FileAccess.Read);
+ BinaryReader bs = new BinaryReader(s);
+
+ int x, y;
+ for (x = 0; x < dimensionX; x++)
+ {
+ for (y = 0; y < dimensionY; y++)
+ {
+ tempMap[x, y] = (double) bs.ReadByte()*((double) bs.ReadByte()/127.0);
+ bs.ReadBytes(11); // Advance the stream to next bytes.
+ }
+ }
+
+ for (y = 0; y < h; y++)
+ {
+ for (x = 0; x < w; x++)
+ {
+ heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]);
+ }
+ }
+
+ bs.Close();
+ s.Close();
+
+ tainted++;
+ //}
+ //finally
+ //{
+ // fileIOLock.ReleaseMutex();
+ //}
+ }
+
+ ///
/// Writes the current terrain heightmap to disk, in the format of a 65536 entry double[] array.
///
/// The desired output filename
@@ -1397,4 +1453,4 @@ namespace OpenSim.Region.Terrain
return bmp;
}
}
-}
\ No newline at end of file
+}
--
cgit v1.1