IsInTestMode() private method

private IsInTestMode ( ) : bool
return bool
Beispiel #1
0
        public bool StepDone(bool updateValues)
        {
            if (!timedNode.IsMasterNode())
            {
                TimedTrafficLights masterLights = timedNode.MasterLights();
                return(masterLights.Steps[masterLights.CurrentStep].StepDone(updateValues));
            }
            // we are the master node

            if (timedNode.IsInTestMode())
            {
                return(false);
            }
            if (stepDone)
            {
                return(true);
            }

            if (getCurrentFrame() >= startFrame + maxTime)
            {
                // maximum time reached. switch!
#if DEBUG
                //Log.Message("step finished @ " + nodeId);
#endif
                if (!stepDone && updateValues)
                {
                    stepDone           = true;
                    endTransitionStart = getCurrentFrame();
                }
                return(stepDone);
            }

            if (getCurrentFrame() >= startFrame + minTime)
            {
                float wait, flow;
                uint  curFrame = getCurrentFrame();
                //Log._Debug($"TTL @ {timedNode.NodeId}: curFrame={curFrame} lastFlowWaitCalc={lastFlowWaitCalc}");
                if (lastFlowWaitCalc < curFrame)
                {
                    //Log._Debug($"TTL @ {timedNode.NodeId}: lastFlowWaitCalc<curFrame");
                    if (!calcWaitFlow(true, timedNode.CurrentStep, out wait, out flow))
                    {
                        //Log._Debug($"TTL @ {timedNode.NodeId}: calcWaitFlow failed!");
                        if (!stepDone && updateValues)
                        {
                            //Log._Debug($"TTL @ {timedNode.NodeId}: !stepDone && updateValues");
                            stepDone           = true;
                            endTransitionStart = getCurrentFrame();
                        }
                        return(stepDone);
                    }
                    else
                    {
                        if (updateValues)
                        {
                            lastFlowWaitCalc = curFrame;
                            //Log._Debug($"TTL @ {timedNode.NodeId}: updated lastFlowWaitCalc=curFrame={curFrame}");
                        }
                    }
                }
                else
                {
                    flow = minFlow;
                    wait = maxWait;
                    //Log._Debug($"TTL @ {timedNode.NodeId}: lastFlowWaitCalc>=curFrame wait={maxWait} flow={minFlow}");
                }

                float newFlow = minFlow;
                float newWait = maxWait;

#if DEBUGMETRIC
                newFlow = flow;
                newWait = wait;
#else
                if (Single.IsNaN(newFlow))
                {
                    newFlow = flow;
                }
                else
                {
                    newFlow = 0.1f * newFlow + 0.9f * flow;                     // some smoothing
                }
                if (Single.IsNaN(newWait))
                {
                    newWait = 0;
                }
                else
                {
                    newWait = 0.1f * newWait + 0.9f * wait;                     // some smoothing
                }
#endif

                // if more cars are waiting than flowing, we change the step
                bool done = newWait > 0 && newFlow < newWait;

                //Log._Debug($"TTL @ {timedNode.NodeId}: newWait={newWait} newFlow={newFlow} updateValues={updateValues} stepDone={stepDone} done={done}");

                if (updateValues)
                {
                    minFlow = newFlow;
                    maxWait = newWait;
                    //Log._Debug($"TTL @ {timedNode.NodeId}: updated minFlow=newFlow={minFlow} maxWait=newWait={maxWait}");
                }
#if DEBUG
                //Log.Message("step finished (2) @ " + nodeId);
#endif
                if (updateValues && !stepDone && done)
                {
                    stepDone           = done;
                    endTransitionStart = getCurrentFrame();
                }
                return(stepDone);
            }

            return(false);
        }
        public bool StepDone(bool updateValues)
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("TimedTrafficLightsStep.StepDone");
#endif
            if (timedNode.IsInTestMode())
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                return(false);
            }
            if (stepDone)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                return(true);
            }

            if (getCurrentFrame() >= startFrame + maxTime)
            {
                // maximum time reached. switch!
#if DEBUG
                //Log.Message("step finished @ " + nodeId);
#endif
                stepDone           = true;
                endTransitionStart = getCurrentFrame();
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                return(stepDone);
            }

            if (getCurrentFrame() >= startFrame + minTime)
            {
                if (!timedNode.isMasterNode())
                {
                    TimedTrafficLights masterLights = timedNode.MasterLights();

                    if (masterLights == null)
                    {
                        invalid            = true;
                        stepDone           = true;
                        endTransitionStart = getCurrentFrame();
#if TRACE
                        Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                        return(true);
                    }
                    bool done = masterLights.Steps[masterLights.CurrentStep].StepDone(updateValues);
#if DEBUG
                    //Log.Message("step finished (1) @ " + nodeId);
#endif
                    stepDone = done;
                    if (stepDone)
                    {
                        endTransitionStart = getCurrentFrame();
                    }
#if TRACE
                    Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                    return(stepDone);
                }
                else
                {
                    // we are the master node
                    float wait, flow;
                    uint  curFrame = getCurrentFrame();
                    if (lastFlowWaitCalc < curFrame)
                    {
                        if (!calcWaitFlow(out wait, out flow))
                        {
                            stepDone           = true;
                            endTransitionStart = getCurrentFrame();
#if TRACE
                            Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                            return(stepDone);
                        }
                        else
                        {
                            lastFlowWaitCalc = curFrame;
                        }
                    }
                    else
                    {
                        flow = minFlow;
                        wait = maxWait;
                    }
                    float newFlow = minFlow;
                    float newWait = maxWait;

#if DEBUGMETRIC
                    newFlow = flow;
                    newWait = wait;
#else
                    if (Single.IsNaN(newFlow))
                    {
                        newFlow = flow;
                    }
                    else
                    {
                        newFlow = 0.1f * newFlow + 0.9f * flow;                         // some smoothing
                    }
                    if (Single.IsNaN(newWait))
                    {
                        newWait = 0;
                    }
                    else
                    {
                        newWait = 0.1f * newWait + 0.9f * wait;                         // some smoothing
                    }
#endif

                    // if more cars are waiting than flowing, we change the step
#if DEBUGMETRIC
                    bool done = false;
#else
                    bool done = newWait > 0 && newFlow < newWait;
#endif
                    if (updateValues)
                    {
                        minFlow = newFlow;
                        maxWait = newWait;
                    }
#if DEBUG
                    //Log.Message("step finished (2) @ " + nodeId);
#endif
                    if (updateValues)
                    {
                        stepDone = done;
                    }
                    if (stepDone)
                    {
                        endTransitionStart = getCurrentFrame();
                    }
#if TRACE
                    Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
                    return(stepDone);
                }
            }

