Exemplo n.º 1
0
        void setUpTestChunk()
        {
            // Set up one chunk to load and mesh
            Level storage = new Level((1, 1, 1), null);

            Chunk.ID chunkID = new Chunk.ID(0, 0, 0);
            World.setActiveLevel(storage);
            levelManager.initializeFor(World.Current.activeLevel);
            World.EventSystem.subscribe(
                levelManager,
                WorldEventSystem.Channels.ChunkActivationUpdates
                );

            // run the load job syncly
            BiomeMap.GenerateChunkDataFromSourceJob terrainGenJob = BiomeMap.GetTerrainGenerationJob(chunkID, storage);
            terrainGenJob.Execute();

            // get the data from the load job
            Chunk newlyLoadedChunk = new Chunk();

            if (terrainGenJob.solidVoxelCount[0] > 0)
            {
                newlyLoadedChunk.setVoxels(
                    terrainGenJob.outVoxels,
                    terrainGenJob.solidVoxelCount[0]
                    );
            }
            terrainGenJob.outVoxels.Dispose();

            // add the loaded chunk to storage
            storage.chunks.Add(chunkID, newlyLoadedChunk);
            newlyLoadedChunk.isLoaded = true;

            // get the mesh gen job and run it syncly
            MarchingTetsMeshGenerator.MarchingTetsMeshGenJob meshGenJob = MarchingTetsMeshGenerator.GetJob(MarchingTetsMeshGenerator.GetVoxelsToMarchOver(chunkID, storage));
            meshGenJob.Execute();

            // set up the mesh data
            bool          meshIsEmpty   = meshGenJob.outVerticies.Length <= 0;
            VoxelMeshData chunkMeshData = new VoxelMeshData(
                chunkID,
                meshIsEmpty,
                meshGenJob.outVerticies,
                meshGenJob.outTriangles,
                meshGenJob.outColors
                );

            // dispose of the allocated resources
            meshGenJob.outVerticies.Dispose();
            meshGenJob.outTriangles.Dispose();
            meshGenJob.outColors.Dispose();

            // update the chunk data to say if it's meshed
            if (storage.chunks.TryGetValue(chunkID, out Chunk updatedChunk))
            {
                updatedChunk.meshIsGenerated = true;
                updatedChunk.meshIsEmpty     = meshIsEmpty;
            }

            /// notify the chunk manager
            World.EventSystem.notifyChannelOf(
                new MeshGenerationAperture.ChunkMeshLoadingFinishedEvent(chunkMeshData),
                WorldEventSystem.Channels.ChunkActivationUpdates
                );

            // set the chunk active
            ActiveChunkObjectAperture.ActivateChunkObjectJob activateChunkJob = new ActiveChunkObjectAperture.ActivateChunkObjectJob(chunkID);
            activateChunkJob.Execute();
        }