/// <summary> /// Creates a map of weights where each weight representing the probability /// between 0 and 1 that the biome will appear /// </summary> /// <param name="values"></param> /// <param name="min"></param> /// <param name="max"></param> //public float[,] GetWeightedValues() { // //Constraint // Constraint hc = new Constraint(HeightmapMinMaxMask.x, HeightmapMinMaxMask.y); // Constraint tc = new Constraint(TemperatureMinMaxMask.x, TemperatureMinMaxMask.y); // Constraint mc = new Constraint(MoistureMinMaxMask.x, MoistureMinMaxMask.y); // int resolution = values.GetLength(0); // float[,] map = new float[resolution, resolution]; // //Normalize values // for (int x = 0; x < resolution; x++) { // for (int y = 0; y < resolution; y++) { // if (!UseHeightmap && !UseTemperature && !UseMoisture) { // map[x, y] = 1f; // continue; // } // float hv = MathUtil.Map01(values[x, y, 0], min, max); // float tv = MathUtil.Map01(values[x, y, 1], min, max); // float mv = MathUtil.Map01(values[x, y, 2], min, max); // float val = 0; // int count = 0; // //Gather heights that fit set min/max // if (UseHeightmap && hc.Fits(hv)) { // val += hc.Weight(hv, Blend); // count++; // } // if (UseTemperature && tc.Fits(tv)) { // val += tc.Weight(tv, Blend); // count++; // } // if (UseMoisture && mc.Fits(mv)) { // val += mc.Weight(mv, Blend); // count++; // } // val = count > 0 ? val / count : 0; // map[x, y] = Mathf.Clamp01(val); // } // } // return map; //} /// <summary> /// Create a map of weights each representing the weights of /// the height, temperature, and moisture maps. /// </summary> /// <param name="position">Position in Terra grid units to poll the generators</param> /// <param name="resolution">Resolution of the map to create</param> /// <param name="spread">Optional spread value to poll the generator with</param> /// <param name="length">Optional length parameter that represents the length of a tile</param> /// <returns> /// A structure containing the weights of the height, temperature, and moisture maps. /// The returned structure is a 3D array where the first two indices are the x & y /// coordinates while the last index is the weight of the height, temperature, and /// moisture maps (in that order). /// </returns> //public BiomeMapResult GetMapsValues(GridPosition position, int resolution, float spread = -1f, int length = -1) { // lock (_asyncLock) { // float[,,] heights = new float[resolution, resolution, 3]; // //Update generators // SetHeightmapSampler(); // SetTemperatureSampler(); // SetMoistureSampler(); // //Default spread/length to TerraConfig settings // spread = spread == -1f ? TerraConfig.Instance.Generator.Spread : spread; // length = length == -1 ? TerraConfig.Instance.Generator.Length : length; // //Track min/max // MinMaxRecorder minMax = new MinMaxRecorder(); // //Fill heights structure and set min/max values // for (int x = 0; x < resolution; x++) { // for (int y = 0; y < resolution; y++) { // float[] generated = GetMapHeightsAt(x, y, position, resolution, spread, length); // for (int z = 0; z < 3; z++) { // float height = generated[z]; // heights[x, y, z] = height; // minMax.Register(height); // } // } // } // MinMaxResult result = minMax.GetMinMax(); // return new BiomeMapResult(heights, result.Min, result.Max); // } //} /// <summary> /// Calculates the min and max result for this Biome's /// connected Generator /// </summary> /// <param name="resolution">resolution of remap calculation</param> public MinMaxResult CalculateMinMax(int resolution) { float min = float.PositiveInfinity; float max = float.NegativeInfinity; for (int x = 0; x < resolution; x++) { for (int y = 0; y < resolution; y++) { float[] heights = GetMapHeightsAt(x, y, GridPosition.Zero, resolution, resolution, 1); MinMaxResult localMinMax = MathUtil.GetMinMax(heights); if (localMinMax.Min < min) { min = localMinMax.Min; } if (localMinMax.Max > max) { max = localMinMax.Max; } } } return(new MinMaxResult(min, max)); }
private float GetRemappedValue(float value) { if (!_generator.RequiresRemap) { return(value); } MinMaxResult remap = GetRemap(); float padding = TerraConfig.Instance.Generator.RemapPadding; return(MathUtil.Map01(value, remap.Min - padding, remap.Max + padding)); }
private MinMaxResult CalculateMinMax(int resolution) { float min = float.PositiveInfinity; float max = float.NegativeInfinity; lock (_minMaxLock) { foreach (BiomeNode biome in _biomes) { MinMaxResult minMax = biome.CalculateMinMax(resolution); if (minMax.Min < min) { min = minMax.Min; } if (minMax.Min > max) { max = minMax.Max; } } } return(new MinMaxResult(min, max)); }
public MinMaxResult GetLargestAndSmallestNumber(double[] data) { MinMaxResult result = new MinMaxResult(); if (data == null || data.Length == 0) { //TODO: Log it return(result); } for (int i = 0; i < data.Length; i++) { if (!result.LargestNumber.HasValue || data[i] > result.LargestNumber) { result.LargestNumber = data[i]; } if (!result.SmallestNumber.HasValue || data[i] < result.SmallestNumber) { result.SmallestNumber = data[i]; } } return(result); }
/// <summary> /// Create a map of weights each representing the weights of /// the height, temperature, and moisture maps. /// </summary> /// <param name="position">Position in Terra grid units to poll the generators</param> /// <param name="resolution">Resolution of the map to create</param> /// <param name="spread">Optional spread value to poll the generator with</param> /// <param name="length">Optional length parameter that represents the length of a tile</param> /// <returns> /// A structure containing the weights of the height, temperature, and moisture maps. /// The returned structure is a 3D array where the first two indices are the x & y /// coordinates while the last index is the weight of the height, temperature, and /// moisture maps (in that order). /// </returns> public BiomeMapResult GetMapsValues(GridPosition position, int resolution, float spread = -1f, int length = -1) { lock (_asyncLock) { float[,,] heights = new float[resolution, resolution, 3]; //Update generators SetHeightmapSampler(); SetTemperatureSampler(); SetMoistureSampler(); //Default spread/length to TerraConfig settings spread = spread == -1f ? TerraConfig.Instance.Generator.Spread : spread; length = length == -1 ? TerraConfig.Instance.Generator.Length : length; //Track min/max MinMaxRecorder minMax = new MinMaxRecorder(); //Fill heights structure and set min/max values for (int x = 0; x < resolution; x++) { for (int y = 0; y < resolution; y++) { float[] generated = GetMapHeightsAt(x, y, position, resolution, spread, length); for (int z = 0; z < 3; z++) { float height = generated[z]; heights[x, y, z] = height; minMax.Register(height); } } } MinMaxResult result = minMax.GetMinMax(); return(new BiomeMapResult(heights, result.Min, result.Max)); } }