#if TRACE
            Singleton <CodeProfiler> .instance.Stop("TimedTrafficLightsStep.StepDone");
#endif
            return(false);
        }
        public bool StepDone(bool updateValues)
        {
            if (timedNode.IsInTestMode())
            {
                return(false);
            }
            if (stepDone)
            {
                return(true);
            }

            if (getCurrentFrame() >= startFrame + maxTime)
            {
                // maximum time reached. switch!
#if DEBUG
                //Log.Message("step finished @ " + nodeId);
#endif
                stepDone           = true;
                endTransitionStart = getCurrentFrame();
                return(stepDone);
            }

            if (getCurrentFrame() >= startFrame + minTime)
            {
                if (timedNode.masterNodeId != timedNode.NodeId)
                {
                    TrafficLightSimulation masterSim = TrafficLightSimulation.GetNodeSimulation(timedNode.masterNodeId);

                    if (masterSim == null || !masterSim.IsTimedLight())
                    {
                        invalid            = true;
                        stepDone           = true;
                        endTransitionStart = getCurrentFrame();
                        return(true);
                    }
                    TimedTrafficLights masterTimedNode = masterSim.TimedLight;
                    bool done = masterTimedNode.Steps[masterTimedNode.CurrentStep].StepDone(updateValues);
#if DEBUG
                    //Log.Message("step finished (1) @ " + nodeId);
#endif
                    stepDone = done;
                    if (stepDone)
                    {
                        endTransitionStart = getCurrentFrame();
                    }
                    return(stepDone);
                }
                else
                {
                    // we are the master node
                    float wait, flow;
                    uint  curFrame = getCurrentFrame();
                    if (lastFlowWaitCalc < curFrame)
                    {
                        if (!calcWaitFlow(out wait, out flow))
                        {
                            stepDone           = true;
                            endTransitionStart = getCurrentFrame();
                            return(stepDone);
                        }
                        else
                        {
                            lastFlowWaitCalc = curFrame;
                        }
                    }
                    else
                    {
                        flow = minFlow;
                        wait = maxWait;
                    }
                    float newFlow = minFlow;
                    float newWait = maxWait;

                    if (Single.IsNaN(newFlow))
                    {
                        newFlow = flow;
                    }
                    else
                    {
                        newFlow = 0.1f * newFlow + 0.9f * flow;                         // some smoothing
                    }
                    if (Single.IsNaN(newWait))
                    {
                        newWait = 0;
                    }
                    else
                    {
                        newWait = 0.1f * newWait + 0.9f * wait;                         // some smoothing
                    }
                    // if more cars are waiting than flowing, we change the step
                    bool done = newWait > 0 && newFlow < newWait;
                    if (updateValues)
                    {
                        minFlow = newFlow;
                        maxWait = newWait;
                    }
#if DEBUG
                    //Log.Message("step finished (2) @ " + nodeId);
#endif
                    if (updateValues)
                    {
                        stepDone = done;
                    }
                    if (stepDone)
                    {
                        endTransitionStart = getCurrentFrame();
                    }
                    return(stepDone);
                }
            }

            return(false);
        }