示例#1
0
 /// <summary>
 ///  执行 Execute 的后置方法,在 Execute() 方法的 returen 前调用
 /// </summary>
 public void Postposition(ResultType resultType)
 {
     if (resultType != ResultType.Running)
     {
         nodeStatus = NODE_STATUS.READY;
         OnExit();
     }
 }
示例#2
0
 //执行 Execute 的前置方法,在 Execute() 方法的第一行调用
 public void Preposition()
 {
     if (nodeStatus == NODE_STATUS.READY)
     {
         nodeStatus = NODE_STATUS.RUNNING;
         OnEnter();
     }
 }
示例#3
0
 // Changes the state of the node
 public void ChangeState(NODE_STATUS newState)
 {
     if (NodeStatus != newState)
     {
         NodeStatus = newState;
         GetComponent <MeshRenderer>().material = materials[(int)NodeStatus];
         if (newState == NODE_STATUS.BLOCKED)
         {
             diffusion           = 0;
             staticDiffusionBase = 0;
         }
     }
 }
示例#4
0
    void Start()
    {
        for (int i = 0; i < 24; i++)
        {
            for (int k = 0; k < 6; k++)
            {
                floats.Add(i * 1.0f + k * 1.0f / 10, 0);
            }
        }


        for (int i = 0; i < 24; i++)
        {
            avatarsOvelapped.Add(i, 0);
        }

        // Sets the node to default values
        avatarsOverlapping = 0;
        Renderer render = GetComponent <MeshRenderer>();

        NodeStatus = NODE_STATUS.UNSEARCHED;

        diffusion                 = 0;
        exitDiffusion             = 0;
        highlighted               = false;
        calculatedDiffOnLastFrame = true;
        groups = myManager.groups.Select(x => x.GetComponent <PeakingGroup>()).ToArray();
        for (int i = 0; i < myManager.groups.Count; i++)
        {
            myManager.groups[i].GetComponent <PeakingGroup>().index = i;
        }
        staticDiffusionBases       = new float[myManager.groups.Count];
        diffusions                 = new float[myManager.groups.Count];
        redirectionDiffusion       = new float[myManager.groups.Count];
        redirectionStaticDiffusion = new float[myManager.groups.Count];
        goalTests = new float[myManager.groups.Count];
        // Sets the nodes default material
        if (render != null)
        {
            render.material = materials[(int)NodeStatus];
        }

        // Sets the node up as a goal
        if (goal)
        {
            NodeStatus          = NODE_STATUS.END;
            diffusion           = goalDiffusion;
            staticDiffusionBase = goalDiffusion;

            openParking = !forceCloseParking;
            goal        = !forceCloseParking;
            //GetComponent<NodeScript>().goalDiffusion = open ? 1000000 : 0;
            NodeStatus = !forceCloseParking ? NodeScript.NODE_STATUS.END : NodeScript.NODE_STATUS.UNSEARCHED;
        }



        // Sets the node up as a exit
        if (exit)
        {
            NodeStatus          = NODE_STATUS.END;
            exitDiffusion       = goalDiffusion;
            staticExitDiffusion = goalDiffusion;
        }
    }
