public void PlanRouteAndStep()
        {
            if (stopped || busy)
            {
                return;
            }

            if (agent.state == Agents.AgentState.Finished)
            {
                GoalReachedEvent();
                return;
            }

            busy = true;

            SearchState state = new SearchState();

            state.id    = agent.id;
            state.color = color;
            state.goal  = agent.goal;

            stopWatch_runTime.Start();

            // Procesor time measurement
            stopWatch_procTime.Start();
            state.path = agent.PlanRouteAndStep();
            stopWatch_procTime.Stop();
            // Measurement ends

            stopWatch_runTime.Stop();

            state.procTime   = stopWatch_procTime.Elapsed;
            state.runTime    = (speedLimitEnabled ? TimeSpan.FromMilliseconds(Math.Max(stopWatch_runTime.ElapsedMilliseconds, waitTime)) : stopWatch_procTime.Elapsed) + runTime_previous;
            runTime_previous = state.runTime;
            stopWatch_runTime.Reset();

            state.stepNumber      = agent.stepNumber;
            state.traversedNodes  = agent.GetTraversedNodes();
            state.discoveredNodes = agent.GetDiscoveredNodes();
            state.distance        = agent.GetDistanceTraveled();

            ReportStateEvent(state);

            busy = false;

            if (!speedLimitEnabled)
            {
                PlanRouteAndStep();
            }
        }
Exemplo n.º 2
0
        public void ProgressChanged(SearchState s)
        {
            for (int i = 0; i < searchStates.Count; i++)
            {
                if (searchStates[i].id == s.id)
                {
                    lock (searchStateSyncroot)
                    {
                        searchStates[i] = s;
                    }
                    Invalidate();
                    return;
                }
            }

            lock (searchStateSyncroot)
            {
                isSearchStateVisible[s.id] = true;
                searchStates.Add(s);
            }
            Invalidate();
        }
 public void ProgressChanged(SearchState state)
 {
     this.state = state;
     Invalidate();
 }