public void GenerateSuperFlatTerrain(BlockTerrain.Chunk chunk) { GameInfo info = WorldManager.Project.GameInfo; int startx = chunk.chunkx << 4; int startz = chunk.chunkx << 4; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 128; y++) { if (y < info.TerrainLevel) { if (y <= 1) { chunk.SetCellValue(x, y, z, 1); } else if (startx + x >= 200 || startz + z >= 200) { chunk.SetCellValue(x, y, z, info.TerrainOceanBlockIndex); } else { chunk.SetCellValue(x, y, z, info.TerrainBlockIndex); } } } } } }
// public void SaveChunkEntries () // { // Point2[] entries = new Point2[chunkOffsets.Count]; // foreach (KeyValuePair<Point2, long> p in chunkOffsets) { // entries [(int)((p.Value - 786444L) / 132112L)] = p.Key; // } // // stream.Seek (0, SeekOrigin.Begin); // for (int i = 0; i < entries.Length; i++) { // WriteChunkEntry (stream, -entries [i].X, entries [i].Y, i); // } // } public unsafe void ReadChunk(int chunkx, int chunky, BlockTerrain.Chunk chunk) { lock (locker) { Point2 p = new Point2(chunkx, chunky); long value; if (chunkOffsets.TryGetValue(p, out value)) { stream.Seek(value, SeekOrigin.Begin); ReadChunkHeader(stream); stream.Read(buffer, 0, 131072); fixed(byte *bptr = &buffer[0]) { int *iptr = (int *)bptr; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { int index = BlockTerrain.GetCellIndex(15 - x, 0, y); int h = 0; while (h < 128) { chunk.SetCellValue(index, *iptr); iptr++; h++; index++; } } } } stream.Read(buffer, 0, 1024); fixed(byte *bptr = &buffer[0]) { int *iptr = (int *)bptr; for (int x = 0; x < 16; x++) { int index = BlockTerrain.GetShiftIndex(15 - x, 0); int h = 0; while (h < 16) { chunk.SetShiftValue(index, *iptr); iptr++; h++; index++; } } } } } }
public void ChangeCell(int x, int y, int z, int newValue) { int index = Terrain.GetChunkIndex(x >> 4, z >> 4); BlockTerrain.Chunk c = Terrain.GetChunk(index); BlockTerrain.ChunkStatics state = Terrain.chunkStats.Get(index); if (c != null) { int cx = x & 15; int cz = z & 15; int content = c.GetCellContent(cx, y, cz); if (content != 0) { state.state = 3; } content = BlockTerrain.GetContent(newValue); if (content != 0) { state.state = 3; } c.SetCellValue(cx, y, cz, newValue); c.isEdited = true; if (cx == 0 && c.XminusOne != null) { QuqueChunkUpdate(c.XminusOne.index, 3); } else if (cx == 15 && c.XplusOne != null) { QuqueChunkUpdate(c.XplusOne.index, 3); } if (cz == 0 && c.YminusOne != null) { QuqueChunkUpdate(c.YminusOne.index, 3); } else if (cz == 15 && c.YplusOne != null) { QuqueChunkUpdate(c.YplusOne.index, 3); } QuqueChunkUpdate(c.index); } }