/// <summary>
        /// The main update method of the replay manager.
        /// Causes the replay manager to update its state based on the current <see cref="state"/>.
        /// </summary>
        /// <param name="deltaTime"></param>
        public void UpdateState(float deltaTime)
        {
            if (deltaTime <= 0f)
            {
                Debug.Log(Time.timeScale);
                throw new InvalidOperationException("Delta time value must be greater than '0'");
            }

            switch (state)
            {
            case PlaybackState.Idle: break;

            case PlaybackState.Playback_Paused: break;     // Do nothing

            case PlaybackState.Recording_Paused: break;    // Do nothing

            case PlaybackState.Recording_Paused_Playback:
            case PlaybackState.Playback:
            {
                // Make sure we are not in single frame mode
                if (singlePlayback == false)
                {
                    ReplaySnapshot frame;

                    // Update the sequencer
                    ReplaySequenceResult result = sequence.UpdatePlayback(out frame, playbackEndBehaviour, deltaTime);

                    // Check if the sequence has a new frame to be displayed
                    if (result == ReplaySequenceResult.SequenceAdvance)
                    {
                        // Restore the scene state
                        scene.RestoreSnapshot(frame, Target.InitialStateBuffer);
                    }
                    // Check if the sequence is at the end of the recording
                    else if (result == ReplaySequenceResult.SequenceEnd)
                    {
                        StopPlayback();
                    }

                    // Update the playback
                    if (result == ReplaySequenceResult.SequenceIdle ||
                        result == ReplaySequenceResult.SequenceAdvance)
                    {
                        // This calls 'updateReplay' on all replay obejcts in the scene
                        ReplayBehaviour.Events.CallReplayUpdateEvents();
                    }
                }
            } break;

            case PlaybackState.Recording:
            {
                // Update the replay timer - Pass the delta time instead of using Time.deltaTime
                ReplayTimer.Tick(deltaTime);

                // Make sure enough time has passed to record a sample
                if (recordStepTimer.HasElapsed() == true)
                {
                    // Get the scene state
                    ReplaySnapshot currentState = scene.RecordSnapshot(Instance.recordTimer.ElapsedSeconds, Target.InitialStateBuffer);

                    // Write it to the replay target
                    Target.RecordSnapshot(currentState);
                }
            } break;
            }
        }
示例#2
0
        private void AsyncThread_DoWork(object sender)
        {
            ReplayTimer Time = new ReplayTimer();

            float statusPrevTime       = 0;
            float rangePrevTime        = 0;
            RangeDeviceEventArgs rPrev = null;
            StatusEventArgs      sPrev = null;

            Time.Reset();
            Time.Start();

            StatusDataReceived?.Invoke(new object(), StartingStatusEventArgs);
            foreach (RangeDeviceEventArgs e in StartingRangeDeviceCurrentReadings)
            {
                RangeDeviceCurrentDataReceived?.Invoke(new object(), e);
            }

            while (IsRunning)
            {
                if (IsPaused)
                {
                    Time.Stop();
                    Thread.Sleep(UpdateRate);
                    continue;
                }
                Time.Start();
                Time.Tick();


                foreach (RangeDeviceEventArgs r in ReplayLaserEntries)
                {
                    if (r.Timestamp >= Time.TotalTime)
                    {
                        if (r.Timestamp == rangePrevTime)
                        {
                            break;
                        }
                        rangePrevTime = r.Timestamp;

                        if (rPrev == null)
                        {
                            rPrev = r;
                        }

                        RangeDeviceCurrentDataReceived?.Invoke(new object(), rPrev);

                        rPrev = r;

                        break;
                    }
                }

                foreach (StatusEventArgs r in ReplayStatusEntries)
                {
                    if (r.Timestamp >= Time.TotalTime)
                    {
                        if (r.Timestamp == statusPrevTime)
                        {
                            break;
                        }
                        statusPrevTime = r.Timestamp;

                        if (sPrev == null)
                        {
                            sPrev = r;
                        }

                        StatusDataReceived?.Invoke(new object(), sPrev);

                        sPrev = r;

                        break;
                    }
                }

                Thread.Sleep(UpdateRate);

                //Robot.Write("onelinestatus");
                //foreach (string l in Devices)
                //{
                //    Robot.Write("rangeDeviceGetCurrent " + l);
                //}
                //foreach (string l in Devices)
                //{
                //    Robot.Write("rangeDeviceGetCumulative " + l);
                //}
            }
        }