Ejemplo n.º 1
0
        public virtual void ProcessFrame()
        {
            (Source as IFrameBasedClock)?.ProcessFrame();

            if (timeUntilNextCalculation <= 0)
            {
                timeUntilNextCalculation += fps_calculation_interval;

                if (framesSinceLastCalculation == 0)
                {
                    FramesPerSecond = 0;
                }
                else
                {
                    FramesPerSecond = (int)Math.Ceiling(framesSinceLastCalculation * 1000f / timeSinceLastCalculation);
                }
                timeSinceLastCalculation = framesSinceLastCalculation = 0;
            }

            framesSinceLastCalculation++;
            timeUntilNextCalculation -= ElapsedFrameTime;
            timeSinceLastCalculation += ElapsedFrameTime;

            AverageFrameTime = Interpolation.Damp(AverageFrameTime, ElapsedFrameTime, 0.01, Math.Abs(ElapsedFrameTime) / 1000);

            LastFrameTime = CurrentTime;
            CurrentTime   = SourceTime;
        }
Ejemplo n.º 2
0
        protected override void Update()
        {
            base.Update();

            if (parallaxEnabled.Value)
            {
                Vector2 offset = Vector2.Zero;

                if (input.CurrentState.Mouse != null)
                {
                    var sizeDiv2 = DrawSize / 2;

                    Vector2 relativeAmount = ToLocalSpace(input.CurrentState.Mouse.Position) - sizeDiv2;

                    const float base_factor = 0.999f;

                    relativeAmount.X = (float)(Math.Sign(relativeAmount.X) * Interpolation.Damp(0, 1, base_factor, Math.Abs(relativeAmount.X)));
                    relativeAmount.Y = (float)(Math.Sign(relativeAmount.Y) * Interpolation.Damp(0, 1, base_factor, Math.Abs(relativeAmount.Y)));

                    offset = relativeAmount * sizeDiv2 * ParallaxAmount;
                }

                double elapsed = Math.Clamp(Clock.ElapsedFrameTime, 0, parallax_duration);

                content.Position = Interpolation.ValueAt(elapsed, content.Position, offset, 0, parallax_duration, Easing.OutQuint);
                content.Scale    = Interpolation.ValueAt(elapsed, content.Scale, new Vector2(1 + Math.Abs(ParallaxAmount)), 0, 1000, Easing.OutQuint);
            }

            firstUpdate = false;
        }
Ejemplo n.º 3
0
        protected override void Update()
        {
            base.Update();

            const float scale_adjust_cutoff    = 0.4f;
            const float velocity_adjust_cutoff = 0.98f;
            const float paused_velocity        = 0.5f;

            if (Beatmap.Value.Track.IsRunning)
            {
                var maxAmplitude = lastBeatIndex >= 0 ? Beatmap.Value.Track.CurrentAmplitudes.Maximum : 0;
                logoAmplitudeContainer.ScaleTo(1 - Math.Max(0, maxAmplitude - scale_adjust_cutoff) * 0.04f, 75, Easing.OutQuint);

                if (maxAmplitude > velocity_adjust_cutoff)
                {
                    triangles.Velocity = 1 + Math.Max(0, maxAmplitude - velocity_adjust_cutoff) * 50;
                }
                else
                {
                    triangles.Velocity = (float)Interpolation.Damp(triangles.Velocity, 1, 0.995f, Time.Elapsed);
                }
            }
            else
            {
                triangles.Velocity = paused_velocity;
            }
        }
Ejemplo n.º 4
0
        protected override void Update()
        {
            base.Update();

            if (!Counting)
            {
                return;
            }

            displayFps = Interpolation.Damp(displayFps, clock.FramesPerSecond, 0.01, clock.ElapsedFrameTime / 1000);

            if (counter.DrawWidth != aimWidth)
            {
                ClearTransformations();

                if (aimWidth == 0)
                {
                    Size = counter.DrawSize;
                }
                else if (Precision.AlmostBigger(counter.DrawWidth, aimWidth))
                {
                    ResizeTo(counter.DrawSize, 200, EasingTypes.InOutSine);
                }
                else
                {
                    Delay(1500);
                    ResizeTo(counter.DrawSize, 500, EasingTypes.InOutSine);
                }

                aimWidth = counter.DrawWidth;
            }

            counter.Text = displayFps.ToString(@"0");
        }
        protected override void Update()
        {
            base.Update();

            complete.Value = Time.Current >= drawableSpinner.Result.TimeCompleted;

            if (complete.Value)
            {
                if (checkNewRotationCount)
                {
                    fill.FinishTransforms(false, nameof(Alpha));
                    fill
                    .FadeTo(tracking_alpha + 0.2f, 60, Easing.OutExpo)
                    .Then()
                    .FadeTo(tracking_alpha, 250, Easing.OutQuint);
                }
            }
            else
            {
                fill.Alpha = (float)Interpolation.Damp(fill.Alpha, drawableSpinner.RotationTracker.Tracking ? tracking_alpha : idle_alpha, 0.98f, (float)Math.Abs(Clock.ElapsedFrameTime));
            }

            const float initial_fill_scale = 0.2f;
            float       targetScale        = initial_fill_scale + (1 - initial_fill_scale) * drawableSpinner.Progress;

            fill.Scale             = new Vector2((float)Interpolation.Lerp(fill.Scale.X, targetScale, Math.Clamp(Math.Abs(Time.Elapsed) / 100, 0, 1)));
            mainContainer.Rotation = drawableSpinner.RotationTracker.Rotation;
        }
