/// <summary> /// Gets the chunk at the target chunk position. /// </summary> /// <param name="chunkPos">The chunk position.</param> /// <param name="create">Whether or not to create the chunk if it doesn't currently exist.</param> /// <returns>The chunk, or null if it doesn't exist.</returns> private Chunk GetChunk(ChunkPosition chunkPos, bool create) { var chunk = World.GetChunk(chunkPos); if (chunk != null || !create) { return(chunk); } chunk = World.CreateChunk(chunkPos); bool remesh = ChunkLoader.LoadSync(chunk); if (remesh) { m_DirtyChunks.Add(chunkPos); m_DirtyChunks.Add(chunkPos.ShiftAlongDirection(0)); m_DirtyChunks.Add(chunkPos.ShiftAlongDirection(1)); m_DirtyChunks.Add(chunkPos.ShiftAlongDirection(2)); m_DirtyChunks.Add(chunkPos.ShiftAlongDirection(3)); m_DirtyChunks.Add(chunkPos.ShiftAlongDirection(4)); m_DirtyChunks.Add(chunkPos.ShiftAlongDirection(5)); RemeshDirtyChunks(); } return(chunk); }
/// <summary> /// Requests the chunk at the given position to start loading in the background. /// </summary> /// <param name="chunkPos">The chunk position.</param> /// <returns>True if the operation was started. False if the chunk is already loaded.</returns> public bool LoadChunkAsync(ChunkPosition chunkPos) { var chunk = World.GetChunk(chunkPos); if (chunk != null) { return(false); } chunk = World.CreateChunk(chunkPos); ChunkLoader.LoadAsync(chunk); return(true); }
/// <summary> /// Creates a new world container for the given world. /// </summary> /// <param name="world">The world.</param> /// <param name="world">The world.</param> internal WorldContainer(WorldProperties worldProperties) { World = new World(worldProperties.ChunkSize, worldProperties.ID); BlockList = new ServerBlockList(); EventQueue = new EventQueue(); ChunkLoader = new ChunkLoader(); ChunkLoader.AddChunkLoadHandler(new WorldLoader(World.ID)); ChunkLoader.AddChunkLoadHandler(worldProperties.WorldGenerator); WorldSaver = new WorldSaver(World.ID); RemeshHandler = new RemeshHandler(); RemeshHandler.AddDistributor(new StandardDistributor(World.ChunkSize, BlockList)); }