From 814d3ea8892d6d95ef3ef26cd694a1aba5c95d9b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 3 Oct 2020 01:18:50 +1000 Subject: [PATCH] Improve performance by a tiny bit --- MCGalaxy/Generator/fCraft/MapGen.cs | 15 ++++++++------- MCGalaxy/Generator/fCraft/Noise.cs | 13 ++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MCGalaxy/Generator/fCraft/MapGen.cs b/MCGalaxy/Generator/fCraft/MapGen.cs index 0af2cba5f..8cd857650 100644 --- a/MCGalaxy/Generator/fCraft/MapGen.cs +++ b/MCGalaxy/Generator/fCraft/MapGen.cs @@ -59,7 +59,7 @@ namespace MCGalaxy.Generator { heightmap = new float[_width * _length]; noise.PerlinNoise( heightmap, _width, _length, - args.FeatureScale, args.DetailScale, args.Roughness, 0, 0 ); + args.FeatureScale, args.DetailScale, args.Roughness ); if( args.UseBias && !args.DelayBias ) { ReportProgress( 2, "Heightmap: Biasing" ); @@ -147,7 +147,7 @@ namespace MCGalaxy.Generator { int blendmapDetailSize = (int)Math.Log( Math.Max( _width, _length ), 2 ) - 2; new Noise( rand.Next(), NoiseInterpolationMode.Cosine ) - .PerlinNoise( altmap, _width, _length, 3, blendmapDetailSize, 0.5f, 0, 0 ); + .PerlinNoise( altmap, _width, _length, 3, blendmapDetailSize, 0.5f ); Noise.Normalize( altmap, -1, 1 ); } @@ -181,7 +181,7 @@ namespace MCGalaxy.Generator { if( heightmap[i] < desiredWaterLevel ) { float depth = args.MaxDepth; if( altmap != null ) { - depth += altmap[i] * args.MaxDepthVariation; + depth += altmap[i] * args.MaxDepthVariation; } slope = slopemap[i] * depth; level = args.WaterLevel - (int)Math.Round( Math.Pow( 1 - heightmap[i] / desiredWaterLevel, args.BelowFuncExponent ) * depth ); @@ -331,15 +331,16 @@ namespace MCGalaxy.Generator { Random rn = new Random(); short[,] shadows = ComputeHeightmap( map ); + int width = _width, length = _length; - for( int x = 0; x < map.Width; x += rn.Next( minTrunkPadding, maxTrunkPadding + 1 ) ) { - for( int z = 0; z < map.Length; z += rn.Next( minTrunkPadding, maxTrunkPadding + 1 ) ) { + for( int x = 0; x < width; x += rn.Next( minTrunkPadding, maxTrunkPadding + 1 ) ) { + for( int z = 0; z < length; z += rn.Next( minTrunkPadding, maxTrunkPadding + 1 ) ) { int nx = x + rn.Next( -(minTrunkPadding / 2), (maxTrunkPadding / 2) + 1 ); int nz = z + rn.Next( -(minTrunkPadding / 2), (maxTrunkPadding / 2) + 1 ); - if( nx < 0 || nx >= map.Width || nz < 0 || nz >= map.Length ) continue; + if( nx < 0 || nx >= width || nz < 0 || nz >= length ) continue; int ny = shadows[nx, nz]; - if( (map.GetBlock( (ushort)nx, (ushort)ny, (ushort)nz ) == bGroundSurface) && slopemap[nx * _length + nz] < .5 ) { + if( (map.GetBlock( (ushort)nx, (ushort)ny, (ushort)nz ) == bGroundSurface) && slopemap[nx * length + nz] < .5 ) { // Pick a random height for the tree between Min and Max, // discarding this tree if it would breach the top of the map int nh; diff --git a/MCGalaxy/Generator/fCraft/Noise.cs b/MCGalaxy/Generator/fCraft/Noise.cs index 08c5d1250..30e1178a2 100644 --- a/MCGalaxy/Generator/fCraft/Noise.cs +++ b/MCGalaxy/Generator/fCraft/Noise.cs @@ -109,13 +109,12 @@ namespace MCGalaxy.Generator { } - public void PerlinNoise( float[] map, int width, int length, - int startOctave, int endOctave, float decay, int offsetX, int offsetY ) { + public void PerlinNoise( float[] map, int width, int length, int startOctave, int endOctave, float decay ) { float maxDim = 1f / Math.Max( width, length ); for( int x = 0, i = 0; x < width; x++ ) for( int y = 0; y < length; y++ ) { - map[i++] += PerlinNoise( x * maxDim + offsetX, y * maxDim + offsetY, startOctave, endOctave, decay ); + map[i++] += PerlinNoise( x * maxDim, y * maxDim, startOctave, endOctave, decay ); } } @@ -202,7 +201,7 @@ namespace MCGalaxy.Generator { heightmap[i - X2 + Y2] + heightmap[i - X1 + Y2] * 4 + heightmap[i + Y2] * 7 + heightmap[i + X1 + Y2] * 4 + heightmap[i + X2 + Y2] ) * GaussianBlurDivisor; } - i++; + i++; } return output; } @@ -218,7 +217,7 @@ namespace MCGalaxy.Generator { if( x == 0 || y == 0 || x == width - 1 || y == length - 1 ) { output[i] = 0; } else { - float origin = heightmap[i]; + float origin = heightmap[i]; output[i] = (Math.Abs( heightmap[i - X1] - origin ) * 3 + Math.Abs( heightmap[i + Y1] - origin ) * 3 + Math.Abs( heightmap[i - X1] - origin ) * 3 + @@ -228,7 +227,7 @@ namespace MCGalaxy.Generator { Math.Abs( heightmap[x - X1 + Y1] - origin ) * 2 + Math.Abs( heightmap[x + X1 + Y1] - origin ) * 2) / 20f; } - i++; + i++; } return output; @@ -258,7 +257,7 @@ namespace MCGalaxy.Generator { int coveredVoxels = 0; for( int i = 0; i < data.Length; i++ ) { - if( data[i] < threshold ) coveredVoxels++; + if( data[i] < threshold ) coveredVoxels++; } return coveredVoxels / (float)data.Length; }