/// <summary> /// Called when the BlockWorld behaviour is enabled. /// </summary> private void OnEnable() { if (m_WorldContainer != null) { return; // Already enabled } var chunkSize = new GridSize(4); var world = new World(chunkSize); var blockList = new BlockTypeList(); var remesh = new RemeshHandler(); var database = new WorldDatabase("/home/thedudefromci/Bones3/TestWorld"); remesh.AddDistributor(new StandardDistributor()); m_WorldContainer = new WorldContainer(world, remesh, blockList, database); m_WorldContainer.BlockContainerProvider.OnBlockContainerCreated += OnChunkCreated; m_WorldContainer.BlockContainerProvider.OnBlockContainerDestroyed += OnChunkDestroyed; m_WorldContainer.RemeshHandler.OnRemeshFinish += OnRemeshFinished; #if UNITY_EDITOR if (!Application.isPlaying) { UnityEditor.EditorApplication.update += Update; } #endif }
/// <summary> /// Creates a new block type preview object. /// </summary> /// <param name="blockTypes">The block type list to reference when rendering.</param> public BlockTypesPreview(BlockTypeList blockTypes) { this.blockTypes = blockTypes; EditorUtility.SetCameraAnimateMaterials(previewUtility.camera, true); remeshHandler = new RemeshHandler(); remeshHandler.AddDistributor(new StandardDistributor()); remeshHandler.OnRemeshFinish += OnRemeshFinish; }
/// <summary> /// Creates a new world container for the given world. /// </summary> /// <param name="world">The world.</param> internal WorldContainer(World world, BlockWorld blockWorld) { World = world; m_BlockWorld = blockWorld; ChunkLoader = new AsyncChunkLoader(); ChunkLoader.AddChunkLoadHandler(new WorldLoader(world)); RemeshHandler = new RemeshHandler(blockWorld); RemeshHandler.AddDistributor(new StandardDistributor(m_BlockWorld)); }
/// <summary> /// Finishes any active remesh tasks. /// </summary> /// <param name="action">The action to preform on each task.</param> internal void FinishRemeshTasks(Action <RemeshTaskStack> action) { CheckAsyncWorldLoader(); RemeshHandler.FinishTasks(m_TaskStacks); foreach (var taskStack in m_TaskStacks) { action(taskStack); } m_TaskStacks.Clear(); }
/// <summary> /// Triggers the given at the given position to be remeshed, if not already in the list. /// Preforms no action if the chunk does not exist. /// </summary> /// <param name="chunkPos">The chunk position.</param> /// <param name="later">Whether to remesh the chunk now or later.</param> private void RemeshChunkAt(ChunkPosition chunkPos, bool later) { if (!World.DoesChunkExist(chunkPos)) { return; } if (later) { RemeshHandler.RemeshChunkLater(chunkPos); } else { RemeshHandler.RemeshChunk(chunkPos); } }
/// <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)); }
/// <summary> /// Remeshes all chunks which are marked as dirty. /// </summary> public void RemeshDirtyChunks() { if (m_DirtyChunks.Count == 0) { return; } List <RemeshTaskStack> tasks = new List <RemeshTaskStack>(); for (int i = 0; i < m_DirtyChunks.Count; i++) { var task = RemeshHandler.RemeshChunk(this, m_DirtyChunks[i]); tasks.Add(task); } for (int i = 0; i < tasks.Count; i++) { tasks[i].Finish(); AddEvent(new ChunkRemeshEvent(tasks[i])); } m_DirtyChunks.Clear(); }