示例#5
0
    //Calculates the diffusion value for the node
    private void CalculateDiffusion()
    {
        for (int i = 0; i < groups.Length; i++)
        {
            //check for desync
            if (i >= staticDiffusionBases.Length)
            {
                return;
            }

            PeakingGroup group = groups[i].GetComponent <PeakingGroup>();

            //if non-goal oriented group skip
            if (groups[i].goals == null)
            {
                continue;
            }

            // If there is an end and this node isn't the goal and not blocked

            if (myManager.GetEndAllocated() && !group.goals.Contains(this) && NodeStatus != NODE_STATUS.BLOCKED)
            {
                // Stores the origional value for the calculation
                float originalDiff          = diffusions[group.index];
                float originalBaseDiffusion = staticDiffusionBases[group.index];
                //specific goal (only goes straight to)
                float originalSpecificGoalDiffusion = goalTests[group.index];

                //reedirection diffusions when avatar is redirected
                float originalRedirDiff       = redirectionDiffusion[group.index];
                float originalRedirStaticDiff = redirectionStaticDiffusion[group.index];
                bool  isRedirGoal             = group.redirectToGoals.Contains(this) && openParking; //is this a open redirection goal

                // For each of the nodes neighbours

                foreach (EdgeScript edge in edges)
                {
                    // If they are not a blocked node use thier diffusion value for the equation
                    if (edge.GetTo().NodeStatus != NODE_STATUS.BLOCKED && !edge.GetTo().spawner)
                    {
                        try
                        {
                            staticDiffusionBases[group.index] += (myManager.diffusionCoeff * (edge.GetTo().staticDiffusionBases[group.index] - originalBaseDiffusion));
                            diffusions[group.index]           += (myManager.diffusionCoeff * (edge.GetTo().diffusions[group.index] - originalDiff));

                            goalTests[group.index] += (myManager.diffusionCoeff * (edge.GetTo().goalTests[group.index] - originalSpecificGoalDiffusion));

                            if (!isRedirGoal)
                            {
                                redirectionDiffusion[group.index]       += (myManager.diffusionCoeff * (edge.GetTo().redirectionDiffusion[group.index] - originalRedirDiff));
                                redirectionStaticDiffusion[group.index] += (myManager.diffusionCoeff * (edge.GetTo().redirectionStaticDiffusion[group.index] - originalRedirStaticDiff));
                            }
                        }
                        catch (IndexOutOfRangeException) {
                            //doesn't affect anything goes in due to bad referencing and race condition when placing new parking lot
                        }
                    }
                }

                staticDiffusionBases[group.index] = staticDiffusionBases[group.index] - (staticDiffusionBases[group.index] * (myManager.decayRate));
                diffusions[group.index]           = (diffusions[group.index] - (diffusions[group.index] * (myManager.decayRate))); // Apply the decay rate to the diffusion

                goalTests[group.index] = (goalTests[group.index] - (goalTests[group.index] * (myManager.decayRate)));

                if (!isRedirGoal)
                {
                    redirectionDiffusion[group.index]       = redirectionDiffusion[group.index] - (redirectionDiffusion[group.index] * (myManager.decayRate));
                    redirectionStaticDiffusion[group.index] = (redirectionStaticDiffusion[group.index] - (redirectionStaticDiffusion[group.index] * (myManager.decayRate)));
                }
            }
            // If the end hasn't been allocated only apply the decay rate
            else if (!myManager.GetEndAllocated())
            {
                staticDiffusionBases[group.index] = staticDiffusionBases[group.index] - (staticDiffusionBases[group.index] * (myManager.decayRate));
                diffusions[group.index]           = (diffusions[group.index] - (diffusions[group.index] * myManager.decayRate));

                goalTests[group.index]                  = (goalTests[group.index] - (goalTests[group.index] * (myManager.decayRate)));
                redirectionDiffusion[group.index]       = redirectionDiffusion[group.index] - (redirectionDiffusion[group.index] * (myManager.decayRate));
                redirectionStaticDiffusion[group.index] = (redirectionStaticDiffusion[group.index] - (redirectionStaticDiffusion[group.index] * (myManager.decayRate)));
            }


            // If the goal node
            if (group.goals.Contains(this))
            {
                // If there is parking available change the value based on the occupancy
                if (openParking)
                {
                    staticDiffusionBases[group.index] = goalDiffusion;
                    diffusions[group.index]           = goalDiffusion;
                    NodeStatus = NODE_STATUS.END;

                    if (group.origin == GetComponent <ParkingLot>())
                    {
                        goalTests[group.index] = goalDiffusion;
                    }
                }

                // If not open treat the node as a standard node
                else
                {
                    NodeStatus = NODE_STATUS.UNSEARCHED;
                    diffusions[group.index]           = 0;
                    staticDiffusionBases[group.index] = 0;
                }
            }
            //if if redir goals and actual goals overlap
            //MAKE ELSE IF IF YOU WANT TO NOT INCLUDE THE GOALS THAT ARE IN THE GOALS LIST
            if (group.redirectToGoals.Contains(this))
            {
                // If there is parking available change the value based on the occupancy
                if (openParking)
                {
                    redirectionDiffusion[group.index]       = goalDiffusion;
                    redirectionStaticDiffusion[group.index] = goalDiffusion;
                    NodeStatus = NODE_STATUS.END;
                }

                // If not open treat the node as a standard node
                else
                {
                    NodeStatus = NODE_STATUS.UNSEARCHED;
                    redirectionDiffusion[group.index]       = 0;
                    redirectionStaticDiffusion[group.index] = 0;
                }
            }
        }



        //update overall diffusions for redirected goals
        // If there is an end and this node isn't the end and not blocked
        //NONGOALS
        if (myManager.GetEndAllocated() && !goal && NodeStatus != NODE_STATUS.BLOCKED)
        {
            // Stores the origional value for the calculation
            float originalDiff          = diffusion;
            float originalBaseDiffusion = staticDiffusionBase;

            float sumDifference = 1f;

            float divne = 0;
            // For each of the nodes neighbours

            foreach (EdgeScript edge in edges)
            {
                // If they are not a blocked node use thier diffusion value for the equation
                if (edge.GetTo().NodeStatus != NODE_STATUS.BLOCKED && !edge.GetTo().spawner)
                {
                    staticDiffusionBase += (myManager.diffusionCoeff * (edge.GetTo().staticDiffusionBase - originalBaseDiffusion));
                    diffusion           += (myManager.diffusionCoeff * (edge.GetTo().diffusion - originalDiff));
                    divne += (originalBaseDiffusion - edge.GetTo().staticDiffusionBase);

                    sumDifference += (Math.Abs(edge.GetTo().div - div));
                }
            }
            div = divne;
            staticDiffusionBase = staticDiffusionBase - (staticDiffusionBase * (0.1f));

            diffusion = (diffusion + sumDifference * 1f) * (1 - 0.1f);    // Apply the decay rate to the diffusion
            //Debug.Log("diffusion is: "+(diffusion-originalDiff) + "sumdiff: " + sumDifference * 0.6f * (1 - myManager.decayRate));
        }
        // If the end hasn't been allocated only apply the decay rate
        else if (!myManager.GetEndAllocated())
        {
            staticDiffusionBase = staticDiffusionBase - (staticDiffusionBase * (myManager.decayRate));
            diffusion           = (diffusion - (diffusion * myManager.decayRate));
        }
        //GOALS
        // If the goal node is in the list of goals give it goal diffusion
        if (goal)
        {
            // If there is parking available change the value based on the occupancy
            if (openParking)
            {
                staticDiffusionBase = goalDiffusion;
                NodeStatus          = NODE_STATUS.END;
                diffusion           = goalDiffusion;
            }
            // If not open treat the node as a standard node
            else
            {
                NodeStatus          = NODE_STATUS.UNSEARCHED;
                diffusion           = 0;
                staticDiffusionBase = 0;
            }
        }



        // If there's any overlapping avatars
        // update each group outside of loop only once
        if (avatarsOverlapping >= 1)
        {
            overlappedTotalForArea.overlappedTotal += avatarsOverlapping;

            overlappedTotal   += avatarsOverlapping;                                                                                            //56 -> 5.6 -> 5.0 -> 0.5
            timeOfDayE         = (float)(GridManagerScript.hours * 1.0f + Math.Round((Math.Floor(GridManagerScript.minutes * 0.1f) * 0.1), 1)); //get the current time
            floats[timeOfDayE] = floats[timeOfDayE] + avatarsOverlapping;

            avatarsOvelapped[GridManagerScript.hours] = avatarsOvelapped[GridManagerScript.hours] + avatarsOverlapping;

            for (int i = 0; i < myManager.groups.Count; i++)
            {
                PeakingGroup group = groups[i].GetComponent <PeakingGroup>();

                // In not a destination node
                if (group.goals != null && !group.goals.Contains(this))
                {
                    diffusions[group.index] /= GridManagerScript.evasionStrength * avatarsOverlapping;
                }
            }
            //actual diffusion
            diffusion /= GridManagerScript.evasionStrength * avatarsOverlapping;
        }
    }
