public void Initialise(VoxelTypeManager typeManager, Allocator allocator = Allocator.Persistent)
        {
            NativeArray <NativeOreSettingsPair> oreSettings = new NativeArray <NativeOreSettingsPair>(ores.Count, allocator);

            for (int i = 0; i < ores.Count; i++)
            {
                var original = ores[i];
                var settings = original.settings;
                settings.Initialise();
                oreSettings[i] = new NativeOreSettingsPair()
                {
                    voxelType = typeManager.GetId(original.voxelType),
                    settings  = settings
                };
            }
            Native = oreSettings;
        }
예제 #2
0
        public override void Initialise(VoxelTypeManager voxelTypeManager, IChunkManager chunkManager, FrameworkEventManager eventManager)
        {
            base.Initialise(voxelTypeManager, chunkManager, eventManager);


            Assert.IsNotNull(bedrockType, $"{typeof(NoisyProvider)} must have a valid reference to a bedrock block type");
            Assert.IsNotNull(waterType, $"{typeof(NoisyProvider)} must have a valid reference to a water block type");
            Assert.IsNotNull(biomeDatabaseComponent, $"{typeof(NoisyProvider)} must have a valid reference to a biome database component");

            if (SceneMessagePasser.TryConsumeMessage <SeedMessage>(out var message))
            {
                worldSettings.seed = GetSeedAsFloat(message.seed);
                Debug.Log($"Int seed: {message.seed}, derived seed: {worldSettings.seed}");
            }
            InitialiseSeeds();

            bedrockID = voxelTypeManager.GetId(bedrockType);
            waterID   = voxelTypeManager.GetId(waterType);

            chunkDimensions = chunkManager.ChunkDimensions.ToNative();

            if (chunkManager.WorldLimits.IsWorldHeightLimited)
            {
                minY = chunkManager.WorldLimits.MinChunkY * chunkManager.ChunkDimensions.y;
            }

            worldSettings.Initialise(minY, chunkManager.ChunkDimensions.ToNative());
            treeSettings.Initialise();

            biomeDatabaseComponent.Initialise();

            //Setup ocean config
            try
            {
                var oceanZone   = biomeDatabaseComponent.config.elevationLowToHigh.Find((zone) => zone.Name.Equals("Ocean"));
                var oceanBiomes = oceanZone.moistureLevelsLowToHigh.Select((def) => def.biomeDefinition).ToArray();

                oceanGenConfig.oceanIDs = new NativeArray <int>(oceanBiomes.Length, Allocator.Persistent);
                for (int i = 0; i < oceanBiomes.Length; i++)
                {
                    oceanGenConfig.oceanIDs[i] = biomeDatabaseComponent.GetBiomeID(oceanBiomes[i]);
                }
                oceanGenConfig.sealevel = math.floor(math.lerp(worldSettings.minPossibleHmValue, worldSettings.maxPossibleHmValue, biomeDatabaseComponent.GetMaxElevationFraction(oceanBiomes[0])));
                oceanGenConfig.waterID  = waterID;
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to find any ocean biomes for biome config {biomeDatabaseComponent.config.name}. Cause {e.Message}");
            }

            noiseMaps = new Dictionary <Vector2Int, ChunkColumnNoiseMaps>();
            numActiveChunksInColumn  = new Dictionary <Vector2Int, int>();
            noiseGenReferenceCounter = new JobReferenceCounter <Vector2Int, NativeChunkColumnNoiseMaps>(MakeNoiseJob);

            structureGenerator = new StructureGenerator();
            structureGenerator.Initalise(voxelTypeManager, biomeDatabaseComponent, treeSettings.TreeThreshold, (int)treemapNoise.Seed);

            oreSettings.Initialise(voxelTypeManager);

            eventManager.OnChunkActivated   += OnChunkActivated;
            eventManager.OnChunkDeactivated += OnChunkDeactivated;
        }
예제 #3
0
        public NativeTreeDefinition ToNative(VoxelTypeManager typeManager)
        {
            NativeTreeDefinition def = new NativeTreeDefinition();

            def.maxHeight        = maxHeight;
            def.minHeight        = minHeight;
            def.minLeafClearance = minLeafClearance;
            def.leafID           = (leafType == null) ? (VoxelTypeID)VoxelTypeID.AIR_ID : typeManager.GetId(leafType);
            def.logID            = (logType == null) ? (VoxelTypeID)VoxelTypeID.AIR_ID : typeManager.GetId(logType);
            def.style            = Style;
            return(def);
        }
