Ejemplo n.º 1
0
 private void RevertState()
 {
     extender.AssumeState(lastRequestState);
 }
        /// <summary>
        /// This is the top level of the replay coroutine.
        /// Conventionally it is called by the Run button in the GUI and at the end of the last replay iteration.
        /// </summary>
        /// <returns></returns>
        IEnumerator RunNextIterationCoroutine(long steps)
        {
            while (!Initialized || !Ready)
            {
                yield return(0);
            }

            itersSinceRun = 0;

            while (Running)
            {
                // We need a consensus on readyness before next iteration
                while (!Ready)
                {
                    yield return(0);
                }

                HeavyDebug("extender.OnIterationState()");
                yield return(StartCoroutine(extender.OnIterationStart()));

                // loop on the agent until we have a next action
                do
                {
                    HeavyDebug("GetNextAction()");
                    yield return(StartCoroutine(GetNextAction()));

                    if (!agent.HasNext)
                    {
                        EndRun();
                        yield break;
                    }
                } while (agent.HasNext && extender.SkipAction(agent.CurrentAction));

                // let the extender know about pre-action
                HeavyDebug("extender.OnActionPre()");
                yield return(StartCoroutine(extender.OnActionPre(agent.CurrentAction)));

                HeavyDebug("interpreter.ResetInterpretation()");
                yield return(StartCoroutine(interpreter.ResetInterpretation()));

                HeavyDebug("extender.AssumeState()");
                yield return(StartCoroutine(extender.AssumeState(agent.CurrentAction.StateObject)));

                Time.timeScale = NormalSpeed;

                HeavyDebug("extender.PerformAction()");
                yield return(StartCoroutine(extender.PerformAction(agent.CurrentAction)));

                if (screenshotTiming == ScreenShotTimingOption.OnCreate)
                {
                    HeavyDebug("CaptureScreenShot()");
                    yield return(StartCoroutine(CaptureScreenShot(interpreter.ScreenShotName(agent.CurrentAction))));
                }

                Time.timeScale = TimeAcceleration;

                HeavyDebug("WaitForStop()");
                yield return(StartCoroutine(WaitForStop(agent.CurrentAction)));

                HeavyDebug("extender.OnStop()");
                yield return(StartCoroutine(extender.OnStop(agent.CurrentAction)));

                //Time.timeScale = 0f;

                //screenshot
                if (screenshotTiming == ScreenShotTimingOption.OnStop)
                {
                    HeavyDebug("CaptureScreenShot()");
                    yield return(StartCoroutine(CaptureScreenShot(interpreter.ScreenShotName(agent.CurrentAction))));
                }

                //calculate
                HeavyDebug("interpreter.InterpretAction()");
                yield return(StartCoroutine(interpreter.InterpretAction(agent.CurrentAction)));

                // let an agent learn is necessary
                HeavyDebug("agent.EvaluateActionResult()");
                yield return(StartCoroutine(agent.EvaluateActionResult()));

                HeavyDebug("interpreter.CommitInterpretation()");
                yield return(StartCoroutine(interpreter.CommitInterpretation()));

                if (screenshotTiming == ScreenShotTimingOption.OnWrite)
                {
                    HeavyDebug("CaptureScreenShot()");
                    yield return(StartCoroutine(CaptureScreenShot(interpreter.ScreenShotName(agent.CurrentAction))));
                }

                //yield return StartCoroutine(interpreter.InterpretAction(agent.CurrentAction));

                //yield return StartCoroutine(interpreter.CommitInterpretation());

                HeavyDebug("extender.OnIterationEnd()");
                yield return(StartCoroutine(extender.OnIterationEnd()));

                itersSinceRun++;

                if (steps > 0 && itersSinceRun == steps)
                {
                    Pause();
                }
            }
            yield break;
        }