From 4eb8ca49a901b09ce4bc3130f76f53b910391bbc Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sat, 21 Jul 2007 22:20:22 +0000 Subject: * Renamed terrain functions to match OpenSim naming styles. * Added capability to support minimum/maximum terrain limits (from the last 'bake') --- .../Region/ClientStack/RegionApplicationBase.cs | 2 +- OpenSim/Region/Environment/LandManagement/Land.cs | 4 +- .../Environment/Scenes/Scene.PacketHandlers.cs | 12 +- OpenSim/Region/Environment/Scenes/Scene.cs | 30 ++--- OpenSim/Region/Environment/Scenes/SceneBase.cs | 4 +- OpenSim/Region/Examples/SimpleApp/MyWorld.cs | 2 +- .../Region/Terrain.BasicTerrain/TerrainEngine.cs | 136 +++++++++++++-------- 7 files changed, 113 insertions(+), 77 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index 4a1fd99..1651ec2 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs @@ -113,7 +113,7 @@ namespace OpenSim.Region.ClientStack scene.LoadWorldMap(); scene.PhysScene = GetPhysicsScene( ); - scene.PhysScene.SetTerrain(scene.Terrain.getHeights1D()); + scene.PhysScene.SetTerrain(scene.Terrain.GetHeights1D()); scene.LoadPrimsFromStorage(); //Master Avatar Setup diff --git a/OpenSim/Region/Environment/LandManagement/Land.cs b/OpenSim/Region/Environment/LandManagement/Land.cs index b333f36..bae3b0e 100644 --- a/OpenSim/Region/Environment/LandManagement/Land.cs +++ b/OpenSim/Region/Environment/LandManagement/Land.cs @@ -219,8 +219,8 @@ namespace OpenSim.Region.Environment.LandManagement } } } - landData.AABBMin = new LLVector3((float)(min_x * 4), (float)(min_y * 4), (float)m_world.Terrain.get((min_x * 4), (min_y * 4))); - landData.AABBMax = new LLVector3((float)(max_x * 4), (float)(max_y * 4), (float)m_world.Terrain.get((max_x * 4), (max_y * 4))); + landData.AABBMin = new LLVector3((float)(min_x * 4), (float)(min_y * 4), (float)m_world.Terrain.GetHeight((min_x * 4), (min_y * 4))); + landData.AABBMax = new LLVector3((float)(max_x * 4), (float)(max_y * 4), (float)m_world.Terrain.GetHeight((max_x * 4), (max_y * 4))); landData.area = tempArea; } diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index 9a81a5f..e963737 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -54,32 +54,32 @@ namespace OpenSim.Region.Environment.Scenes { case 0: // flatten terrain - Terrain.flatten(north, west, size, (double)seconds / 5.0); + Terrain.FlattenTerrain(north, west, size, (double)seconds / 5.0); RegenerateTerrain(true, (int)north, (int)west); break; case 1: // raise terrain - Terrain.raise(north, west, size, (double)seconds / 5.0); + Terrain.RaiseTerrain(north, west, size, (double)seconds / 5.0); RegenerateTerrain(true, (int)north, (int)west); break; case 2: //lower terrain - Terrain.lower(north, west, size, (double)seconds / 5.0); + Terrain.LowerTerrain(north, west, size, (double)seconds / 5.0); RegenerateTerrain(true, (int)north, (int)west); break; case 3: // smooth terrain - Terrain.smooth(north, west, size, (double)seconds / 5.0); + Terrain.SmoothTerrain(north, west, size, (double)seconds / 5.0); RegenerateTerrain(true, (int)north, (int)west); break; case 4: // noise - Terrain.noise(north, west, size, (double)seconds / 5.0); + Terrain.NoiseTerrain(north, west, size, (double)seconds / 5.0); RegenerateTerrain(true, (int)north, (int)west); break; case 5: // revert - Terrain.revert(north, west, size, (double)seconds / 5.0); + Terrain.RevertTerrain(north, west, size, (double)seconds / 5.0); RegenerateTerrain(true, (int)north, (int)west); break; diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index acd7f3f..64676f0 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -239,10 +239,10 @@ namespace OpenSim.Region.Environment.Scenes { lock (m_syncRoot) { - phyScene.SetTerrain(Terrain.getHeights1D()); + phyScene.SetTerrain(Terrain.GetHeights1D()); } - storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); + storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); ForEachScenePresence(delegate(ScenePresence presence) { @@ -295,14 +295,14 @@ namespace OpenSim.Region.Environment.Scenes { try { - Terrain.hills(); + Terrain.HillsGenerator(); lock (m_syncRoot) { - phyScene.SetTerrain(Terrain.getHeights1D()); + phyScene.SetTerrain(Terrain.GetHeights1D()); } - storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); + storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); ForEachScenePresence(delegate(ScenePresence presence) { @@ -328,12 +328,12 @@ namespace OpenSim.Region.Environment.Scenes { try { - Terrain.setHeights2D(newMap); + Terrain.SetHeights2D(newMap); lock (m_syncRoot) { - phyScene.SetTerrain(Terrain.getHeights1D()); + phyScene.SetTerrain(Terrain.GetHeights1D()); } - storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); + storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); ForEachScenePresence(delegate(ScenePresence presence) { @@ -395,28 +395,28 @@ namespace OpenSim.Region.Environment.Scenes if (string.IsNullOrEmpty(m_regInfo.estateSettings.terrainFile)) { Console.WriteLine("No default terrain, procedurally generating..."); - Terrain.hills(); + Terrain.HillsGenerator(); - storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); + storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); } else { try { - Terrain.loadFromFileF32(m_regInfo.estateSettings.terrainFile); + Terrain.LoadFromFileF32(m_regInfo.estateSettings.terrainFile); Terrain *= m_regInfo.estateSettings.terrainMultiplier; } catch { Console.WriteLine("Unable to load default terrain, procedurally generating instead..."); - Terrain.hills(); + Terrain.HillsGenerator(); } - storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); + storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); } } else { - Terrain.setHeights2D(map); + Terrain.SetHeights2D(map); } CreateTerrainTexture(); @@ -433,7 +433,7 @@ namespace OpenSim.Region.Environment.Scenes public void CreateTerrainTexture() { //create a texture asset of the terrain - byte[] data = Terrain.exportJpegImage("defaultstripe.png"); + byte[] data = Terrain.ExportJpegImage("defaultstripe.png"); m_regInfo.estateSettings.terrainImageID = LLUUID.Random(); AssetBase asset = new AssetBase(); asset.FullID = m_regInfo.estateSettings.terrainImageID; diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index f3db9e2..c91c654 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs @@ -81,7 +81,7 @@ namespace OpenSim.Region.Environment.Scenes /// Client to send to public virtual void SendLayerData(IClientAPI RemoteClient) { - RemoteClient.SendLayerData(Terrain.getHeights1D()); + RemoteClient.SendLayerData(Terrain.GetHeights1D()); } /// @@ -92,7 +92,7 @@ namespace OpenSim.Region.Environment.Scenes /// The client to send to public virtual void SendLayerData(int px, int py, IClientAPI RemoteClient) { - RemoteClient.SendLayerData(px, py, Terrain.getHeights1D()); + RemoteClient.SendLayerData(px, py, Terrain.GetHeights1D()); } #endregion diff --git a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs index 9749e22..6704a19 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs @@ -36,7 +36,7 @@ namespace SimpleApp map[i] = 25f; } - this.Terrain.setHeights1D(map); + this.Terrain.GetHeights1D(map); this.CreateTerrainTexture(); } diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs index 686b35d..f965c41 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs @@ -69,6 +69,17 @@ namespace OpenSim.Region.Terrain public Channel watermap; /// + /// Max amount the terrain can be raised from the revert parameters + /// + public double maxRaise = 500.0; + + /// + /// Min amount the terrain can be lowered from the revert parameters + /// + public double minLower = 500.0; + + + /// /// Whether or not the terrain has been modified since it was last saved and sent to the Physics engine. /// Counts the number of modifications since the last save. (0 = Untainted) /// @@ -89,10 +100,33 @@ namespace OpenSim.Region.Terrain } /// + /// Checks to make sure the terrain is within baked values +/- maxRaise/minLower + /// + public void CheckHeightValues() + { + int x, y; + for (x = 0; x < w; x++) + { + for (y = 0; y < h; y++) + { + if ((heightmap.get(x, y) > revertmap.get(x, y) + maxRaise)) + { + heightmap.map[x, y] = revertmap(x, y) + maxRaise; + } + if ((heightmap.get(x, y) > revertmap.get(x, y) - minLower)) + { + heightmap.map[x, y] = revertmap(x, y) - minLower; + } + } + } + } + + + /// /// Converts the heightmap to a 65536 value 1D floating point array /// /// A float[65536] array containing the heightmap - public float[] getHeights1D() + public float[] GetHeights1D() { float[] heights = new float[w * h]; int i; @@ -109,7 +143,7 @@ namespace OpenSim.Region.Terrain /// Converts the heightmap to a 256x256 value 2D floating point array. /// /// An array of 256,256 values containing the heightmap - public float[,] getHeights2D() + public float[,] GetHeights2D() { float[,] heights = new float[w, h]; int x, y; @@ -127,7 +161,7 @@ namespace OpenSim.Region.Terrain /// Converts the heightmap to a 256x256 value 2D floating point array. Double precision version. /// /// An array of 256,256 values containing the heightmap - public double[,] getHeights2DD() + public double[,] GetHeights2DD() { return heightmap.map; } @@ -136,7 +170,7 @@ namespace OpenSim.Region.Terrain /// Imports a 1D floating point array into the 2D heightmap array /// /// The array to import (must have 65536 members) - public void setHeights1D(float[] heights) + public void GetHeights1D(float[] heights) { int i; for (i = 0; i < w * h; i++) @@ -151,7 +185,7 @@ namespace OpenSim.Region.Terrain /// Loads a 2D array of values into the heightmap /// /// An array of 256,256 float values - public void setHeights2D(float[,] heights) + public void SetHeights2D(float[,] heights) { int x, y; for (x = 0; x < w; x++) @@ -161,6 +195,7 @@ namespace OpenSim.Region.Terrain heightmap.set(x, y, (double)heights[x, y]); } } + SaveRevertMap(); tainted++; } @@ -168,7 +203,7 @@ namespace OpenSim.Region.Terrain /// Loads a 2D array of values into the heightmap (Double Precision Version) /// /// An array of 256,256 float values - public void setHeights2D(double[,] heights) + public void SetHeights2D(double[,] heights) { int x, y; for (x = 0; x < w; x++) @@ -178,13 +213,14 @@ namespace OpenSim.Region.Terrain heightmap.set(x, y, heights[x, y]); } } + SaveRevertMap(); tainted++; } /// /// Swaps the two heightmap buffers (the 'revert map' and the heightmap) /// - public void swapRevertMaps() + public void SwapRevertMaps() { Channel backup = heightmap.copy(); heightmap = revertmap; @@ -194,7 +230,7 @@ namespace OpenSim.Region.Terrain /// /// Saves the current heightmap into the revertmap /// - public void saveRevertMap() + public void SaveRevertMap() { revertmap = heightmap.copy(); } @@ -239,20 +275,20 @@ namespace OpenSim.Region.Terrain return false; case "revert": - swapRevertMaps(); - saveRevertMap(); + SwapRevertMaps(); + SaveRevertMap(); break; case "bake": - saveRevertMap(); + SaveRevertMap(); break; case "seed": - setSeed(Convert.ToInt32(args[1])); + SetSeed(Convert.ToInt32(args[1])); break; case "erode": - return consoleErosion(args, ref resultText); + return ConsoleErosion(args, ref resultText); case "voronoi": double[] c = new double[2]; @@ -262,14 +298,14 @@ namespace OpenSim.Region.Terrain break; case "hills": - return consoleHills(args, ref resultText); + return ConsoleHills(args, ref resultText); case "regenerate": - hills(); + HillsGenerator(); break; case "rescale": - setRange(Convert.ToSingle(args[1]), Convert.ToSingle(args[2])); + SetRange(Convert.ToSingle(args[1]), Convert.ToSingle(args[2])); break; case "multiply": @@ -282,15 +318,15 @@ namespace OpenSim.Region.Terrain switch (args[1].ToLower()) { case "f32": - loadFromFileF32(args[2]); + LoadFromFileF32(args[2]); break; case "f64": - loadFromFileF64(args[2]); + LoadFromFileF64(args[2]); break; case "raw": - loadFromFileSLRAW(args[2]); + LoadFromFileSLRAW(args[2]); break; case "img": @@ -308,15 +344,15 @@ namespace OpenSim.Region.Terrain switch (args[1].ToLower()) { case "f32": - writeToFileF32(args[2]); + WriteToFileF32(args[2]); break; case "f64": - writeToFileF64(args[2]); + WriteToFileF64(args[2]); break; case "grdmap": - exportImage(args[2], args[3]); + ExportImage(args[2], args[3]); break; case "png": @@ -324,11 +360,11 @@ namespace OpenSim.Region.Terrain break; case "raw": - writeToFileRAW(args[2]); + WriteToFileRAW(args[2]); break; case "hiraw": - writeToFileHiRAW(args[2]); + WriteToFileHiRAW(args[2]); break; default: @@ -366,7 +402,7 @@ namespace OpenSim.Region.Terrain } } - private bool consoleErosion(string[] args, ref string resultText) + private bool ConsoleErosion(string[] args, ref string resultText) { switch (args[1].ToLower()) { @@ -384,10 +420,10 @@ namespace OpenSim.Region.Terrain return true; } - private bool consoleHills(string[] args, ref string resultText) + private bool ConsoleHills(string[] args, ref string resultText) { Random RandomClass = new Random(); - setSeed(RandomClass.Next()); + SetSeed(RandomClass.Next()); int count; double sizeMin; double sizeRange; @@ -441,7 +477,7 @@ namespace OpenSim.Region.Terrain /// /// Minimum value of the new array /// Maximum value of the new array - public void setRange(float min, float max) + public void SetRange(float min, float max) { heightmap.normalise((double)min, (double)max); tainted++; @@ -452,7 +488,7 @@ namespace OpenSim.Region.Terrain /// /// TODO: Move this to libTerrain itself /// The filename of the double array to import - public void loadFromFileF64(string filename) + public void LoadFromFileF64(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.Open, FileAccess.Read); @@ -477,7 +513,7 @@ namespace OpenSim.Region.Terrain /// /// TODO: Move this to libTerrain itself /// The filename of the float array to import - public void loadFromFileF32(string filename) + public void LoadFromFileF32(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.Open, FileAccess.Read); @@ -502,7 +538,7 @@ namespace OpenSim.Region.Terrain /// /// This file format stinks and is best avoided. /// A path to the .RAW format - public void loadFromFileSLRAW(string filename) + public void LoadFromFileSLRAW(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.Open, FileAccess.Read); @@ -527,7 +563,7 @@ namespace OpenSim.Region.Terrain /// Writes the current terrain heightmap to disk, in the format of a 65536 entry double[] array. /// /// The desired output filename - public void writeToFileF64(string filename) + public void WriteToFileF64(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); @@ -550,7 +586,7 @@ namespace OpenSim.Region.Terrain /// Writes the current terrain heightmap to disk, in the format of a 65536 entry float[] array /// /// The desired output filename - public void writeToFileF32(string filename) + public void WriteToFileF32(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); @@ -574,7 +610,7 @@ namespace OpenSim.Region.Terrain /// (is also editable in an image application) /// /// Filename to write to - public void writeToFileRAW(string filename) + public void WriteToFileRAW(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); @@ -639,7 +675,7 @@ namespace OpenSim.Region.Terrain /// /// Does not calculate the revert map /// The filename to output to - public void writeToFileHiRAW(string filename) + public void WriteToFileHiRAW(string filename) { FileInfo file = new FileInfo(filename); FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); @@ -712,7 +748,7 @@ namespace OpenSim.Region.Terrain /// Sets the random seed to be used by procedural functions which involve random numbers. /// /// The desired seed - public void setSeed(int val) + public void SetSeed(int val) { heightmap.seed = val; } @@ -724,7 +760,7 @@ namespace OpenSim.Region.Terrain /// Center of the sphere on the Y axis /// The radius of the sphere /// Scale the height of the sphere by this amount (recommended 0..2) - public void raise(double rx, double ry, double size, double amount) + public void RaiseTerrain(double rx, double ry, double size, double amount) { lock (heightmap) { @@ -741,7 +777,7 @@ namespace OpenSim.Region.Terrain /// The center of the sphere at the Y axis /// The radius of the sphere in meters /// Scale the height of the sphere by this amount (recommended 0..2) - public void lower(double rx, double ry, double size, double amount) + public void LowerTerrain(double rx, double ry, double size, double amount) { lock (heightmap) { @@ -758,7 +794,7 @@ namespace OpenSim.Region.Terrain /// Center of sphere /// Radius of the sphere /// Thickness of the mask (0..2 recommended) - public void flatten(double rx, double ry, double size, double amount) + public void FlattenTerrain(double rx, double ry, double size, double amount) { lock (heightmap) { @@ -775,7 +811,7 @@ namespace OpenSim.Region.Terrain /// Center of the bounding sphere /// The radius of the sphere /// Strength of the mask (0..2) recommended - public void noise(double rx, double ry, double size, double amount) + public void NoiseTerrain(double rx, double ry, double size, double amount) { lock (heightmap) { @@ -798,7 +834,7 @@ namespace OpenSim.Region.Terrain /// Center of the bounding sphere /// The radius of the sphere /// Strength of the mask (0..2) recommended - public void revert(double rx, double ry, double size, double amount) + public void RevertTerrain(double rx, double ry, double size, double amount) { lock (heightmap) { @@ -818,7 +854,7 @@ namespace OpenSim.Region.Terrain /// Center of the sphere /// Radius of the sphere /// Thickness of the mask (0..2 recommended) - public void smooth(double rx, double ry, double size, double amount) + public void SmoothTerrain(double rx, double ry, double size, double amount) { lock (heightmap) { @@ -837,7 +873,7 @@ namespace OpenSim.Region.Terrain /// /// Generates a simple set of hills in the shape of an island /// - public void hills() + public void HillsGenerator() { lock (heightmap) { @@ -855,7 +891,7 @@ namespace OpenSim.Region.Terrain /// X coord /// Y coord /// Height at specified coordinates - public double get(int x, int y) + public double GetHeight(int x, int y) { return heightmap.get(x, y); } @@ -866,11 +902,11 @@ namespace OpenSim.Region.Terrain /// The heightfield /// The multiplier /// - public static TerrainEngine operator *(TerrainEngine meep, Double val) + public static TerrainEngine operator *(TerrainEngine terrain, Double val) { - meep.heightmap *= val; - meep.tainted++; - return meep; + terrain.heightmap *= val; + terrain.tainted++; + return terrain; } /// @@ -878,7 +914,7 @@ namespace OpenSim.Region.Terrain /// /// The destination filename for the image /// A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal. - public void exportImage(string filename, string gradientmap) + public void ExportImage(string filename, string gradientmap) { try { @@ -917,7 +953,7 @@ namespace OpenSim.Region.Terrain /// Exports the current heightmap in Jpeg2000 format to a byte[] /// /// A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal. - public byte[] exportJpegImage(string gradientmap) + public byte[] ExportJpegImage(string gradientmap) { byte[] imageData = null; try -- cgit v1.1