예제 #4
0
 public override void Initialise(VoxelTypeManager voxelTypeManager, IChunkManager chunkManager, FrameworkEventManager eventManager)
 {
     base.Initialise(voxelTypeManager, chunkManager, eventManager);
     dirtID  = voxelTypeManager.GetId(dirtType);
     grassID = voxelTypeManager.GetId(grassType);
 }
        public NativeBiomeDatabase ConfigToNative(SOBiomeConfiguration config, VoxelTypeManager typeManager)
        {
            List <NativeVoxelRange> allLayersList   = new List <NativeVoxelRange>();
            List <StartEndRange>    biomeLayersList = new List <StartEndRange>();
            List <NativeBiomeMoistureDefinition> allMoistureDefsList   = new List <NativeBiomeMoistureDefinition>();
            List <NativeElevationZone>           allElevationZonesList = new List <NativeElevationZone>();


            foreach (var elevationEntry in config.elevationLowToHigh)
            {
                NativeElevationZone elevationZone = new NativeElevationZone();
                elevationZone.maxElevationPercentage = elevationEntry.max;
                elevationZone.moistureLevels         = new StartEndRange()
                {
                    start = allMoistureDefsList.Count
                };

                foreach (var moistureEntry in elevationEntry.moistureLevelsLowToHigh)
                {
                    NativeBiomeMoistureDefinition moistureDef = new NativeBiomeMoistureDefinition();
                    moistureDef.maxMoisturePercentage = moistureEntry.max;

                    if (!biomeIds.TryGetValue(moistureEntry.biomeDefinition, out var id))
                    {
                        //Create new biome data
                        id = biomeLayersList.Count;
                        biomeIds.Add(moistureEntry.biomeDefinition, id);
                        biomeDefinitionsById.Add(moistureEntry.biomeDefinition);

                        Assert.IsTrue(moistureEntry.biomeDefinition.topLayers.Count > 0, $"All biome definitions must have at least one layer,{moistureEntry.biomeDefinition.name} does not");
                        StartEndRange layersForThisBiome = new StartEndRange()
                        {
                            start = allLayersList.Count
                        };

                        foreach (var layer in moistureEntry.biomeDefinition.topLayers)
                        {
                            NativeVoxelRange nativeLayer = new NativeVoxelRange();
                            nativeLayer.depth   = layer.depth;
                            nativeLayer.voxelID = typeManager.GetId(layer.voxelType);
                            allLayersList.Add(nativeLayer);
                        }

                        layersForThisBiome.end = allLayersList.Count;
                        biomeLayersList.Add(layersForThisBiome);
                    }

                    moistureDef.biomeID = id;

                    allMoistureDefsList.Add(moistureDef);
                }

                elevationZone.moistureLevels.end = allMoistureDefsList.Count;
                allElevationZonesList.Add(elevationZone);
            }

            NativeBiomeDatabase biomeDatabase = new NativeBiomeDatabase();

            VoxelTypeID defaultVoxelType = new VoxelTypeID(VoxelTypeID.AIR_ID);

            if (config.defaultVoxelType != null)
            {
                defaultVoxelType = typeManager.GetId(config.defaultVoxelType);
            }

            biomeDatabase.defaultVoxelType = defaultVoxelType;

            biomeDatabase.allLayers         = new NativeArray <NativeVoxelRange>(allLayersList.ToArray(), Allocator.Persistent);
            biomeDatabase.biomeLayers       = new NativeArray <StartEndRange>(biomeLayersList.ToArray(), Allocator.Persistent);
            biomeDatabase.allMoistureDefs   = new NativeArray <NativeBiomeMoistureDefinition>(allMoistureDefsList.ToArray(), Allocator.Persistent);
            biomeDatabase.allElevationZones = new NativeArray <NativeElevationZone>(allElevationZonesList.ToArray(), Allocator.Persistent);

            return(biomeDatabase);
        }