Example #1
0
        // Initialization
        private void Initialize()
        {
            VoxelWorld = new VoxelWorld(4582);

            UpdateJobs    = new BlockingCollection <ChunkUpdateJob>(new ConcurrentStack <ChunkUpdateJob>());
            _meshResults  = new ConcurrentStack <ChunkMeshResult>();
            _lightResults = new ConcurrentStack <ChunkLightResult>();

            // Initialize the voxel dictionary
            VoxelDictionary.InitializeVoxelDictionary();

            // Instantiate a new runtime texture atlas
            AtlasGenerator = new RuntimeTextureAtlas();

            // Instantiate mesh workers proportional to system thread count
            var workerCount = Environment.ProcessorCount > 4 ? Environment.ProcessorCount - 2 : 2;

            _meshExtractors = new ChunkUpdateWorker[workerCount];
            for (var i = 0; i < _meshExtractors.Length; i++)
            {
                _meshExtractors[i] = new ChunkUpdateWorker(UpdateJobs, _meshResults);
            }

            // Start the chunk generation routine
            StartCoroutine(nameof(GenerateChunks));
        }