Terrain: more double to float

0.9.1.1
UbitUmarov 2019-11-13 19:53:15 +00:00
parent 5d2ffdc35b
commit d9d78c3423
11 changed files with 52 additions and 43 deletions

View File

@ -147,6 +147,9 @@ namespace OpenSim.Region.CoreModules.Framework.InterfaceCommander
case "Integer": case "Integer":
m_args[i].ArgumentValue = Int32.Parse(arg.ToString()); m_args[i].ArgumentValue = Int32.Parse(arg.ToString());
break; break;
case "Float":
m_args[i].ArgumentValue = float.Parse(arg.ToString(), OpenSim.Framework.Culture.NumberFormatInfo);
break;
case "Double": case "Double":
m_args[i].ArgumentValue = Double.Parse(arg.ToString(), OpenSim.Framework.Culture.NumberFormatInfo); m_args[i].ArgumentValue = Double.Parse(arg.ToString(), OpenSim.Framework.Culture.NumberFormatInfo);
break; break;

View File

@ -70,7 +70,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
/// <param name='y'> /// <param name='y'>
/// Y. /// Y.
/// </param> /// </param>
double operate(double[,] map, TerrainModifierData data, int x, int y); float operate(float[,] map, TerrainModifierData data, int x, int y);
} }
} }

View File

@ -80,10 +80,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers
return val; 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); float factor = this.computeBevel(data, x, y);
double result = data.elevation - (data.elevation - data.bevelevation) * factor; float result = data.elevation - (data.elevation - data.bevelevation) * factor;
return result; return result;
} }

View File

@ -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); float factor = this.computeBevel(data, x, y);
double result = map[x, y] - (data.elevation - (data.elevation - data.bevelevation) * factor); float result = map[x, y] - (data.elevation - (data.elevation - data.bevelevation) * factor);
return result; return result;
} }

View File

@ -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); float factor = this.computeBevel(data, x, y);
double result = Math.Min(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]); float result = Math.Min(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]);
return result; return result;
} }

View File

@ -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); float factor = this.computeBevel(data, x, y);
double result = Math.Max(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]); float result = Math.Max(data.elevation - (data.elevation - data.bevelevation) * factor, map[x, y]);
return result; return result;
} }

View File

@ -96,11 +96,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers
return val; 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); float factor = this.computeBevel(data, x, y);
double noise = TerrainUtil.PerlinNoise2D((double)x / map.GetLength(0), (double)y / map.GetLength(1), 8, 1.0); 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 - .5); return map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor) * (noise - .5f);
} }
} }

View File

@ -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); float factor = this.computeBevel(data, x, y);
double result = map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor); float result = map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor);
return result; return result;
} }

View File

@ -95,22 +95,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers
return val; 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[0] = data.elevation;
scale[1] = ((1.0 - scale[0]) * data.bevelevation) / 8.0; scale[1] = ((1.0f - scale[0]) * data.bevelevation) / 8.0f;
scale[2] = ((1.0 - scale[0]) * (1.0 - data.bevelevation)) / 16.0; scale[2] = ((1.0f - scale[0]) * (1.0f - data.bevelevation)) / 16.0f;
int xMax = map.GetLength(0); int xMax = map.GetLength(0);
int yMax = map.GetLength(1); int yMax = map.GetLength(1);
double result; float result;
if ((x == 0) || (y == 0) || (x == (xMax - 1)) || (y == (yMax - 1))) if ((x == 0) || (y == 0) || (x == (xMax - 1)) || (y == (yMax - 1)))
{ {
result = map[x, y]; result = map[x, y];
} }
else else
{ {
result = 0.0; result = 0.0f;
for(int yPos = (y - 2); yPos < (y + 3); yPos++) for(int yPos = (y - 2); yPos < (y + 3); yPos++)
{ {
int yVal = (yPos <= 0) ? 0 : ((yPos < yMax) ? yPos : yMax - 1); int yVal = (yPos <= 0) ? 0 : ((yPos < yMax) ? yPos : yMax - 1);

View File

@ -46,7 +46,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
public abstract string GetUsage(); 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) 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) protected string parseFloat(String s, out float f)
{ {
string result; string result;
double d; float d;
if (Double.TryParse(s, out d)) if (float.TryParse(s, out d))
{ {
try try
{ {
@ -213,7 +213,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
yMid = 0; yMid = 0;
} }
// m_log.DebugFormat("Apply {0} mask {1}x{2} @ {3},{4}", data.shape, xMax, yMax, xMid, yMid); // 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; int yDim = yMax;
while(--yDim >= 0) while(--yDim >= 0)
{ {
@ -224,6 +229,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
while(--xDim >= 0) while(--xDim >= 0)
{ {
int xPos = data.x0 + xDim - xMid; int xPos = data.x0 + xDim - xMid;
if ((xPos >= 0) && (xPos < map.Width) && (mask[xDim, yDim])) if ((xPos >= 0) && (xPos < map.Width) && (mask[xDim, yDim]))
{ {
double endElevation = this.operate(buffer, data, xPos, yPos); 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 deltaX;
int deltaY; int deltaY;
int xMax; int xMax;
int yMax; int yMax;
double factor; float factor;
if (data.bevel == "taper") if (data.bevel == "taper")
{ {
if (data.shape == "ellipse") if (data.shape == "ellipse")
@ -249,7 +255,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
deltaY = y - data.y0; deltaY = y - data.y0;
xMax = data.dx; xMax = data.dx;
yMax = data.dy; yMax = data.dy;
factor = (double)((deltaX * deltaX) + (deltaY * deltaY)); factor = ((deltaX * deltaX) + (deltaY * deltaY));
factor /= ((xMax * xMax) + (yMax * yMax)); factor /= ((xMax * xMax) + (yMax * yMax));
} }
else else
@ -259,12 +265,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
yMax = data.dy / 2 + data.dy % 2; yMax = data.dy / 2 + data.dy % 2;
deltaX = Math.Abs(data.x0 + xMax - x); deltaX = Math.Abs(data.x0 + xMax - x);
deltaY = Math.Abs(data.y0 + yMax - y); 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 else
{ {
factor = 0.0; factor = 0.0f;
} }
return factor; return factor;
} }

View File

@ -1832,19 +1832,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain
Command fillRegionCommand = Command fillRegionCommand =
new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); 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.", fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.",
"Double"); "Float");
Command elevateCommand = Command elevateCommand =
new Command("elevate", CommandIntentions.COMMAND_HAZARDOUS, InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); 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 = Command lowerCommand =
new Command("lower", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); 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 = Command multiplyCommand =
new Command("multiply", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); 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 = Command bakeRegionCommand =
new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions baked map."); 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 = Command rescaleCommand =
new Command("rescale", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRescaleTerrain, "Rescales the current terrain to fit between the given min and max heights"); 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("min", "min terrain height after rescaling", "Float");
rescaleCommand.AddArgument("max", "max terrain height after rescaling", "Double"); 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."); 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."); 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 // Debug