Ejemplo n.º 6
0
        protected override void LoadComplete()
        {
            base.LoadComplete();

            double lastUpdate = 0;

            Scheduler.AddDelayed(() =>
                {
                    if (!Counting) return;

                    if (!Precision.AlmostEquals(counter.DrawWidth, aimWidth))
                    {
                        ClearTransforms();

                        if (aimWidth == 0)
                            Size = counter.DrawSize;
                        else if (Precision.AlmostBigger(counter.DrawWidth, aimWidth))
                            this.ResizeTo(counter.DrawSize, 200, Easing.InOutSine);
                        else
                            this.Delay(1500).ResizeTo(counter.DrawSize, 500, Easing.InOutSine);

                        aimWidth = counter.DrawWidth;
                    }

                    double dampRate = Math.Max(Clock.CurrentTime - lastUpdate, 0) / 1000;

                    displayFps = Interpolation.Damp(displayFps, clock.FramesPerSecond, 0.01, dampRate);
                    displayFrameTime = Interpolation.Damp(displayFrameTime, clock.ElapsedFrameTime - clock.SleptTime, 0.01, dampRate);

                    lastUpdate = clock.CurrentTime;

                    counter.Text = $"{displayFps:0}fps({displayFrameTime:0.00}ms)"
                                   + $"{(clock.MaximumUpdateHz < 10000 ? clock.MaximumUpdateHz.ToString("0") : "∞").PadLeft(4)}hz";
                }, 1000.0 / updates_per_second, true);
        }
