예제 #1
0
        public static Dictionary <string, string> SerializeAll()
        {
            var filesToWrite = new Dictionary <string, string>();

            foreach (var kvp in _dirtyChunks)
            {
                var fileName = kvp.Key.ToString();
                var data     = new SerializableChunk(kvp.Value).Serialize();
                filesToWrite.Add(fileName, data);
            }

            foreach (var kvp in _dirtyBuilders)
            {
                var fileName = kvp.Key.ToString() + "B";
                var data     = new SerializableChunkBuilder(kvp.Value).Serialize();
                filesToWrite.Add(fileName, data);
            }

            foreach (var kvp in _dirtySpaces)
            {
                var fileName = kvp.Key;
                var data     = SerializableSpaceHelper.ToSerializableSpace(kvp.Value).Serialize();
                filesToWrite.Add(fileName, data);
            }

            var characterFile = new SerializableCharacter(CurrentCharacter);

            filesToWrite.Add(Paths.CHARACTERFILE, characterFile.Serialize());

            return(filesToWrite);
        }
예제 #2
0
        private Chunk LoadChunk(IntVector2 worldPosition)
        {
            var serializedChunk   = DataReader.Read(worldPosition.ToString(), DataTypes.CurrentGame);
            var serializableChunk = SerializableChunk.Deserialize(serializedChunk);

            var chunk = serializableChunk.ToObject();
            var chunkActivationCommand = new ChunkActivationCommand(chunk, serializableChunk.ReconstructCoroutine);

            _chunkActivationCommands.Enqueue(chunkActivationCommand);

            return(chunk);
        }
예제 #3
0
    private void saveWorldData(World world)
    {
        List <SerializableChunk> chunks = new List <SerializableChunk>();

        foreach (KeyValuePair <int, Chunk> pair in world.chunks)
        {
            // create the savable chunk from the current chunk
            SerializableChunk addingChunk = new SerializableChunk {
            };
            //addingChunk.tileIDs = pair.Value.tileIDs;
            addingChunk.biomeID = pair.Value.biomeRefrence.refrence;
            addingChunk.chunkX  = pair.Value.chunkX;
            addingChunk.chunkY  = pair.Value.chunkY;
            addingChunk.seed    = pair.Value.seed;

            // add that savable to the chunk list
            chunks.Add(addingChunk);
        }

        savedData.chunks = chunks.ToArray();
    }
예제 #4
0
    void serializeChunkData(SerializableChunk copyTo, WorldChunk copyFrom)
    {
        // save indexes
        copyTo.x = copyFrom.getX();
        copyTo.z = copyFrom.getZ();

        // save chunk sectors
        WorldSector[,] sectors = copyFrom.getAllSectors();
        for (int i = 0; i < GameSettings.LoadedConfig.ChunkLength_Sectors*GameSettings.LoadedConfig.ChunkLength_Sectors; ++i) {
            copyTo.sectors.Add(new SerializableSector());

            int sx = i%GameSettings.LoadedConfig.ChunkLength_Sectors;
            int sz = Mathf.FloorToInt(i/GameSettings.LoadedConfig.ChunkLength_Sectors);
            serializeSectorData(copyTo.sectors[i], sectors[sx, sz]);
        }
    }
    public void CreateChunks(int width, int height, int levels)
    {
        if(Chunks != null)
            return;

        Width = width;
        Height = height;
        Levels = levels;

        int count = width * height;
        Chunks = new SerializableChunk[count];
        for(int i = 0; i < Chunks.Length; ++i)
        {
            Chunks[i] = new SerializableChunk();
        }
    }
예제 #6
0
 public DecodableChunk(SerializableChunk chunk, Vector2i pos)
 {
     this.chunk = chunk;
     this.pos   = pos;
 }
예제 #7
0
    public void restoreChunkData(SerializableChunk restoreFrom)
    {
        if (restoreFrom == null) {
            throw new InvalidOperationException("SerializableChunk is null.");
        }

        // restore sectors
        for (int sector_x = 0; sector_x < GameSettings.LoadedConfig.ChunkLength_Sectors; ++sector_x) {
            for (int sector_z = 0; sector_z < GameSettings.LoadedConfig.ChunkLength_Sectors; ++sector_z) {
                SerializableSector loadedSector = restoreFrom.sectors[
                    sector_z * GameSettings.LoadedConfig.ChunkLength_Sectors + sector_x
                ];
                sectors[sector_x, sector_z].restoreSectorData(loadedSector);
            }
        }
    }