Ejemplo n.º 1
0
        public ExteriorSkyIslandMapChunkFactory(
            IRasterChunkConfig <Index2D> config, SkyIslandMaps outOfBoundsValue, bool modifyingThrowsException)
        {
            Contracts.Requires.That(config != null);

            this.outOfBoundsChunk = new ConstantArray2D <SkyIslandMaps>(
                config.Bounds.Dimensions, outOfBoundsValue, modifyingThrowsException);
        }
Ejemplo n.º 2
0
        public VoxelGridChunkResourcesSerializer(
            IConstantSerializerDeserializer <TerrainVoxel> serializer, IRasterChunkConfig <Index3D> config)
        {
            Contracts.Requires.That(serializer != null);
            Contracts.Requires.That(config != null);

            this.serializer = new BoundedIndexable3DSerializer <TerrainVoxel>(serializer, config.Bounds.Dimensions);
        }
Ejemplo n.º 3
0
        public ExteriorVoxelGridChunkFactory(
            IRasterChunkConfig <Index3D> config, TerrainVoxel outOfBoundsValue, bool modifyingThrowsException)
        {
            Contracts.Requires.That(config != null);

            this.outOfBoundsChunk = new ConstantArray3D <TerrainVoxel>(
                config.Bounds.Dimensions, outOfBoundsValue, modifyingThrowsException);
        }
		public SkyIslandMapChunkResourcesSerializer(
			IConstantSerializerDeserializer<SkyIslandMaps> serializer, IRasterChunkConfig<Index2D> config)
		{
			Contracts.Requires.That(serializer != null);
			Contracts.Requires.That(config != null);

			this.serializer = new BoundedIndexable2DSerializer<SkyIslandMaps>(serializer, config.Bounds.Dimensions);
		}
        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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        public ContourPhase(
            IStageIdentity stageIdentity,
            IStageBounds stageBounds,
            IRasterChunkConfig <Index3D> voxelChunkConfig,
            IAsyncFactory <ChunkKey, IDisposableValue <IReadOnlyVoxelGridChunk> > voxelChunkFactory,
            IDualContourer <TerrainVoxel, TSurfaceData, NormalColorTextureVertex> contourer,
            IChunkStore <ChunkKey, SerializedMeshChunk> meshChunkStore,
            int maxBufferedChunks,
            BatchSerializeGenerationOptions options = null)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(voxelChunkConfig != null);
            Contracts.Requires.That(voxelChunkFactory != null);
            Contracts.Requires.That(contourer != null);
            Contracts.Requires.That(meshChunkStore != null);
            Contracts.Requires.That(maxBufferedChunks > 0);

            var phaseIdentity = new GenerationPhaseIdentity(nameof(ContourPhase <TSurfaceData>));
            var chunkKeys     = new ChunkKeyCollection(stageBounds);

            var poolOptions = new PoolOptions <IMutableDivisibleMesh <NormalColorTextureVertex> >()
            {
                ResetAction = mesh => mesh.Clear(),
            };

            this.pool = Pool.WithFactory.New(
                Factory.From <IMutableDivisibleMesh <NormalColorTextureVertex> >(
                    () => new MutableDivisibleMesh <NormalColorTextureVertex>()),
                poolOptions);

            var chunkFactory = new ContourMeshFactory <TSurfaceData>(
                voxelChunkConfig, voxelChunkFactory, this.pool, contourer);
            var serializer = DivisibleMeshSerializer.NormalColorTextureVertices.WithColorAlpha[
                options?.SerializationEndianness ?? DefaultSerializationEndianness];
            var persistableFactory = new SerializeMeshChunkFactory(chunkFactory, serializer);

            this.Phase = new ChunkedBatchingPhase <ChunkKey, SerializedMeshChunk>(
                stageIdentity,
                phaseIdentity,
                chunkKeys,
                persistableFactory,
                meshChunkStore,
                maxBufferedChunks,
                options);

            this.Completion = this.CompleteAsync();
        }
        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();
        }
        public ContourMeshFactory(
            IRasterChunkConfig <Index3D> voxelChunkConfig,
            IAsyncFactory <ChunkKey, IDisposableValue <IReadOnlyVoxelGridChunk> > voxelChunkFactory,
            IPool <IMutableDivisibleMesh <NormalColorTextureVertex> > meshBuilderPool,
            IDualContourer <TerrainVoxel, TSurfaceData, NormalColorTextureVertex> contourer)
        {
            Contracts.Requires.That(voxelChunkConfig != null);
            Contracts.Requires.That(voxelChunkFactory != null);
            Contracts.Requires.That(meshBuilderPool != null);
            Contracts.Requires.That(contourer != null);

            this.voxelChunkDimensionsInVoxels = voxelChunkConfig.Bounds.Dimensions;
            this.meshBuilderPool = meshBuilderPool;
            this.contourer       = contourer;

            this.chunkConglomerator = new ChunkConglomerator <IReadOnlyVoxelGridChunk>(
                async index => await voxelChunkFactory.CreateAsync(
                    new ChunkKey(index - new Index3D(1))).DontMarshallContext(),
                new Index3D(3));
        }
        public static SkyIslandMapPopulatorConfig.Builder CreatePreconfigured(
            IStageBounds stageBounds, IRasterChunkConfig chunkConfig)
        {
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(chunkConfig != null);

            double baselineHeightVariation = 50;
            double halfStageHeight         = stageBounds.InChunks.Dimensions.Y * chunkConfig.SideLength / 2.0;
            double baselineMin             = halfStageHeight - baselineHeightVariation;
            double baselineMax             = halfStageHeight + baselineHeightVariation;
            double scale = 10000;

            return(new SkyIslandMapPopulatorConfig.Builder()
            {
                SelectionGradientStartDistancePercent = .6,
                ShapeDistorter = NoiseDistorter.Combine(
                    NoiseDistorter.New().Frequency(20 / scale, 20 / scale).ConvertRange(-1, 1),
                    NoiseDistorter.New().Frequency(40 / scale, 40 / scale).ConvertRange(-.5, .5),
                    NoiseDistorter.New().Frequency(80 / scale, 80 / scale).ConvertRange(-.3, .3)),
                BaselineHeightDistorter =
                    NoiseDistorter.New().Frequency(10 / scale, 10 / scale).ConvertRange(baselineMin, baselineMax),
                MountainDistorter =
                    NoiseDistorter.New().Frequency(10 / scale, 10 / scale).ConvertRange(-6, 5).Clamp(1, 4),
                TopHeightDistorter = NoiseDistorter.Combine(
                    NoiseDistorter.New().Frequency(20 / scale, 20 / scale).ConvertRange(0, 10),
                    NoiseDistorter.New().Frequency(40 / scale, 40 / scale).ConvertRange(0, 40),
                    NoiseDistorter.New().Frequency(80 / scale, 80 / scale).ConvertRange(0, 20),
                    NoiseDistorter.New().Frequency(160 / scale, 160 / scale).ConvertRange(0, 10)),
                TopHeightNearEdgeDistorter = NoiseDistorter.Combine(
                    NoiseDistorter.New().Frequency(20 / scale, 20 / scale).ConvertRange(0, 7.5),
                    NoiseDistorter.New().Frequency(40 / scale, 40 / scale).ConvertRange(0, 30),
                    NoiseDistorter.New().Frequency(80 / scale, 80 / scale).ConvertRange(0, 15),
                    NoiseDistorter.New().Frequency(160 / scale, 160 / scale).ConvertRange(0, 7.5)),
                BottomHeightDistorter =
                    NoiseDistorter.New().Frequency(200 / scale, 200 / scale).ConvertRange(-200, -100),
                BottomHeightNearEdgeDistorter =
                    NoiseDistorter.New().Frequency(800 / scale, 800 / scale).ConvertRange(-100, -50),
            });
        }
        public VoxelGridChunkResourcesFactory(IRasterChunkConfig <Index3D> config)
        {
            Contracts.Requires.That(config != null);

            this.dimensions = config.Bounds.Dimensions;
        }
Ejemplo n.º 12
0
        public SkyIslandMapChunkResourcesFactory(IRasterChunkConfig <Index2D> config)
        {
            Contracts.Requires.That(config != null);

            this.dimensions = config.Bounds.Dimensions;
        }