コード例 #1
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);
        }
コード例 #2
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()
                    };
                }
            }
        }