示例#6
0
        // 子节点设备状态改变事件
        private void Form1_nodeStatusEvt(NODE_STATUS ns)
        {
            string strStatus = string.Empty;

            switch (ns)
            {
            case NODE_STATUS.DEVICE_POWER_OFF:
            {
                strStatus = "DEVICE_POWER_OFF";
            }
            break;

            case NODE_STATUS.DEVICE_STANDBY:
            {
                strStatus = "DEVICE_STANDBY";
            }
            break;

            case NODE_STATUS.DEVICE_INIT_BTN:
            {
                strStatus = "DEVICE_INIT_BTN";
            }
            break;

            case NODE_STATUS.DEVICE_OFFLINE:
            {
                strStatus = "DEVICE_OFFLINE";
            }
            break;

            case NODE_STATUS.DEVICE_ACTIVE:
            {
                strStatus = "DEVICE_ACTIVE";
            }
            break;

            case NODE_STATUS.DEVICE_LOW_POWER_ACTIVE:
            {
                strStatus = "DEVICE_LOW_POWER_ACTIVE";
            }
            break;

            case NODE_STATUS.DEVICE_OTA_MODE:
            {
                strStatus = "DEVICE_OTA_MODE";
            }
            break;

            case NODE_STATUS.DEVICE_OTA_WAIT_SWITCH:
            {
                strStatus = "DEVICE_OTA_WAIT_SWITCH";
            }
            break;

            case NODE_STATUS.DEVICE_DFU_MODE:
            {
                strStatus = "DEVICE_DFU_MODE";
            }
            break;

            case NODE_STATUS.DEVICE_TRYING_POWER_OFF:
            {
                strStatus = "DEVICE_TRYING_POWER_OFF";
            }
            break;

            case NODE_STATUS.DEVICE_FINISHED_PRODUCT_TEST:
            {
                strStatus = "DEVICE_FINISHED_PRODUCT_TEST";
            }
            break;

            case NODE_STATUS.DEVICE_SYNC_MODE:
            {
                strStatus = "DEVICE_SYNC_MODE";
            }
            break;

            //case NODE_STATUS.DEVICE_SEMI_FINISHED_PRODUCT_TEST:
            //    {
            //        strStatus = "DEVICE_SEMI_FINISHED_PRODUCT_TEST";
            //    }
            //    break;
            default:
            {
                strStatus = "UNKNOW";
            }
            break;
            }
            CallDelegate(strStatus);
        }