internal void Evaluate()
        {
            var realTimeNow = DateTime.UtcNow;
            // while the simulation time is ahead of the wall clock, spin
            var wallClockTimeElapsed = realTimeNow - wallClockTimeAdded;
            var age = t.Now - timeAdded;

            while (Enabled && age > wallClockTimeElapsed)
            {
                wallClockTimeElapsed = DateTime.UtcNow - wallClockTimeAdded;
            }

            var idleTime = DateTime.UtcNow - realTimeNow;

            busyPercentageAverage.AddSample(1 - (idleTime.TotalSeconds / t.Increment.TotalSeconds));
            sleepTimeAverage.AddSample(idleTime.TotalMilliseconds);
            age = t.Now - timeAdded;

            // At this point, we're sure that the wall clock is equal to or ahead of the simulation time.

            // If the wall clock is ahead by too much then the simulation is falling behind. Calculate the amount.
            var behindAmount = wallClockTimeElapsed - age;

            // Send the latest behind amount to the behind signal debouncer.
            behindSignal.Update(behindAmount.TotalMilliseconds);
        }
Exemplo n.º 2
0
        internal void Evaluate()
        {
            var realTimeNow = DateTime.UtcNow;
            // while the simulation time is ahead of the wall clock, spin
            var wallClockTimeElapsed  = TimeSpan.FromSeconds(1 * (realTimeNow - wallClockSample).TotalSeconds);
            var simulationTimeElapsed = TimeSpan.FromSeconds(SlowMoRatio * (t.Now - simulationTimeSample).TotalSeconds);
            var slept = false;

            if (Enabled && simulationTimeElapsed > wallClockTimeElapsed)
            {
                var sleepTime = simulationTimeElapsed - wallClockTimeElapsed;
                Thread.Sleep(sleepTime);
                slept = true;
            }

            wallClockTimeElapsed = DateTime.UtcNow - wallClockSample;

            if (slept == false)
            {
                ZeroSleepCycles++;
                Time.CurrentTime.QueueAction("Clogged", () => { });
            }
            else
            {
                SleepCycles++;
            }

            var idleTime = DateTime.UtcNow - realTimeNow;

            busyPercentageAverage.AddSample(1 - (idleTime.TotalSeconds / t.Increment.TotalSeconds));
            sleepTimeAverage.AddSample(idleTime.TotalMilliseconds);
            simulationTimeElapsed = t.Now - simulationTimeSample;

            // At this point, we're sure that the wall clock is equal to or ahead of the simulation time.

            // If the wall clock is ahead by too much then the simulation is falling behind. Calculate the amount.
            var behindAmount = wallClockTimeElapsed - simulationTimeElapsed;

            // Send the latest behind amount to the behind signal debouncer.
            behindSignal.Update(behindAmount.TotalMilliseconds);
            wallClockSample      = DateTime.UtcNow;
            simulationTimeSample = t.Now;
        }
Exemplo n.º 3
0
        internal void Evaluate()
        {
            var realTimeNow = DateTime.UtcNow;
            // while the simulation time is ahead of the wall clock, spin
            var wallClockTimeElapsed = realTimeNow - wallClockSample;
            var age   = t.Now - simulationTimeSample;
            var slept = false;

            if (Enabled && age > wallClockTimeElapsed)
            {
                var sleepTime = age - wallClockTimeElapsed;
                Thread.Sleep(sleepTime);
                slept = true;
            }

            wallClockTimeElapsed = DateTime.UtcNow - wallClockSample;

            if (slept == false)
            {
                ZeroSleepCycles++;
            }
            else
            {
                SleepCycles++;
            }

            var idleTime = DateTime.UtcNow - realTimeNow;

            busyPercentageAverage.AddSample(1 - (idleTime.TotalSeconds / t.Increment.TotalSeconds));
            sleepTimeAverage.AddSample(idleTime.TotalMilliseconds);
            age = t.Now - simulationTimeSample;

            // At this point, we're sure that the wall clock is equal to or ahead of the simulation time.

            // If the wall clock is ahead by too much then the simulation is falling behind. Calculate the amount.
            var behindAmount = wallClockTimeElapsed - age;

            // Send the latest behind amount to the behind signal debouncer.
            behindSignal.Update(behindAmount.TotalMilliseconds);
            ReSync();
        }