コード例 #1
0
        public void Save(Stream stream, WorldDescription desc)
        {
            FixedTerrain terrain = desc.Terrain;

            using (BinaryWriter writer = new BinaryWriter(stream))
            {
                writer.Write(1.0f);
                writer.Write(terrain.Chunks.Count);

                foreach (Chunk chunk in terrain.Chunks.Values)
                {
                    writer.Write((ushort)chunk.IndexPosition.X);
                    writer.Write((ushort)chunk.IndexPosition.Y);
                    writer.Write((ushort)chunk.IndexPosition.Z);
                    writer.Write(false);
                    //if (!chunk.IsEmpty)
                    {
                        ushort skip = 0;

                        for (int x = 0; x < Chunk.HSIZE; x++)
                        {
                            for (int y = 0; y < Chunk.VSIZE; y++)
                            {
                                for (int z = 0; z < Chunk.HSIZE; z++)
                                {
                                    Block block = chunk.Blocks[z, y, x];
                                    //if (block != Block.AIR)
                                    {
                                        if (skip > 0)
                                        {
                                            writer.Write(true);
                                            writer.Write(skip);
                                            skip = 0;
                                        }

                                        writer.Write(block == Block.AIR);
                                        writer.Write(block.R);
                                        writer.Write(block.G);
                                        writer.Write(block.B);
                                        writer.Write(block.Data.Value);
                                    }
                                    //else
                                    //    skip++;
                                }
                            }
                        }

                        if (skip > 0)
                        {
                            writer.Write(true);
                            writer.Write(skip);
                            skip = 0;
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void Save(Stream stream, WorldDescription desc)
        {
            FixedTerrain terrain = desc.Terrain;

            using (GZipStream gz = new GZipStream(stream, CompressionMode.Compress))
                using (BinaryWriter writer = new BinaryWriter(gz))
                {
                    writer.Write(2.0f);

                    writer.Write((ushort)terrain.Chunks.Count);
                    foreach (Chunk chunk in terrain.Chunks.Values)
                    {
                        writer.Write((byte)0);
                        writer.Write((short)chunk.IndexPosition.X);
                        writer.Write((short)chunk.IndexPosition.Y);
                        writer.Write((short)chunk.IndexPosition.Z);

                        Block?lastBlock = null;
                        int   numRead   = 0;

                        for (int x = 0; x < chunk.Width; x++)
                        {
                            for (int y = 0; y < chunk.Height; y++)
                            {
                                for (int z = 0; z < chunk.Depth; z++)
                                {
                                    Block block      = chunk.Blocks[z, y, x];
                                    bool  blocksDiff = lastBlock.HasValue ? BlocksDifferent(block, lastBlock.Value) : false;

                                    if (blocksDiff)
                                    {
                                        Block b = lastBlock ?? block;
                                        WriteBlocks(writer, b, numRead);
                                        numRead = 0;
                                    }

                                    numRead++;
                                    lastBlock = block;
                                }
                            }
                        }

                        if (numRead > 0)
                        {
                            WriteBlocks(writer, lastBlock.Value, numRead);
                        }
                    }
                }
        }
コード例 #3
0
        public static void Save(string fileName, WorldDescription description,
                                bool useRelativePath = true, float version = 3.0f)
        {
            IWorldFileIO handler;

            if (ioHandlers.TryGetValue(version, out handler))
            {
                using (FileStream fs = File.Create(useRelativePath ? "Content/Worlds/" + fileName + ".aosw" : fileName))
                {
                    handler.Save(fs, description);
                }
            }
            else
            {
                throw new IOException("No world IO handler defined for version " + version + "!");
            }
        }