Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FrameStatistics a bindable for better consumer state management #2399

Merged
merged 2 commits into from
May 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions osu.Framework/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public abstract class Game : Container, IKeyBindingHandler<FrameworkAction>

private readonly Container content;

private PerformanceOverlay performanceContainer;

private DrawVisualiser drawVisualiser;

private LogOverlay logOverlay;
Expand Down Expand Up @@ -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,
Expand All @@ -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<FrameStatisticsMode> FrameStatistics = new Bindable<FrameStatisticsMode>();

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;
Expand Down