diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs index 48eff1b63a..b2ee3b66cb 100644 --- a/OpenSim.RegionServer/OpenSimMain.cs +++ b/OpenSim.RegionServer/OpenSimMain.cs @@ -505,20 +505,92 @@ namespace OpenSim case "help": m_console.WriteLine("show users - show info about connected users"); m_console.WriteLine("shutdown - disconnect all clients and shutdown"); - m_console.WriteLine("regenerate - regenerate the sim's terrain"); break; case "show": Show(cmdparams[0]); break; - case "regenerate": - LocalWorld.RegenerateTerrain(); + case "terrain": + RunTerrainCmd(cmdparams); break; case "shutdown": Shutdown(); break; + + default: + m_console.WriteLine("Unknown command"); + break; + } + } + + /// + /// Processes a terrain-specific command + /// + /// TODO: Move this into BasicTerrain directly (no need to hard limit what each terrain engine can support) + /// + public void RunTerrainCmd(string[] args) + { + string command = args[0]; + switch (command) + { + case "help": + m_console.WriteLine("terrain regenerate - rebuilds the sims terrain using a default algorithm"); + m_console.WriteLine("terrain seed - sets the random seed value to "); + m_console.WriteLine("terrain load - loads a terrain from disk, type can be 'F32', 'F64' or 'IMG'"); + m_console.WriteLine("terrain save - saves a terrain to disk, type can be 'F32' or 'F64'"); + break; + + case "seed": + LocalWorld.Terrain.setSeed(Convert.ToInt32(args[1])); + break; + + case "regenerate": + LocalWorld.Terrain.hills(); + break; + + case "load": + switch (args[1].ToLower()) + { + case "f32": + LocalWorld.Terrain.loadFromFileF32(args[2]); + break; + + case "f64": + LocalWorld.Terrain.loadFromFileF64(args[2]); + break; + + case "img": + m_console.WriteLine("Error - IMG mode is presently unsupported."); + break; + + default: + m_console.WriteLine("Unknown image or data format"); + break; + } + break; + + case "save": + switch (args[1].ToLower()) + { + case "f32": + LocalWorld.Terrain.writeToFileF32(args[2]); + break; + + case "f64": + LocalWorld.Terrain.writeToFileF64(args[2]); + break; + + default: + m_console.WriteLine("Unknown image or data format"); + break; + } + break; + + default: + m_console.WriteLine("Unknown terrain command"); + break; } } diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs index 65e267aa62..080671bc37 100644 --- a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs @@ -102,6 +102,63 @@ namespace OpenSim.Terrain } } + /// + /// Loads a file consisting of 256x256 floats and imports it as an array into the map. + /// + /// TODO: Move this to libTerrain itself + /// The filename of the float array to import + public void loadFromFileF32(string filename) + { + System.IO.FileInfo file = new System.IO.FileInfo(filename); + System.IO.FileStream s = file.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read); + System.IO.BinaryReader bs = new System.IO.BinaryReader(s); + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + heightmap.map[x, y] = (double)bs.ReadSingle(); + } + } + } + + public void writeToFileF64(string filename) + { + System.IO.FileInfo file = new System.IO.FileInfo(filename); + System.IO.FileStream s = file.Open(System.IO.FileMode.CreateNew, System.IO.FileAccess.Write); + System.IO.BinaryWriter bs = new System.IO.BinaryWriter(s); + + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + bs.Write(heightmap.get(x,y)); + } + } + } + + public void writeToFileF32(string filename) + { + System.IO.FileInfo file = new System.IO.FileInfo(filename); + System.IO.FileStream s = file.Open(System.IO.FileMode.CreateNew, System.IO.FileAccess.Write); + System.IO.BinaryWriter bs = new System.IO.BinaryWriter(s); + + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + bs.Write((float)heightmap.get(x, y)); + } + } + } + + public void setSeed(int val) + { + heightmap.seed = val; + } + /// /// Raises land in a sphere around the specified coordinates ///