Exemple #1
0
        private int SerializeHeader(WorldData world)
        {
            WorldHeader header = world.GetHeader();

            writer.Write(header.name);
            writer.Write(header.width);
            writer.Write(header.height);
            writer.Write(header.spawnArea.X);
            writer.Write(header.spawnArea.Y);

            return((int)writer.BaseStream.Position);
        }
Exemple #2
0
        private void SerializeSectionPointers(WorldData world, int[] pointers)
        {
            writer.BaseStream.Position = 0L;

            WorldHeader header = world.GetHeader();

            writer.Write(world.GetVersion());
            writer.Write((byte)pointers.Length);

            for (int i = 0; i < pointers.Length; i++)
            {
                writer.Write(pointers[i]);
            }
        }
Exemple #3
0
        private void DeserializeWorldHeader(WorldData worldData)
        {
            worldData.SetName(reader.ReadString());
            int width  = reader.ReadInt32();
            int height = reader.ReadInt32();
            int spawnX = reader.ReadInt32();
            int spawnY = reader.ReadInt32();

            WorldHeader header = new WorldHeader();

            header.width     = width;
            header.height    = height;
            header.spawnArea = new Rectangle(spawnX, spawnY, Config.SPAWN_AREA_SIZE, Config.SPAWN_AREA_SIZE);
            worldData.SetHeader(header);
        }
Exemple #4
0
        // Generates an empty world based on the given header
        public WorldData(WorldHeader _header)
        {
            header = _header;

            int chunkWidth  = (header.width / Config.CHUNK_SIZE);
            int chunkHeight = (header.height / Config.CHUNK_SIZE);

            chunks       = new Chunk[chunkWidth * chunkHeight];
            loadedChunks = new Dictionary <int, Chunk>();

            for (int i = 0; i < (chunkWidth * chunkHeight); i++)
            {
                chunks[i] = new Chunk();
            }
        }
Exemple #5
0
        public void Serialize(WorldData world)
        {
            WorldHeader header = world.GetHeader();

            string dir = Path.Combine(Config.WorldSaveDirectory, header.name);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            fileStream = new FileStream(Path.Combine(dir, header.name + fileExtension), FileMode.Create, FileAccess.Write);
            writer     = new BinaryWriter(fileStream);
            int[] sectionPointers = new int[numSections];

            sectionPointers[0] = BlockOutSectionPointer(world);
            sectionPointers[1] = SerializeHeader(world);
            sectionPointers[2] = SerializeChunks(world);
            SerializeSectionPointers(world, sectionPointers);

            writer.Close();
            fileStream.Close();
        }
Exemple #6
0
 public void GenerateEmptyWorld(WorldHeader header)
 {
     // used for client in networked games. Generates an empty world based on the given WorldHeader
     worldData = new WorldData(header);
 }
Exemple #7
0
 public void SetHeader(WorldHeader value)
 {
     header = value;
 }