public void SaveData() { Chunk chunk = GetComponent <Chunk>(); string compressedData = ChunkDataFiles.CompressData(chunk); WriteChunkData(chunk.ChunkIndex, compressedData); }
public static IEnumerator SaveAllChunks() { /*if (!Engine.SaveVoxelData) { * Debug.LogWarning ("Uniblocks: Saving is disabled. You can enable it in the Engine Settings."); * yield break; * }*/ while (ChunkDataFiles.SavingChunks) { yield return(new WaitForEndOfFrame()); } ChunkDataFiles.SavingChunks = true; // for each chunk object, save data to memory int count = 0; List <Chunk> chunksToSave = new List <Chunk>(ChunkManager.Chunks.Values); foreach (Chunk chunk in chunksToSave) { chunk.gameObject.GetComponent <ChunkDataFiles>().SaveData(); count++; if (count > Engine.MaxChunkSaves) { yield return(new WaitForEndOfFrame()); count = 0; } } // write data to disk ChunkDataFiles.WriteLoadedChunks(); ChunkDataFiles.SavingChunks = false; Debug.Log("Uniblocks: World saved successfully."); }
public void SendVoxelData(NetworkPlayer player, int chunkx, int chunky, int chunkz) { // >> You can check whether the request for voxel data is valid here << // if (true) { Chunk chunk = ChunkManager.SpawnChunkFromServer(chunkx, chunky, chunkz).GetComponent <Chunk>(); // get the chunk (spawn it if it's not spawned already) chunk.lifetime = 0f; // refresh the chunk's lifetime string data = ChunkDataFiles.CompressData(chunk); // get data from the chunk and compress it byte[] dataBytes = GetBytes(data); // convert to byte array (sending strings over RPC doesn't work too well) GetComponent <NetworkView>().RPC("ReceiveVoxelData", player, chunkx, chunky, chunkz, dataBytes); // send compressed data to the player who requested it // } }
public void ReceiveVoxelData(int chunkx, int chunky, int chunkz, byte[] data) { GameObject chunkObject = ChunkManager.GetChunk(chunkx, chunky, chunkz); // find the chunk if (chunkObject == null) { return; // abort if chunk isn't spawned anymore } Chunk chunk = chunkObject.GetComponent <Chunk>(); ChunkDataFiles.DecompressData(chunk, GetString(data)); // decompress data // ChunkManager.DataReceivedCount ++; // let ChunkManager know that we have received the data chunk.VoxelsDone = true; // let Chunk know that it can update it's mesh Chunk.CurrentChunkDataRequests--; }
public static Dictionary <string, string[]> LoadedRegions; // data of currently loaded regions public bool LoadData() // attempts to load data from file, returns false if data is not found { Chunk chunk = GetComponent <Chunk>(); string chunkData = GetChunkData(chunk.ChunkIndex); if (chunkData != "") { ChunkDataFiles.DecompressData(chunk, GetChunkData(chunk.ChunkIndex)); chunk.VoxelsDone = true; return(true); } else { return(false); } }
public static void SaveAllChunksInstant() { // writes data from TempChunkData into region files /*if (!Engine.SaveVoxelData) { * Debug.LogWarning ("Uniblocks: Saving is disabled. You can enable it in the Engine Settings."); * return; * }*/ // for each chunk object, save data to memory foreach (Chunk chunk in ChunkManager.Chunks.Values) { chunk.gameObject.GetComponent <ChunkDataFiles>().SaveData(); } // write data to disk ChunkDataFiles.WriteLoadedChunks(); Debug.Log("Uniblocks: World saved successfully. (Instant)"); }
public static void SaveWorldInstant() { ChunkDataFiles.SaveAllChunksInstant(); }
public static void SaveWorld() { // saves the data over multiple frames EngineInstance.StartCoroutine(ChunkDataFiles.SaveAllChunks()); }