コード例 #1
0
        public void UpdateIfNeeded(BiomeData biomeData)
        {
            if (blendEnabled != null && biomeData.length == blendEnabled.Length)
            {
                return;
            }

            blendEnabled = new bool[biomeData.length];

            //set all blendEnabled value to true
            for (int i = 0; i < biomeData.length; i++)
            {
                blendEnabled[i] = true;
            }

            int waterIndex = biomeData.GetBiomeIndex(BiomeSamplerName.waterHeight);

            if (waterIndex != -1)
            {
                blendEnabled[waterIndex] = false;
            }
        }
コード例 #2
0
        public bool BuildGraph(BiomeData biomeData)
        {
            ResetGraph();

            BaseNode rootNode = biomeData.biomeSwitchGraphStartPoint;

            Stack <BaseNode> biomeNodes = new Stack <BaseNode>();

            biomeNodes.Push(rootNode);

            BiomeSwitchCell currentCell = null;

            //fill param range dictionary (used to compute weights)
            FillParamRange(biomeData);

            while (biomeNodes.Count > 0)
            {
                BaseNode currentNode = biomeNodes.Pop();
                Type     nodeType    = currentNode.GetType();

                if (nodeType == typeof(NodeBiome))
                {
                    //get all precedent switch data in the order of the tree (start from rootNode)
                    var precedentSwitchDatas = GetPrecedentSwitchDatas(currentNode, rootNode);

                    var biomeNode  = currentNode as NodeBiome;
                    var lastSwitch = precedentSwitchDatas.Last();
                    currentCell = new BiomeSwitchCell();

                    //Set cell and partial biome remaining empty params
                    currentCell.name                   = lastSwitch.name;
                    biomeNode.outputBiome.name         = lastSwitch.name;
                    biomeNode.outputBiome.id           = biomeIdCount++;
                    currentCell.id                     = biomeNode.outputBiome.id;
                    biomeNode.outputBiome.previewColor = lastSwitch.color;
                    currentCell.color                  = lastSwitch.color;
                    currentCell.weight                 = currentCell.GetWeight(paramRanges);

                    //add the partial biome to utility dictionary accessors:
                    partialBiomePerName[currentCell.name] = biomeNode.outputBiome;
                    partialBiomePerId[currentCell.id]     = biomeNode.outputBiome;

                    //load all access condition for this biome switch
                    foreach (var sd in precedentSwitchDatas)
                    {
                        int index = biomeData.GetBiomeIndex(sd.samplerName);
                        var param = currentCell.switchParams.switchParams[index];

                        param.enabled         = true;
                        param.min             = sd.min;
                        param.max             = sd.max;
                        biomeCoverage[index] += (sd.max - sd.min) / (sd.absoluteMax - sd.absoluteMin);
                    }
                }
                else if (nodeType == typeof(NodeBiomeBlender))
                {
                    if (currentCell == null)
                    {
                        throw new InvalidOperationException("[PWBiomeSwitchGraph] idk what happened but this is really bad");
                    }

                    //if the flow reaches the biomeblender everything is OK and add the current cell to the graph
                    cells.Add(currentCell);
                    continue;
                }

                foreach (var outputNode in currentNode.GetOutputNodes())
                {
                    biomeNodes.Push(outputNode);
                }
            }

            //Generate links between all linkable nodes
            BuildLinks();

            if (cells.Count != 0)
            {
                rootCell = cells.First();
            }

            if (!CheckValid())
            {
                return(false);
            }

            isBuilt = true;

            return(true);
        }