/* ========================= */ /* ===== OLD FUNCTIONS ===== */ /* ========================= */ void CreateHeightmap() { CombinedNoise n1 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); CombinedNoise n2 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); OctaveNoise n3 = new OctaveNoise(6, rnd); int index = 0; short[] hMap = new short[Width * Length]; CurrentState = "Building heightmap"; for (int z = 0; z < Length; z++) { CurrentProgress = (float)z / Length; for (int x = 0; x < Width; x++) { double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4, height = hLow; double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6; if (n3.Compute(x, z) <= 0) { height = Math.Max(hLow, hHigh); } /*if (x == 135 && z == 138) { * double nose = n3.Compute(x, z) / 8; * Console.WriteLine(nose.ToString()); * }*/ height *= 0.5; if (height < 0) { height *= 0.8f; } double erode = n3.Compute(x, z); //if (n3.Compute(x, z) > 3.0 && hHigh < hLow) { if (erode / 8 <= hLow && Closer(hLow, hHigh, erode / 4) == hLow && erode >= 0) { //if (n3.Compute(x * 1.3, z * 1.3) / 6 < -0.5 || n3.Compute(x * 1.3, z * 1.3) / 6 > 1.5) { if ((short)height % 2 != 0 && (short)height > 0) { height -= 1; } } short adjHeight = (short)(height + waterLevel); minHeight = adjHeight < minHeight ? adjHeight : minHeight; hMap[index++] = adjHeight; } } heightmap = hMap; }
void CreateHeightmap() { Noise n1 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); Noise n2 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); Noise n3 = new OctaveNoise(6, rnd); int index = 0; short[] hMap = new short[width * length]; CurrentState = "Building heightmap"; for (int z = 0; z < length; z++) { CurrentProgress = (float)z / length; for (int x = 0; x < width; x++) { double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4; double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6; double height = n3.Compute(x, z) > 0 ? hLow : Math.Max(hLow, hHigh); height *= 0.5; if (height < 0) { height *= 0.8f; } hMap[index++] = (short)(height + waterLevel); } } heightmap = hMap; }
void CreateSurfaceLayer() { OctaveNoise n1 = new OctaveNoise(8, rnd), n2 = new OctaveNoise(8, rnd); CurrentState = "Creating surface"; // TODO: update heightmap int hMapIndex = 0; for (int z = 0; z < Length; z++) { CurrentProgress = (float)z / Length; for (int x = 0; x < Width; x++) { int y = heightmap[hMapIndex++]; if (y < 0 || y >= Height) { continue; } int index = (y * Length + z) * Width + x; BlockID blockAbove = y >= (Height - 1) ? Block.Air : blocks[index + oneY]; if (blockAbove == Block.Water && (n2.Compute(x, z) > 12)) { blocks[index] = Block.Gravel; } else if (blockAbove == Block.Air) { blocks[index] = (y <= waterLevel && (n1.Compute(x, z) > 8)) ? Block.Sand : Block.Grass; } } } }
void CreateStrata() { OctaveNoise n = new OctaveNoise(8, rnd); CurrentState = "Creating strata"; int hMapIndex = 0, maxY = Height - 1, mapIndex = 0; // Try to bulk fill bottom of the map if possible int minStoneY = CreateStrataFast(); for (int z = 0; z < Length; z++) { for (int x = 0; x < Width; x++) { int dirtThickness = (int)(n.Compute(x, z) / 24 - 4); int dirtHeight = heightmap[hMapIndex++]; int stoneHeight = dirtHeight + dirtThickness; stoneHeight = Math.Min(stoneHeight, maxY); dirtHeight = Math.Min(dirtHeight, maxY); mapIndex = minStoneY * oneY + z * Width + x; for (int y = minStoneY; y <= stoneHeight; y++) { blocks[mapIndex] = Block.Stone; mapIndex += oneY; } stoneHeight = Math.Max(stoneHeight, 0); mapIndex = (stoneHeight + 1) * oneY + z * Width + x; for (int y = stoneHeight + 1; y <= dirtHeight; y++) { blocks[mapIndex] = Block.Dirt; mapIndex += oneY; } } } }
void CreateSurfaceLayer() { Noise n1 = new OctaveNoise(8, rnd), n2 = new OctaveNoise(8, rnd); CurrentState = "Creating surface"; // TODO: update heightmap int hMapIndex = 0; for (int z = 0; z < length; z++) { CurrentProgress = (float)z / length; for (int x = 0; x < width; x++) { bool sand = n1.Compute(x, z) > 8; bool gravel = n2.Compute(x, z) > 12; int y = heightmap[hMapIndex++]; if (y >= height) { continue; } int index = (y * length + z) * width + x; byte blockAbove = y >= (height - 1) ? Block.Air : blocks[index + oneY]; if (blockAbove == Block.Water && gravel) { blocks[index] = Block.Gravel; } else if (blockAbove == Block.Air) { blocks[index] = (y <= waterLevel && sand) ? Block.Sand : Block.Grass; } } } }
void CreateChunkSurfaceLayer(int chunkX, int chunkZ, OctaveNoise n1, OctaveNoise n2) { CurrentState = "Creating surface"; // TODO: update heightmap int offsetX = (chunkX * 16); int offsetZ = (chunkZ * 16); for (int z = 0; z < 16; z++) { int zCur = z + offsetZ; CurrentProgress = (float)z / Length; for (int x = 0; x < 16; x++) { int xCur = x + offsetX; int hMapIndex = zCur * Width + xCur; int y = heightmap[hMapIndex]; if (y < 0 || y >= Height) { continue; } int index = (y * Length + zCur) * Width + xCur; BlockRaw blockAbove = y >= (Height - 1) ? Block.Air : blocks[index + oneY]; if (blockAbove == Block.Water && (n2.Compute(xCur, zCur) > 12)) { blocks[index] = Block.Gravel; } else if (blockAbove == Block.Air) { blocks[index] = (y <= waterLevel && (n1.Compute(xCur, zCur) > 8)) ? Block.Sand : Block.Grass; } } } }
void CreateChunkHeightmap(int chunkX, int chunkZ, CombinedNoise n1, CombinedNoise n2, OctaveNoise n3) { /*CombinedNoise n1 = new CombinedNoise( * new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); * CombinedNoise n2 = new CombinedNoise( * new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); * OctaveNoise n3 = new OctaveNoise(6, rnd);*/ int index = 0; //short[] hMap = new short[16 * 16]; int offsetX = (chunkX * 16); int offsetZ = (chunkZ * 16); CurrentState = "Building heightmap"; for (int z = 0; z < 16; z++) { int zCur = z + offsetZ; CurrentProgress = (float)z / Length; for (int x = 0; x < 16; x++) { int xCur = x + offsetX; if (xCur >= Width || zCur >= Length) { break; } double hLow = n1.Compute(xCur * 1.3f, zCur * 1.3f) / 6 - 4, height = hLow; if (n3.Compute(xCur, zCur) <= 0) { double hHigh = n2.Compute(xCur * 1.3f, zCur * 1.3f) / 5 + 6; height = Math.Max(hLow, hHigh); } height *= 0.5; if (height < 0) { height *= 0.8f; } short adjHeight = (short)(height + waterLevel); minHeight = adjHeight < minHeight ? adjHeight : minHeight; index = zCur * Width + xCur; heightmap[index] = adjHeight; } } //heightmap = hMap; }
void CreateStrata() { Noise n = new OctaveNoise(8, rnd); CurrentState = "Creating strata"; int hMapIndex = 0; for (int z = 0; z < length; z++) { CurrentProgress = (float)z / length; for (int x = 0; x < width; x++) { int dirtThickness = (int)(n.Compute(x, z) / 24 - 4); int dirtHeight = heightmap[hMapIndex++]; int stoneHeight = dirtHeight + dirtThickness; int mapIndex = z * width + x; blocks[mapIndex] = (byte)Block.Lava; mapIndex += oneY; for (int y = 1; y < height; y++) { byte type = 0; if (y <= stoneHeight) { type = (byte)Block.Stone; } else if (y <= dirtHeight) { type = (byte)Block.Dirt; } blocks[mapIndex] = type; mapIndex += oneY; } } } }
void CreateChunkStrata(int chunkX, int chunkZ, OctaveNoise n) { CurrentState = "Creating strata"; int hMapIndex = 0, maxY = Height - 1, mapIndex = 0; // Try to bulk fill bottom of the map if possible int minStoneY = CreateChunkStrataFast(chunkX, chunkZ); int offsetX = (chunkX * 16); int offsetZ = (chunkZ * 16); for (int z = 0; z < 16; z++) { int zCur = z + offsetZ; CurrentProgress = (float)z / Length; for (int x = 0; x < 16; x++) { int xCur = x + offsetX; int index = zCur * Width + xCur; int dirtThickness = (int)(n.Compute(x, z) / 24 - 4); int dirtHeight = heightmap[index]; int stoneHeight = dirtHeight + dirtThickness; stoneHeight = Math.Min(stoneHeight, maxY); dirtHeight = Math.Min(dirtHeight, maxY); mapIndex = minStoneY * oneY + zCur * Width + xCur; for (int y = minStoneY; y <= stoneHeight; y++) { blocks[mapIndex] = Block.Stone; mapIndex += oneY; } stoneHeight = Math.Max(stoneHeight, 0); mapIndex = (stoneHeight + 1) * oneY + zCur * Width + xCur; for (int y = stoneHeight + 1; y <= dirtHeight; y++) { blocks[mapIndex] = Block.Dirt; mapIndex += oneY; } } } }
void CreateHeightmap() { CombinedNoise n1 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); CombinedNoise n2 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); OctaveNoise n3 = new OctaveNoise(6, rnd); int index = 0; short[] hMap = new short[Width * Length]; CurrentState = "Building heightmap"; for (int z = 0; z < Length; z++) { CurrentProgress = (float)z / Length; for (int x = 0; x < Width; x++) { double hLow = n1.Compute(x * 1.3f, z * 1.3f) / 6 - 4, height = hLow; if (n3.Compute(x, z) <= 0) { double hHigh = n2.Compute(x * 1.3f, z * 1.3f) / 5 + 6; height = Math.Max(hLow, hHigh); } height *= 0.5; if (height < 0) { height *= 0.8f; } short adjHeight = (short)(height + waterLevel); minHeight = adjHeight < minHeight ? adjHeight : minHeight; hMap[index++] = adjHeight; } } heightmap = hMap; }
public double Compute(double x, double y) { double offset = noise2.Compute(x, y); return(noise1.Compute(x + offset, y)); }
void CreateSurfaceLayer() { Noise n1 = new OctaveNoise( 8, rnd ), n2 = new OctaveNoise( 8, rnd ); CurrentState = "Creating surface"; // TODO: update heightmap int hMapIndex = 0; for( int z = 0; z < length; z++ ) { CurrentProgress = (float)z / length; for( int x = 0; x < width; x++ ) { bool sand = n1.Compute( x, z ) > 8; bool gravel = n2.Compute( x, z ) > 12; int y = heightmap[hMapIndex++]; if( y >= height ) continue; int index = (y * length + z) * width + x; byte blockAbove = y >= (height - 1) ? (byte)0 : blocks[index + oneY]; if( blockAbove == (byte)Block.Water && gravel ) { blocks[index] = (byte)Block.Gravel; } else if( blockAbove == 0 ) { blocks[index] = (y <= waterLevel && sand) ? (byte)Block.Sand : (byte)Block.Grass; } } } }
void CreateStrata() { Noise n = new OctaveNoise( 8, rnd ); CurrentState = "Creating strata"; int hMapIndex = 0; for( int z = 0; z < length; z++ ) { CurrentProgress = (float)z / length; for( int x = 0; x < width; x++ ) { int dirtThickness = (int)(n.Compute( x, z ) / 24 - 4); int dirtHeight = heightmap[hMapIndex++]; int stoneHeight = dirtHeight + dirtThickness; int mapIndex = z * width + x; blocks[mapIndex] = (byte)Block.Lava; mapIndex += oneY; for( int y = 1; y < height; y++ ) { byte type = 0; if( y <= stoneHeight ) type = (byte)Block.Stone; else if( y <= dirtHeight ) type = (byte)Block.Dirt; blocks[mapIndex] = type; mapIndex += oneY; } } } }
void CreateHeightmap() { Noise n1 = new CombinedNoise( new OctaveNoise( 8, rnd ), new OctaveNoise( 8, rnd ) ); Noise n2 = new CombinedNoise( new OctaveNoise( 8, rnd ), new OctaveNoise( 8, rnd ) ); Noise n3 = new OctaveNoise( 6, rnd ); int index = 0; short[] hMap = new short[width * length]; CurrentState = "Building heightmap"; for( int z = 0; z < length; z++ ) { CurrentProgress = (float)z / length; for( int x = 0; x < width; x++ ) { double hLow = n1.Compute( x * 1.3f, z * 1.3f ) / 6 - 4; double hHigh = n2.Compute( x * 1.3f, z * 1.3f ) / 5 + 6; double height = n3.Compute( x, z ) > 0 ? hLow : Math.Max( hLow, hHigh ); height *= 0.5; if( height < 0 ) height *= 0.8f; hMap[index++] = (short)(height + waterLevel); } } heightmap = hMap; }