mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-19 04:07:10 -04:00
Improve performance by a tiny bit
This commit is contained in:
parent
c6303e43ea
commit
814d3ea889
@ -59,7 +59,7 @@ namespace MCGalaxy.Generator {
|
|||||||
heightmap = new float[_width * _length];
|
heightmap = new float[_width * _length];
|
||||||
|
|
||||||
noise.PerlinNoise( heightmap, _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 ) {
|
if( args.UseBias && !args.DelayBias ) {
|
||||||
ReportProgress( 2, "Heightmap: Biasing" );
|
ReportProgress( 2, "Heightmap: Biasing" );
|
||||||
@ -147,7 +147,7 @@ namespace MCGalaxy.Generator {
|
|||||||
int blendmapDetailSize = (int)Math.Log( Math.Max( _width, _length ), 2 ) - 2;
|
int blendmapDetailSize = (int)Math.Log( Math.Max( _width, _length ), 2 ) - 2;
|
||||||
|
|
||||||
new Noise( rand.Next(), NoiseInterpolationMode.Cosine )
|
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 );
|
Noise.Normalize( altmap, -1, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ namespace MCGalaxy.Generator {
|
|||||||
if( heightmap[i] < desiredWaterLevel ) {
|
if( heightmap[i] < desiredWaterLevel ) {
|
||||||
float depth = args.MaxDepth;
|
float depth = args.MaxDepth;
|
||||||
if( altmap != null ) {
|
if( altmap != null ) {
|
||||||
depth += altmap[i] * args.MaxDepthVariation;
|
depth += altmap[i] * args.MaxDepthVariation;
|
||||||
}
|
}
|
||||||
slope = slopemap[i] * depth;
|
slope = slopemap[i] * depth;
|
||||||
level = args.WaterLevel - (int)Math.Round( Math.Pow( 1 - heightmap[i] / desiredWaterLevel, args.BelowFuncExponent ) * 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();
|
Random rn = new Random();
|
||||||
short[,] shadows = ComputeHeightmap( map );
|
short[,] shadows = ComputeHeightmap( map );
|
||||||
|
int width = _width, length = _length;
|
||||||
|
|
||||||
for( int x = 0; x < map.Width; x += rn.Next( minTrunkPadding, maxTrunkPadding + 1 ) ) {
|
for( int x = 0; x < width; x += rn.Next( minTrunkPadding, maxTrunkPadding + 1 ) ) {
|
||||||
for( int z = 0; z < map.Length; z += 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 nx = x + rn.Next( -(minTrunkPadding / 2), (maxTrunkPadding / 2) + 1 );
|
||||||
int nz = z + 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];
|
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,
|
// Pick a random height for the tree between Min and Max,
|
||||||
// discarding this tree if it would breach the top of the map
|
// discarding this tree if it would breach the top of the map
|
||||||
int nh;
|
int nh;
|
||||||
|
@ -109,13 +109,12 @@ namespace MCGalaxy.Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void PerlinNoise( float[] map, int width, int length,
|
public void PerlinNoise( float[] map, int width, int length, int startOctave, int endOctave, float decay ) {
|
||||||
int startOctave, int endOctave, float decay, int offsetX, int offsetY ) {
|
|
||||||
float maxDim = 1f / Math.Max( width, length );
|
float maxDim = 1f / Math.Max( width, length );
|
||||||
for( int x = 0, i = 0; x < width; x++ )
|
for( int x = 0, i = 0; x < width; x++ )
|
||||||
for( int y = 0; y < length; y++ )
|
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]
|
heightmap[i - X2 + Y2] + heightmap[i - X1 + Y2] * 4 + heightmap[i + Y2] * 7 + heightmap[i + X1 + Y2] * 4 + heightmap[i + X2 + Y2]
|
||||||
) * GaussianBlurDivisor;
|
) * GaussianBlurDivisor;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -218,7 +217,7 @@ namespace MCGalaxy.Generator {
|
|||||||
if( x == 0 || y == 0 || x == width - 1 || y == length - 1 ) {
|
if( x == 0 || y == 0 || x == width - 1 || y == length - 1 ) {
|
||||||
output[i] = 0;
|
output[i] = 0;
|
||||||
} else {
|
} else {
|
||||||
float origin = heightmap[i];
|
float origin = heightmap[i];
|
||||||
output[i] = (Math.Abs( heightmap[i - X1] - origin ) * 3 +
|
output[i] = (Math.Abs( heightmap[i - X1] - origin ) * 3 +
|
||||||
Math.Abs( heightmap[i + Y1] - origin ) * 3 +
|
Math.Abs( heightmap[i + Y1] - origin ) * 3 +
|
||||||
Math.Abs( heightmap[i - X1] - 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 +
|
||||||
Math.Abs( heightmap[x + X1 + Y1] - origin ) * 2) / 20f;
|
Math.Abs( heightmap[x + X1 + Y1] - origin ) * 2) / 20f;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -258,7 +257,7 @@ namespace MCGalaxy.Generator {
|
|||||||
int coveredVoxels = 0;
|
int coveredVoxels = 0;
|
||||||
|
|
||||||
for( int i = 0; i < data.Length; i++ ) {
|
for( int i = 0; i < data.Length; i++ ) {
|
||||||
if( data[i] < threshold ) coveredVoxels++;
|
if( data[i] < threshold ) coveredVoxels++;
|
||||||
}
|
}
|
||||||
return coveredVoxels / (float)data.Length;
|
return coveredVoxels / (float)data.Length;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user