Ejemplo n.º 7
0
        protected override void LoadComplete()
        {
            base.LoadComplete();

            double lastUpdate = 0;

            thread.Scheduler.AddDelayed(() =>
            {
                if (!Counting)
                {
                    return;
                }

                double clockFps = clock.FramesPerSecond;
                double updateHz = clock.MaximumUpdateHz;

                Schedule(() =>
                {
                    if (!Precision.AlmostEquals(counter.DrawWidth, aimWidth))
                    {
                        ClearTransforms();

                        if (aimWidth == 0)
                        {
                            Size = counter.DrawSize;
                        }
                        else if (Precision.AlmostBigger(counter.DrawWidth, aimWidth))
                        {
                            this.ResizeTo(counter.DrawSize, 200, Easing.InOutSine);
                        }
                        else
                        {
                            this.Delay(1500).ResizeTo(counter.DrawSize, 500, Easing.InOutSine);
                        }

                        aimWidth = counter.DrawWidth;
                    }

                    double dampRate = Math.Max(Clock.CurrentTime - lastUpdate, 0) / 1000;

                    displayFps = Interpolation.Damp(displayFps, clockFps, 0.01, dampRate);
                    if (framesSinceLastUpdate > 0)
                    {
                        rollingElapsed = Interpolation.Damp(rollingElapsed, elapsedSinceLastUpdate / framesSinceLastUpdate, 0.01, dampRate);
                    }

                    lastUpdate = Clock.CurrentTime;

                    framesSinceLastUpdate  = 0;
                    elapsedSinceLastUpdate = 0;

                    counter.Text = $"{displayFps:0}fps({rollingElapsed:0.00}ms)"
                                   + (clock.Throttling ? $"{(updateHz < 10000 ? updateHz.ToString("0") : "∞").PadLeft(4)}hz" : string.Empty);
                });
            }, 1000.0 / updates_per_second, true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Resets all frame statistics. Run exactly once per frame.
        /// </summary>
        public void NewFrame()
        {
            // Reset the counters we keep track of
            for (int i = 0; i < ActiveCounters.Length; ++i)
            {
                if (ActiveCounters[i])
                {
                    long count = FrameStatistics.COUNTERS[i];
                    var  type  = (StatisticsCounterType)i;

                    if (!globalStatistics.TryGetValue(type, out var global))
                    {
                        globalStatistics[type] = global = GlobalStatistics.Get <long>(threadName, type.ToString());
                    }

                    global.Value = count;
                    currentFrame.Counts[type]    = count;
                    currentFrame.FramesPerSecond = Clock.FramesPerSecond;

                    FrameStatistics.COUNTERS[i] = 0;
                }
            }

            if (PendingFrames.Count < max_pending_frames - 1)
            {
                PendingFrames.Enqueue(currentFrame);
                currentFrame = FramesPool.Get();
            }

            currentFrame.Clear();

            if (HandleGC)
            {
                for (int i = 0; i < lastAmountGarbageCollects.Length; ++i)
                {
                    int amountCollections = GC.CollectionCount(i);

                    if (lastAmountGarbageCollects[i] != amountCollections)
                    {
                        lastAmountGarbageCollects[i] = amountCollections;
                        currentFrame.GarbageCollections.Add(i);
                    }
                }
            }

            double dampRate = Math.Max(Clock.ElapsedFrameTime, 0) / 1000;

            averageFrameTime = Interpolation.Damp(averageFrameTime, Clock.ElapsedFrameTime, 0.01, dampRate);

            //check for dropped (stutter) frames
            traceCollector?.NewFrame(Clock.ElapsedFrameTime, Math.Max(10, Math.Max(1000 / Clock.MaximumUpdateHz, averageFrameTime) * 4));

            consumeStopwatchElapsedTime();
        }
Ejemplo n.º 9
0
        protected override void Update()
        {
            base.Update();

            if (!Counting)
            {
                return;
            }

            displayFPS = Interpolation.Damp(displayFPS, clock.FramesPerSecond, 0.01, Clock.ElapsedFrameTime / 1000);

            counter.Text = displayFPS.ToString(@"0");
        }
Ejemplo n.º 10
0
        protected override void Update()
        {
            base.Update();

            const float scale_adjust_cutoff = 0.4f;
            const float velocity_adjust_cutoff = 0.98f;

            var maxAmplitude = lastBeatIndex >= 0 ? Beatmap.Value?.Track?.CurrentAmplitudes.Maximum ?? 0 : 0;
            logoAmplitudeContainer.ScaleTo(1 - Math.Max(0, maxAmplitude - scale_adjust_cutoff) * 0.04f, 75, EasingTypes.OutQuint);

            if (maxAmplitude > velocity_adjust_cutoff)
                triangles.Velocity = 1 + Math.Max(0, maxAmplitude - velocity_adjust_cutoff) * 50;
            else
                triangles.Velocity = (float)Interpolation.Damp(triangles.Velocity, 1, 0.995f, Time.Elapsed);
        }
        protected override void Update()
        {
            base.Update();
            var thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));

            var delta = thisAngle - lastAngle;

            if (Tracking)
            {
                AddRotation(delta);
            }

            lastAngle = thisAngle;

            IsSpinning.Value = isSpinnableTime && Math.Abs(currentRotation / 2 - Rotation) > 5f;

            Rotation = (float)Interpolation.Damp(Rotation, currentRotation / 2, 0.99, Math.Abs(Time.Elapsed));
        }
Ejemplo n.º 12
0
        private void updateDisplay()
        {
            double dampRate = Math.Max(Clock.CurrentTime - lastUpdateLocalTime, 0) / 1000;

            displayFps = Interpolation.Damp(displayFps, lastFrameFramesPerSecond, 0.01, dampRate);

            if (framesSinceLastUpdate > 0)
            {
                rollingElapsed = Interpolation.Damp(rollingElapsed, elapsedSinceLastUpdate / framesSinceLastUpdate, 0.01, dampRate);
            }

            lastUpdateLocalTime = Clock.CurrentTime;

            framesSinceLastUpdate  = 0;
            elapsedSinceLastUpdate = 0;

            counter.Text = $"{displayFps:0}fps ({rollingElapsed:0.00}ms)"
                           + (clock.Throttling ? $"{(clock.MaximumUpdateHz > 0 && clock.MaximumUpdateHz < 10000 ? clock.MaximumUpdateHz.ToString("0") : "∞"),4}hz" : string.Empty);
        }
Ejemplo n.º 13
0
 protected override double CalculateAverageFrameTime() => Interpolation.Damp(AverageFrameTime, ElapsedFrameTime - SleptTime, 0.01, Math.Max(ElapsedFrameTime, 0) / 1000);
Ejemplo n.º 14
0
 protected virtual double CalculateAverageFrameTime() => Interpolation.Damp(AverageFrameTime, ElapsedFrameTime, 0.01, Math.Max(ElapsedFrameTime, 0) / 1000);