public MinMaxResult GetRemap() { int res = TerraConfig.Instance.Generator.RemapResolution; MinMaxRecorder recorder = new MinMaxRecorder(); for (int x = 0; x < res; x++) { for (int y = 0; y < res; y++) { recorder.Register(_generator.GetValue(x / (float)res, y / (float)res, 0)); } } return(recorder.GetMinMax()); }
private MinMaxResult GetRemap() { if (_cachedRemap != null) { return(_cachedRemap.Value); } int res = TerraConfig.Instance.Generator.RemapResolution; MinMaxRecorder recorder = new MinMaxRecorder(); for (int x = 0; x < res; x++) { for (int y = 0; y < res; y++) { recorder.Register(_generator.GetValue(x, y, 0)); } } _cachedRemap = recorder.GetMinMax(); return(_cachedRemap.Value); }
/// <summary> /// Gets the min/max values for all connected biomes /// </summary> /// <returns></returns> private MinMaxResult GetBiomesMinMax() { MinMaxRecorder recorder = new MinMaxRecorder(); int res = TerraConfig.Instance.Generator.RemapResolution; List <Generator> generators = new List <Generator>(); foreach (BiomeNode b in _combiner.GetConnectedBiomeNodes()) { Generator g1 = b.HeightmapGenerator.GetGenerator(); Generator g2 = b.TemperatureGenerator.GetGenerator(); Generator g3 = b.MoistureGenerator.GetGenerator(); if (g1 != null) { generators.Add(g1); } if (g2 != null) { generators.Add(g2); } if (g3 != null) { generators.Add(g3); } } for (int x = 0; x < res; x++) { for (int y = 0; y < res; y++) { foreach (Generator g in generators) { recorder.Register(g.GetValue(x / (float)res, y / (float)res, 0)); } } } return(recorder.GetMinMax()); }
/// <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)); } }