public VoxelGridChunkPoolingFactory(
            IPool <VoxelGridChunkResources> pool, IAsyncChunkPopulator <IVoxelGridChunk> populator)
        {
            Contracts.Requires.That(pool != null);
            Contracts.Requires.That(populator != null);

            this.pool      = pool;
            this.populator = populator;
        }
        public SkyIslandMapChunkPoolingFactory(
            IPool <SkyIslandMapChunkResources> pool, IAsyncChunkPopulator <ISkyIslandMapChunk> populator)
        {
            Contracts.Requires.That(pool != null);
            Contracts.Requires.That(populator != null);

            this.pool      = pool;
            this.populator = populator;
        }
        public SkyIslandMapChunkCacheBuilder(
            IRasterChunkConfig <Index2D> chunkConfig, IAsyncChunkPopulator <ISkyIslandMapChunk> chunkPopulator)
        {
            Contracts.Requires.That(chunkConfig != null);
            Contracts.Requires.That(chunkPopulator != null);

            this.chunkConfig     = chunkConfig;
            this.ResourceFactory = new SkyIslandMapChunkResourcesFactory(chunkConfig);
            this.chunkPopulator  = chunkPopulator;
        }
Example #4
0
        public VoxelGridChunkCacheBuilder(
            IRasterChunkConfig <Index3D> chunkConfig, IAsyncChunkPopulator <IVoxelGridChunk> chunkPopulator)
        {
            Contracts.Requires.That(chunkConfig != null);
            Contracts.Requires.That(chunkPopulator != null);

            this.chunkConfig     = chunkConfig;
            this.ResourceFactory = new VoxelGridChunkResourcesFactory(chunkConfig);
            this.chunkPopulator  = chunkPopulator;
        }
        private static IChunkCache <ChunkKey, IVoxelGridChunk, IReadOnlyVoxelGridChunk> CreateVoxelChunkCache(
            IAsyncChunkPopulator <IVoxelGridChunk> populator)
        {
            Contracts.Requires.That(populator != null);

            var voxelChunkCacheBuilder = new VoxelGridChunkCacheBuilder(VoxelChunkConfig, populator);
            var voxelCacheOptions      = new ChunkCacheBuilderOptions <VoxelGridChunkResources>()
            {
                StashCapacityMultiplier = 2,
                EagerFillPool           = true,
            };

            voxelChunkCacheBuilder.CreateAndAssignStandardResourceStash(CacheSizeInBytes, voxelCacheOptions);
            return(voxelChunkCacheBuilder.Build());
        }
        public SkyIslandMapAbsolutePhase(
            IStageIdentity stageIdentity,
            IStageBounds stageBounds,
            IRasterChunkConfig <Index2D> chunkConfig,
            IAsyncChunkPopulator <ISkyIslandMapChunk> chunkPopulator,
            IChunkStore <ChunkOverheadKey, SerializedSkyIslandMapChunk> chunkStore,
            int maxBufferedChunks,
            BatchSerializeGenerationOptions options = null)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(chunkConfig != null);
            Contracts.Requires.That(chunkPopulator != null);
            Contracts.Requires.That(chunkStore != null);
            Contracts.Requires.That(maxBufferedChunks > 0);

            var phaseIdentity = new GenerationPhaseIdentity(nameof(SkyIslandMapAbsolutePhase));
            var chunkKeys     = new ChunkOverheadKeyCollection(stageBounds);

            var poolOptions = new PoolOptions <SkyIslandMapChunkResources>()
            {
            };

            this.pool = Pool.WithFactory.New(new SkyIslandMapChunkResourcesFactory(chunkConfig), poolOptions);

            var chunkFactory = new SkyIslandMapChunkPoolingFactory(this.pool, chunkPopulator);
            var serializer   = new SkyIslandMapChunkResourcesSerializer(
                SkyIslandMapsSerializer.Get[options?.SerializationEndianness ?? DefaultSerializationEndianness],
                chunkConfig);
            var persister          = new SkyIslandMapChunkPersister(serializer);
            var persistableFactory = ChunkFactory.Persister.Create(chunkFactory, persister);

            this.Phase = new ChunkedBatchingPhase <ChunkOverheadKey, SerializedSkyIslandMapChunk>(
                stageIdentity,
                phaseIdentity,
                chunkKeys,
                persistableFactory,
                chunkStore,
                maxBufferedChunks,
                options);

            this.Completion = this.CompleteAsync();
        }
        private static StreamingStageMeshFactory CreateMeshFactory(
            NoiseFactory noise, IAsyncChunkPopulator <IVoxelGridChunk> populator, IAsyncCompletable additional = null)
        {
            Contracts.Requires.That(noise != null);
            Contracts.Requires.That(populator != null);

            var voxelCache = CreateVoxelChunkCache(populator);
            var meshPool   = CreateMeshBuilderPool();

            var meshFactory = new ContourMeshFactory <TerrainSurfaceData>(
                VoxelChunkConfig,
                voxelCache.AsReadOnly,
                meshPool,
                new TerrainDualContourer <TerrainSurfaceData>(noise));

            var completable = new AggregateAsyncCompletable(voxelCache, new DisposableAsyncCompletable(meshPool));

            if (additional != null)
            {
                completable = new AggregateAsyncCompletable(additional, completable);
            }

            return(new StreamingStageMeshFactory(meshFactory, completable));
        }