private void EdgesInit() { edges = new ChunkEdge[4]; edges[(int)Direction.N] = new NorthEdge(); edges[(int)Direction.S] = new SouthEdge(); edges[(int)Direction.W] = new WestEdge(); edges[(int)Direction.E] = new EastEdge(); }
private ChunkEdge[] InitEdges() { ChunkEdge[] edges = new ChunkEdge[4]; edges[(int)Direction.N] = new NorthEdge(); edges[(int)Direction.S] = new SouthEdge(); edges[(int)Direction.W] = new WestEdge(); edges[(int)Direction.E] = new EastEdge(); return(edges); }
private void GenerateChunk(int x, int z) { //Debug.Log("TCG.GenerateChunk() => " + "[" + x + "," + z +"]"); if (Cache.ChunkCanBeAdded(x, z)) { ChunkEdge edgetype = CheckChunkIsEdge(new Vector2i(x, z)); var chunk = new TerrainChunk(Settings, WorldGenerator, edgetype, x, z); Cache.AddNewChunk(chunk); } }
public TerrainChunk(TerrainChunkSettings settings, WorldGenerator worldGenerator, ChunkEdge edgetype, int x, int z) { HeightmapThreadLockObject = new object(); WorldGenerator = worldGenerator; Settings = settings; EdgeType = edgetype; Biomes = new List <BiomeType>(); Neighborhood = new TerrainChunkNeighborhood(); Position = new Vector2i(x, z); }
public static float[,] GetEdgeMask(ChunkEdge edgetype) { float[,] mask = new float[2, 2]; float[,] scaledmask; switch (edgetype) { case ChunkEdge.TL: mask = new float[, ] { { 0, 0 }, { 0, 1 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); break; case ChunkEdge.T: mask = new float[, ] { { 0, 0 }, { 1, 1 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); for (int x = 0; x < 129; x++) { scaledmask[x, TerrainChunkSettings.ChunkSize - 1] = 1.0f; } break; case ChunkEdge.TR: mask = new float[, ] { { 0, 0 }, { 1, 0 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); break; case ChunkEdge.R: mask = new float[, ] { { 1, 0 }, { 1, 0 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); for (int z = 0; z < TerrainChunkSettings.ChunkSize; z++) { scaledmask[0, z] = 1.0f; } break; case ChunkEdge.BR: mask = new float[, ] { { 1, 0 }, { 0, 0 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); break; case ChunkEdge.B: mask = new float[, ] { { 1, 1 }, { 0, 0 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); for (int x = 0; x < TerrainChunkSettings.ChunkSize; x++) { scaledmask[x, 0] = 1.0f; } break; case ChunkEdge.BL: mask = new float[, ] { { 0, 1 }, { 0, 0 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); break; case ChunkEdge.L: mask = new float[, ] { { 0, 1 }, { 0, 1 } }; scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); for (int z = 0; z < TerrainChunkSettings.ChunkSize; z++) { scaledmask[TerrainChunkSettings.ChunkSize - 1, z] = 1.0f; } break; } scaledmask = MathUtils.BilinearInterpolationScale(mask, 129, 129); return(scaledmask); }
/// <summary> /// Checks chunks world position and applies height masking as nessecary /// to turn edge chunks into beaches /// </summary> /// <param name="Position">World Position of this chunk</param> /// <returns></returns> public ChunkEdge CheckChunkIsEdge(Vector2i Position) { ChunkEdge edgetype = ChunkEdge.NotEdge; var mapwidth = WorldGenerator.MAP_SIZE - 1; var mapheight = WorldGenerator.MAP_SIZE - 1; if (Position.X == (int)(mapwidth / 2) - mapwidth) //leftmost edge { if (Position.Z == (int)(mapheight / 2) - mapheight) { //top left edgetype = ChunkEdge.TL; } else if (Position.Z == (int)(mapheight / 2)) { //bottom left edgetype = ChunkEdge.BL; } else { //left edgetype = ChunkEdge.L; } } else if (Position.X == (int)(mapwidth / 2)) //right edge { if (Position.Z == (int)(mapheight / 2) - mapheight) { //top right edgetype = ChunkEdge.TR; } else if (Position.Z == (int)(mapheight / 2)) { //bottom right edgetype = ChunkEdge.BR; } else { //right edgetype = ChunkEdge.R; } } else if (Position.Z == (int)(mapheight / 2) - mapwidth) //top edge { if (Position.X == (int)(mapwidth / 2) - mapwidth) { //top left edgetype = ChunkEdge.TL; } else if (Position.X == (int)(mapwidth / 2)) { //top right edgetype = ChunkEdge.TR; } else { //top edgetype = ChunkEdge.T; } } else if (Position.Z == (int)(mapwidth / 2)) //bottom edge { if (Position.X == (int)(mapheight / 2) - mapheight) { //bottom left edgetype = ChunkEdge.BL; } else if (Position.X == (int)(mapheight / 2)) { //bottom right edgetype = ChunkEdge.BR; } else { //bottom edgetype = ChunkEdge.B; } } else { edgetype = ChunkEdge.NotEdge; } //Debug.Log("ctor: Chunk is " + edgetype); return(edgetype); }