public static StreamingStageMeshFactory CreateSkyIsland()
        {
            var stageIdentity = new StageIdentity("Test Stage");
            var multiNoise    = new NoiseFactory(seed: 0);

            // maps
            var mapChunkConfig = new SkyIslandMapChunkConfig(VoxelChunkConfig.TreeDepth);
            var stageBounds    = new StageBounds(new ChunkKey(0, 0, 0), new Index3D(1, 8, 1));
            var mapConfig      = SkyIslandMapGenerationConfigService.CreatePreconfigured(stageBounds, mapChunkConfig).Build();

            var mapChunkPopulator = new AsyncChunkPopulator <ISkyIslandMapChunk>(
                new SkyIslandMapChunkPopulator(mapConfig, stageBounds, multiNoise));

            var mapChunkCacheBuilder = new SkyIslandMapChunkCacheBuilder(mapChunkConfig, mapChunkPopulator);
            var mapCacheOptions      = new ChunkCacheBuilderOptions <SkyIslandMapChunkResources>()
            {
                StashCapacityMultiplier = 2,
                EagerFillPool           = true,
            };

            mapChunkCacheBuilder.CreateAndAssignStandardResourceStash(CacheSizeInBytes / 10, mapCacheOptions);
            var mapChunkCache = mapChunkCacheBuilder.Build();

            // voxels
            var voxelChunkPopulator = new SkyIslandVoxelGridChunkPopulator(
                SkyIslandVoxelGridGenerationConfigService.CreatePreconfigured().Build(),
                mapChunkCache.AsReadOnly,
                multiNoise);

            return(CreateMeshFactory(multiNoise, voxelChunkPopulator, mapChunkCache));
        }
Ejemplo n.º 2
0
    public static TrackingPool <TResource> CreateAndAssignTrackingResourceStash <TKey, TResource>(
        this IChunkCacheBuilder <TKey, TResource> builder,
        long approximateCapacityInBytes,
        ChunkCacheBuilderOptions <TResource> options = null)
    {
        Contracts.Requires.That(builder != null);
        Contracts.Requires.That(approximateCapacityInBytes > 0);

        var poolOptions = new TrackingPoolOptions <TResource>();

        options = HandleOptions(poolOptions, options);
        poolOptions.BoundedCapacity = builder.CalculateResourcePoolCapacity(approximateCapacityInBytes);

        TrackingPool <TResource> pool;

        if (options.EagerFillPool)
        {
            pool = Pool.Tracking.New(poolOptions);
            pool.GiveUntilFull(builder.ResourceFactory);
        }
        else
        {
            pool = Pool.Tracking.WithFactory.Bounded.New(builder.ResourceFactory, poolOptions);
        }

        builder.ResourceStash = PoolStash.Create <TKey, TResource>(pool, options.StashCapacityMultiplier);
        return(pool);
    }
Ejemplo n.º 3
0
    private static ChunkCacheBuilderOptions <TResource> HandleOptions <TResource>(
        PoolOptions <TResource> poolOptions, ChunkCacheBuilderOptions <TResource> options)
    {
        Contracts.Requires.That(poolOptions != null);

        options = options ?? Options <TResource> .Default;
        poolOptions.ResetAction   = options.ResetResource ?? Options <TResource> .Default.ResetResource;
        poolOptions.ReleaseAction = options.ReleaseResource ?? Options <TResource> .Default.ReleaseResource;
        return(options);
    }
        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());
        }