// Loads Chunk data, but doesn't draw them private void LoadChunk() { if (toLoad.Count > 0) { // Prevention if (toUnload.Contains(toLoad[0])) { toUnload.Remove(toLoad[0]); toLoad.RemoveAt(0); return; } if (chunks.ContainsKey(toLoad[0])) { toLoad.RemoveAt(0); return; } bool isPregen; // Gets correct region file regionHandler.GetCorrectRegion(toLoad[0]); // If current chunk toLoad was already generated if (regionHandler.IsIndexed(toLoad[0])) { isPregen = regionHandler.GetsNeedGeneration(toLoad[0]); // If chunk is Pre-Generated if (isPregen) { chunks.Add(toLoad[0], new Chunk(toLoad[0], this.rend, this.blockBook, this, fromMemory: true)); vfx.NewChunk(toLoad[0]); regionHandler.LoadChunk(chunks[toLoad[0]]); this.worldGen.SetVoxdata(chunks[toLoad[0]].data.GetData()); this.worldGen.SetCacheHP(chunks[toLoad[0]].metadata.GetHPData()); this.worldGen.SetCacheState(chunks[toLoad[0]].metadata.GetStateData()); chunks[toLoad[0]].BuildOnVoxelData(this.worldGen.AssignBiome(toLoad[0], pregen: true)); chunks[toLoad[0]].metadata = new VoxelMetadata(this.worldGen.GetCacheHP(), this.worldGen.GetCacheState()); chunks[toLoad[0]].needsGeneration = 0; regionHandler.SaveChunk(chunks[toLoad[0]]); } // If it's just a normally generated chunk else { chunks.Add(toLoad[0], new Chunk(toLoad[0], this.rend, this.blockBook, this, fromMemory: true)); vfx.NewChunk(toLoad[0]); regionHandler.LoadChunk(chunks[toLoad[0]]); chunks[toLoad[0]].needsGeneration = 0; } } // If it's a new chunk to be generated else { chunks.Add(toLoad[0], new Chunk(toLoad[0], this.rend, this.blockBook, this)); vfx.NewChunk(toLoad[0]); chunks[toLoad[0]].BuildOnVoxelData(this.worldGen.AssignBiome(toLoad[0])); chunks[toLoad[0]].metadata = new VoxelMetadata(this.worldGen.GetCacheHP(), this.worldGen.GetCacheState()); chunks[toLoad[0]].needsGeneration = 0; regionHandler.SaveChunk(chunks[toLoad[0]]); } toDraw.Add(toLoad[0]); toLoad.RemoveAt(0); } }
// Loads Chunk data, but doesn't draw them private void LoadChunk() { for (int i = 0; i < 3; i++) { if (toLoad.Count > 0) { // Prevention if (toUnload.Contains(toLoad[0])) { toUnload.Remove(toLoad[0]); toLoad.RemoveAt(0); return; } if (chunks.ContainsKey(toLoad[0])) { toLoad.RemoveAt(0); return; } bool isPregen; // Gets correct region file regionHandler.GetCorrectRegion(toLoad[0]); // If current chunk toLoad was already generated if (regionHandler.IsIndexed(toLoad[0])) { isPregen = regionHandler.GetsNeedGeneration(toLoad[0]); // If chunk is Pre-Generated if (isPregen) { chunks.Add(toLoad[0], new Chunk(toLoad[0], server: true)); vfx.NewChunk(toLoad[0], isServer: true); regionHandler.LoadChunk(chunks[toLoad[0]]); this.worldGen.ClearCaches(); this.worldGen.SetVoxdata(chunks[toLoad[0]].data.GetData()); this.worldGen.SetCacheHP(chunks[toLoad[0]].metadata.GetHPData()); this.worldGen.SetCacheState(chunks[toLoad[0]].metadata.GetStateData()); this.worldGen.GenerateChunk(toLoad[0], isPregen: true); chunks[toLoad[0]].biomeName = this.worldGen.GetCacheBiome(); chunks[toLoad[0]].BuildOnVoxelData(new VoxelData(this.worldGen.GetVoxdata())); chunks[toLoad[0]].metadata = new VoxelMetadata(this.worldGen.GetCacheHP(), this.worldGen.GetCacheState()); chunks[toLoad[0]].needsGeneration = 0; regionHandler.SaveChunk(chunks[toLoad[0]]); } // If it's just a normally generated chunk else { chunks.Add(toLoad[0], new Chunk(toLoad[0], server: true)); vfx.NewChunk(toLoad[0], isServer: true); regionHandler.LoadChunk(chunks[toLoad[0]]); chunks[toLoad[0]].needsGeneration = 0; } } // If it's a new chunk to be generated else { chunks.Add(toLoad[0], new Chunk(toLoad[0], server: true)); vfx.NewChunk(toLoad[0], isServer: true); this.worldGen.ClearCaches(); this.worldGen.GenerateChunk(toLoad[0]); chunks[toLoad[0]].BuildOnVoxelData(new VoxelData(this.worldGen.GetVoxdata())); chunks[toLoad[0]].metadata = new VoxelMetadata(this.worldGen.GetCacheHP(), this.worldGen.GetCacheState()); chunks[toLoad[0]].needsGeneration = 0; chunks[toLoad[0]].biomeName = this.worldGen.GetCacheBiome(); regionHandler.SaveChunk(chunks[toLoad[0]]); } SendChunkToRequestingClients(toLoad[0]); toLoad.RemoveAt(0); } } }