From d9d78c342328bd3ffabc1f71d5ce88296654d15b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 13 Nov 2019 19:53:15 +0000 Subject: Terrain: more double to float --- .../CoreModules/World/Terrain/ITerrainModifier.cs | 2 +- .../World/Terrain/Modifiers/FillModifier.cs | 6 +++--- .../World/Terrain/Modifiers/LowerModifier.cs | 6 +++--- .../World/Terrain/Modifiers/MaxModifier.cs | 6 +++--- .../World/Terrain/Modifiers/MinModifier.cs | 6 +++--- .../World/Terrain/Modifiers/NoiseModifier.cs | 8 ++++---- .../World/Terrain/Modifiers/RaiseModifier.cs | 6 +++--- .../World/Terrain/Modifiers/SmoothModifier.cs | 12 +++++------ .../CoreModules/World/Terrain/TerrainModifier.cs | 24 ++++++++++++++-------- .../CoreModules/World/Terrain/TerrainModule.cs | 16 +++++++-------- 10 files changed, 49 insertions(+), 43 deletions(-) (limited to 'OpenSim/Region/CoreModules/World/Terrain') diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainModifier.cs index 0e0a0e4..5e3232d 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainModifier.cs @@ -70,7 +70,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain /// /// Y. /// - double operate(double[,] map, TerrainModifierData data, int x, int y); + float operate(float[,] map, TerrainModifierData data, int x, int y); } } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/FillModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/FillModifier.cs index 32f1de9..a56b4a7 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/FillModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/FillModifier.cs @@ -80,10 +80,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers return val; } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double factor = this.computeBevel(data, x, y); - double result = data.elevation - (data.elevation - data.bevelevation) * factor; + float factor = this.computeBevel(data, x, y); + float result = data.elevation - (data.elevation - data.bevelevation) * factor; return result; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/LowerModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/LowerModifier.cs index 2ab4bcc..4fb08ce 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/LowerModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/LowerModifier.cs @@ -79,10 +79,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double factor = this.computeBevel(data, x, y); - double result = map[x, y] - (data.elevation - (data.elevation - data.bevelevation) * factor); + float factor = this.computeBevel(data, x, y); + float result = map[x, y] - (data.elevation - (data.elevation - data.bevelevation) * factor); return result; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MaxModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MaxModifier.cs index 0939c0a..cf4bfab 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MaxModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MaxModifier.cs @@ -79,10 +79,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double factor = this.computeBevel(data, x, y); - double result = Math.Min(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]); + float factor = this.computeBevel(data, x, y); + float result = Math.Min(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]); return result; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MinModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MinModifier.cs index cbbccc0..7e8f6c8 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MinModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/MinModifier.cs @@ -79,10 +79,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double factor = this.computeBevel(data, x, y); - double result = Math.Max(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]); + float factor = this.computeBevel(data, x, y); + float result = Math.Max(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]); return result; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs index d6b95d0..ea11ab5 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs @@ -96,11 +96,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers return val; } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double factor = this.computeBevel(data, x, y); - double noise = TerrainUtil.PerlinNoise2D((double)x / map.GetLength(0), (double)y / map.GetLength(1), 8, 1.0); - return map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor) * (noise - .5); + float factor = this.computeBevel(data, x, y); + float noise = (float)TerrainUtil.PerlinNoise2D((double)x / map.GetLength(0), (double)y / map.GetLength(1), 8, 1.0); + return map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor) * (noise - .5f); } } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/RaiseModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/RaiseModifier.cs index 35fb9d6..9f5f59a 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/RaiseModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/RaiseModifier.cs @@ -79,10 +79,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double factor = this.computeBevel(data, x, y); - double result = map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor); + float factor = this.computeBevel(data, x, y); + float result = map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor); return result; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs index 9f8d5b2..1a4bb61 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs @@ -95,22 +95,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers return val; } - public override double operate(double[,] map, TerrainModifierData data, int x, int y) + public override float operate(float[,] map, TerrainModifierData data, int x, int y) { - double[] scale = new double[3]; + float[] scale = new float[3]; scale[0] = data.elevation; - scale[1] = ((1.0 - scale[0]) * data.bevelevation) / 8.0; - scale[2] = ((1.0 - scale[0]) * (1.0 - data.bevelevation)) / 16.0; + scale[1] = ((1.0f - scale[0]) * data.bevelevation) / 8.0f; + scale[2] = ((1.0f - scale[0]) * (1.0f - data.bevelevation)) / 16.0f; int xMax = map.GetLength(0); int yMax = map.GetLength(1); - double result; + float result; if ((x == 0) || (y == 0) || (x == (xMax - 1)) || (y == (yMax - 1))) { result = map[x, y]; } else { - result = 0.0; + result = 0.0f; for(int yPos = (y - 2); yPos < (y + 3); yPos++) { int yVal = (yPos <= 0) ? 0 : ((yPos < yMax) ? yPos : yMax - 1); diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs index e977a75..e808d1c 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs @@ -46,7 +46,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain public abstract string GetUsage(); - public abstract double operate(double[,] map, TerrainModifierData data, int x, int y); + public abstract float operate(float[,] map, TerrainModifierData data, int x, int y); protected String parseParameters(string[] args, out TerrainModifierData data) { @@ -153,8 +153,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain protected string parseFloat(String s, out float f) { string result; - double d; - if (Double.TryParse(s, out d)) + float d; + if (float.TryParse(s, out d)) { try { @@ -213,7 +213,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain yMid = 0; } // m_log.DebugFormat("Apply {0} mask {1}x{2} @ {3},{4}", data.shape, xMax, yMax, xMid, yMid); - double[,] buffer = map.GetDoubles(); + + float[,] buffer = new float[map.Width, map.Height]; + for (int x = data.x0; x < xMax; ++x) + for (int y = data.y0; y < yMax; ++y) + buffer[x,y] = map[x,y]; + int yDim = yMax; while(--yDim >= 0) { @@ -224,6 +229,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain while(--xDim >= 0) { int xPos = data.x0 + xDim - xMid; + if ((xPos >= 0) && (xPos < map.Width) && (mask[xDim, yDim])) { double endElevation = this.operate(buffer, data, xPos, yPos); @@ -234,13 +240,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain } } - protected double computeBevel(TerrainModifierData data, int x, int y) + protected float computeBevel(TerrainModifierData data, int x, int y) { int deltaX; int deltaY; int xMax; int yMax; - double factor; + float factor; if (data.bevel == "taper") { if (data.shape == "ellipse") @@ -249,7 +255,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain deltaY = y - data.y0; xMax = data.dx; yMax = data.dy; - factor = (double)((deltaX * deltaX) + (deltaY * deltaY)); + factor = ((deltaX * deltaX) + (deltaY * deltaY)); factor /= ((xMax * xMax) + (yMax * yMax)); } else @@ -259,12 +265,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain yMax = data.dy / 2 + data.dy % 2; deltaX = Math.Abs(data.x0 + xMax - x); deltaY = Math.Abs(data.y0 + yMax - y); - factor = Math.Max(((double)(deltaY) / yMax), ((double)(deltaX) / xMax)); + factor = Math.Max(((float)(deltaY) / yMax), ((float)(deltaX) / xMax)); } } else { - factor = 0.0; + factor = 0.0f; } return factor; } diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index d73c89f..8f60d2f 100755 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs @@ -1832,19 +1832,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain Command fillRegionCommand = new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.", - "Double"); + "Float"); Command elevateCommand = new Command("elevate", CommandIntentions.COMMAND_HAZARDOUS, InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); - elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double"); + elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Float"); Command lowerCommand = new Command("lower", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); - lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double"); + lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Float"); Command multiplyCommand = new Command("multiply", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); - multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); + multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Float"); Command bakeRegionCommand = new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions baked map."); @@ -1857,14 +1857,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain Command rescaleCommand = new Command("rescale", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRescaleTerrain, "Rescales the current terrain to fit between the given min and max heights"); - rescaleCommand.AddArgument("min", "min terrain height after rescaling", "Double"); - rescaleCommand.AddArgument("max", "max terrain height after rescaling", "Double"); + rescaleCommand.AddArgument("min", "min terrain height after rescaling", "Float"); + rescaleCommand.AddArgument("max", "max terrain height after rescaling", "Float"); Command minCommand = new Command("min", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMinTerrain, "Sets the minimum terrain height to the specified value."); - minCommand.AddArgument("min", "terrain height to use as minimum", "Double"); + minCommand.AddArgument("min", "terrain height to use as minimum", "Float"); Command maxCommand = new Command("max", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMaxTerrain, "Sets the maximum terrain height to the specified value."); - maxCommand.AddArgument("min", "terrain height to use as maximum", "Double"); + maxCommand.AddArgument("min", "terrain height to use as maximum", "Float"); // Debug -- cgit v1.1