From e488d50e2c2491114f1d38f201697b972151344f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 14 May 2019 13:14:12 +0900 Subject: [PATCH] Make FrameStatistics a bindable for better consumer state management --- osu.Framework/Game.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/osu.Framework/Game.cs b/osu.Framework/Game.cs index bedb4f76ad..c95c71244b 100644 --- a/osu.Framework/Game.cs +++ b/osu.Framework/Game.cs @@ -53,8 +53,6 @@ public abstract class Game : Container, IKeyBindingHandler private readonly Container content; - private PerformanceOverlay performanceContainer; - private DrawVisualiser drawVisualiser; private LogOverlay logOverlay; @@ -172,7 +170,9 @@ protected override void LoadComplete() { base.LoadComplete(); - LoadComponentAsync(performanceContainer = new PerformanceOverlay(Host.Threads.Reverse()) + PerformanceOverlay performanceOverlay; + + LoadComponentAsync(performanceOverlay = new PerformanceOverlay(Host.Threads.Reverse()) { Margin = new MarginPadding(5), Direction = FillDirection.Vertical, @@ -184,40 +184,43 @@ protected override void LoadComplete() Depth = float.MinValue }, AddInternal); + FrameStatistics.BindValueChanged(e => performanceOverlay.State = e.NewValue, true); + addDebugTools(); } - protected FrameStatisticsMode FrameStatisticsMode - { - get => performanceContainer.State; - set => performanceContainer.State = value; - } + protected readonly Bindable FrameStatistics = new Bindable(); public bool OnPressed(FrameworkAction action) { switch (action) { case FrameworkAction.CycleFrameStatistics: - switch (FrameStatisticsMode) + switch (FrameStatistics.Value) { case FrameStatisticsMode.None: - FrameStatisticsMode = FrameStatisticsMode.Minimal; + FrameStatistics.Value = FrameStatisticsMode.Minimal; break; + case FrameStatisticsMode.Minimal: - FrameStatisticsMode = FrameStatisticsMode.Full; + FrameStatistics.Value = FrameStatisticsMode.Full; break; + case FrameStatisticsMode.Full: - FrameStatisticsMode = FrameStatisticsMode.None; + FrameStatistics.Value = FrameStatisticsMode.None; break; } return true; + case FrameworkAction.ToggleDrawVisualiser: drawVisualiser.ToggleVisibility(); return true; + case FrameworkAction.ToggleLogOverlay: logOverlay.ToggleVisibility(); return true; + case FrameworkAction.ToggleFullscreen: Window?.CycleMode(); return true;