Esempio n. 1
0
        protected override void SetUp(LayerConfigObject config)
        {
            // Config files for random layers MUST define these properties
            Block block = world.blockProvider.GetBlock(config.BlockName);

            blockToPlace = new BlockData(block.type, block.solid);
        }
Esempio n. 2
0
        public void BaseSetUp(LayerConfigObject config, World world, TerrainGen terrainGen)
        {
            this.terrainGen = terrainGen;
            layerName       = config.LayerName;
            IsStructure     = config.IsStructure();
            this.world      = world;
            Index           = config.Index;

            noise = new NoiseWrapper(world.worldName);
#if (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) && ENABLE_FASTSIMD
            noiseSIMD = new NoiseWrapperSIMD(world.name);
#endif

            SetUp(config);
        }
Esempio n. 3
0
        protected override void SetUp(LayerConfigObject config)
        {
            string configStructure = string.Empty;

            if (config is StructureLayerConfigObject structureConfig)
            {
                configStructure = structureConfig.Structure;
            }

            // Config files for random layers MUST define these properties
            Type structureType = Type.GetType(configStructure + ", " + typeof(GeneratedStructure).Assembly, false);

            if (structureType == null)
            {
                Debug.LogError("Could not create structure " + configStructure);
                return;
            }

            structure = (GeneratedStructure)Activator.CreateInstance(structureType);
        }
Esempio n. 4
0
        private void ProcessConfigs(World world, LayerCollection layers)
        {
            List <LayerConfigObject> layersConfigs = new List <LayerConfigObject>(layers.Layers);

            // Terrain layers
            List <TerrainLayer> terrainLayers        = new List <TerrainLayer>();
            List <int>          terrainLayersIndexes = new List <int>(); // could be implemented as a HashSet, however, it would be insane storing hundreads of layers here

            // Structure layers
            List <TerrainLayer> structLayers        = new List <TerrainLayer>();
            List <int>          structLayersIndexes = new List <int>(); // could be implemented as a HashSet, however, it would be insane storing hundreads of layers here

            for (int i = 0; i < layers.Layers.Length;)
            {
                LayerConfigObject config = layers.Layers[i];

                // Set layers up
                TerrainLayer layer = config.GetLayer();
                layer.BaseSetUp(config, world, this);

                if (layer.IsStructure)
                {
                    // Do not allow any two layers share the same index
                    if (structLayersIndexes.Contains(layer.Index))
                    {
                        Debug.LogError("Could not create structure layer " + config.LayerName + ". Index " + layer.Index.ToString() + " already defined");
                        layersConfigs.RemoveAt(i);
                        continue;
                    }

                    // Add layer to layers list
                    structLayers.Add(layer);
                    structLayersIndexes.Add(layer.Index);
                }
                else
                {
                    // Do not allow any two layers share the same index
                    if (terrainLayersIndexes.Contains(layer.Index))
                    {
                        Debug.LogError("Could not create terrain layer " + config.LayerName + ". Index " + layer.Index.ToString() + " already defined");
                        layersConfigs.RemoveAt(i);
                        continue;
                    }

                    // Add layer to layers list
                    terrainLayers.Add(layer);
                    terrainLayersIndexes.Add(layer.Index);
                }

                ++i;
            }

            // Call OnInit for each layer now that they all have been set up. Thanks to this, layers can
            // e.g. address other layers knowing that they will be able to access all data they need.
            int ti = 0, si = 0;

            for (int i = 0; i < layersConfigs.Count; i++)
            {
                LayerConfigObject config = layersConfigs[i];
                if (config.IsStructure())
                {
                    structLayers[si++].Init(config);
                }
                else
                {
                    terrainLayers[ti++].Init(config);
                }
            }

            // Sort the layers by index
            TerrainLayers = terrainLayers.ToArray();
            Array.Sort(TerrainLayers);
            StructureLayers = structLayers.ToArray();
            Array.Sort(StructureLayers);

            // Register support for noise functionality with each workpool thread
            for (int i = 0; i < Globals.WorkPool.Size; i++)
            {
                LocalPools pool = Globals.WorkPool.GetPool(i);
                pool.noiseItems = new NoiseItem[layersConfigs.Count];
                for (int j = 0; j < layersConfigs.Count; j++)
                {
                    pool.noiseItems[j] = new NoiseItem
                    {
                        noiseGen = new NoiseInterpolator()
                    };
                }
            }
        }
Esempio n. 5
0
 public virtual void Init(LayerConfigObject config)
 {
 }
Esempio n. 6
0
 protected virtual void SetUp(LayerConfigObject config)
 {
 }
Esempio n. 7
0
 public override void Init(LayerConfigObject config)
 {
     structure.Init(world);
 }