Exemple #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;
            }
        }
Exemple #2
0
        public bool BuildGraph(BiomeData biomeData)
        {
            ResetGraph();

            PWNode rootNode = biomeData.biomeSwitchGraphStartPoint;

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

            biomeNodes.Push(rootNode);

            BiomeSwitchCell currentCell = null;

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

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

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

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

                    //Set cell and partial biome remaining empty params
                    currentCell.name   = biomeNode.outputBiome.name = lastSwitch.name;
                    currentCell.id     = biomeNode.outputBiome.id = biomeIdCount++;
                    currentCell.color  = biomeNode.outputBiome.previewColor = 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(PWNodeBiomeBlender))
                {
                    if (currentCell == null)
                    {
                        throw new Exception("[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();

            rootCell = cells.First();

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

            isBuilt = true;

            return(true);
        }