示例#1
0
        public void SaveChunk(IChunk runtimeChunk)
        {
            using (var file = new FileStream(Path.Combine(this.m_Path, this.GetName(runtimeChunk)), FileMode.Create))
            {
                var size = this.m_ChunkSizePolicy.ChunkCellWidth * this.m_ChunkSizePolicy.ChunkCellHeight
                           * this.m_ChunkSizePolicy.ChunkCellDepth;
                var chunk = new Chunk
                {
                    X = runtimeChunk.X,
                    Y = runtimeChunk.Y,
                    Z = runtimeChunk.Z,
                    Cells = new Cell[size],
                    Indexes = runtimeChunk.GeneratedIndices,
                    Vertexes = new Vertex[runtimeChunk.GeneratedVertexes.Length]
                };

                chunk.Cells = runtimeChunk.Cells;

                for (var i = 0; i < runtimeChunk.GeneratedVertexes.Length; i++)
                {
                    chunk.Vertexes[i] = new Vertex
                    {
                        X = runtimeChunk.GeneratedVertexes[i].Position.X,
                        Y = runtimeChunk.GeneratedVertexes[i].Position.Y,
                        Z = runtimeChunk.GeneratedVertexes[i].Position.Z,
                        U = runtimeChunk.GeneratedVertexes[i].TextureCoordinate.X,
                        V = runtimeChunk.GeneratedVertexes[i].TextureCoordinate.Y,
                    };
                }

                var serializer = new TychaiaDataSerializer();
                serializer.Serialize(file, chunk);
            }
        }
示例#2
0
        public void SaveChunk(long chunkX, long chunkY, long chunkZ, Cell[,,] data)
        {
            using (
                var file = new FileStream(
                    Path.Combine(this.m_Path, this.GetName(chunkX, chunkY, chunkZ)),
                    FileMode.Create))
            {
                var size = this.m_ChunkSizePolicy.ChunkCellWidth * this.m_ChunkSizePolicy.ChunkCellHeight
                           * this.m_ChunkSizePolicy.ChunkCellDepth;
                var chunk = new Chunk
                {
                    X = chunkX,
                    Y = chunkY,
                    Z = chunkZ,
                    Cells = new Cell[size],
                    Indexes = new int[0],
                    Vertexes = new Vertex[0]
                };

                for (var x = 0; x < this.m_ChunkSizePolicy.ChunkCellWidth; x++)
                {
                    for (var y = 0; y < this.m_ChunkSizePolicy.ChunkCellHeight; y++)
                    {
                        for (var z = 0; z < this.m_ChunkSizePolicy.ChunkCellDepth; z++)
                        {
                            var idx = x;
                            idx += y * this.m_ChunkSizePolicy.ChunkCellWidth;
                            idx += z * this.m_ChunkSizePolicy.ChunkCellWidth * this.m_ChunkSizePolicy.ChunkCellHeight;
                            chunk.Cells[idx] = data[x, y, z];
                        }
                    }
                }

                var serializer = new TychaiaDataSerializer();
                serializer.Serialize(file, chunk);
            }
        }