diff --git a/osu.Game/Overlays/FirstRunSetup/ScreenBehaviour.cs b/osu.Game/Overlays/FirstRunSetup/ScreenBehaviour.cs index a583ba5f6b..00a753f481 100644 --- a/osu.Game/Overlays/FirstRunSetup/ScreenBehaviour.cs +++ b/osu.Game/Overlays/FirstRunSetup/ScreenBehaviour.cs @@ -1,11 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Development; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; @@ -22,7 +19,7 @@ namespace osu.Game.Overlays.FirstRunSetup [LocalisableDescription(typeof(FirstRunSetupOverlayStrings), nameof(FirstRunSetupOverlayStrings.Behaviour))] public partial class ScreenBehaviour : WizardScreen { - private SearchContainer searchContainer; + private SearchContainer searchContainer = null!; [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -91,13 +88,11 @@ namespace osu.Game.Overlays.FirstRunSetup new GraphicsSection(), new OnlineSection(), new MaintenanceSection(), + new DebugSection() }, SearchTerm = SettingsItem.CLASSIC_DEFAULT_SEARCH_TERM, } }; - - if (DebugUtils.IsDebugBuild) - searchContainer.Add(new DebugSection()); } private void applyClassic() diff --git a/osu.Game/Overlays/Settings/Sections/DebugSection.cs b/osu.Game/Overlays/Settings/Sections/DebugSection.cs index 1d2129413c..969e65e823 100644 --- a/osu.Game/Overlays/Settings/Sections/DebugSection.cs +++ b/osu.Game/Overlays/Settings/Sections/DebugSection.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Development; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; @@ -20,12 +21,13 @@ namespace osu.Game.Overlays.Settings.Sections public DebugSection() { - Children = new Drawable[] + if (DebugUtils.IsDebugBuild) { - new GeneralSettings(), - new BatchImportSettings(), - new MemorySettings(), - }; + Add(new GeneralSettings()); + Add(new BatchImportSettings()); + } + + Add(new MemorySettings()); } } } diff --git a/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs index bd6ada4ca7..914fc9d141 100644 --- a/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs @@ -3,7 +3,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; -using osu.Framework.Graphics; using osu.Framework.Localisation; namespace osu.Game.Overlays.Settings.Sections.DebugSettings @@ -15,19 +14,17 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings [BackgroundDependencyLoader] private void load(FrameworkDebugConfigManager config, FrameworkConfigManager frameworkConfig) { - Children = new Drawable[] + Add(new SettingsCheckbox { - new SettingsCheckbox - { - LabelText = @"Show log overlay", - Current = frameworkConfig.GetBindable(FrameworkSetting.ShowLogOverlay) - }, - new SettingsCheckbox - { - LabelText = @"Bypass front-to-back render pass", - Current = config.GetBindable(DebugSetting.BypassFrontToBackPass) - }, - }; + LabelText = @"Show log overlay", + Current = frameworkConfig.GetBindable(FrameworkSetting.ShowLogOverlay) + }); + + Add(new SettingsCheckbox + { + LabelText = @"Bypass front-to-back render pass", + Current = config.GetBindable(DebugSetting.BypassFrontToBackPass) + }); } } } diff --git a/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs b/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs index b693822838..7b9b88a213 100644 --- a/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs +++ b/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs @@ -2,9 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Runtime; using System.Threading; using System.Threading.Tasks; using osu.Framework.Allocation; +using osu.Framework.Development; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Localisation; @@ -24,73 +26,112 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings SettingsButton blockAction; SettingsButton unblockAction; - Children = new Drawable[] + Add(new SettingsButton { - new SettingsButton + Text = @"Clear all caches", + Action = () => { - Text = @"Clear all caches", - Action = host.Collect - }, - new SettingsButton + host.Collect(); + + // host.Collect() uses GCCollectionMode.Optimized, but we should be as aggressive as possible here. + GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); + } + }); + + SettingsEnumDropdown latencyModeDropdown; + Add(latencyModeDropdown = new SettingsEnumDropdown + { + LabelText = "GC mode", + }); + + latencyModeDropdown.Current.BindValueChanged(mode => + { + Logger.Log($"Changing latency mode: {mode.NewValue}"); + + switch (mode.NewValue) { - Text = @"Compact realm", - Action = () => + case GCLatencyMode.Default: + // https://github.com/ppy/osu-framework/blob/1d5301018dfed1a28702be56e1d53c4835b199f2/osu.Framework/Platform/GameHost.cs#L703 + GCSettings.LatencyMode = System.Runtime.GCLatencyMode.SustainedLowLatency; + break; + + case GCLatencyMode.Interactive: + GCSettings.LatencyMode = System.Runtime.GCLatencyMode.Interactive; + break; + } + }); + + if (DebugUtils.IsDebugBuild) + { + AddRange(new Drawable[] + { + new SettingsButton { - // Blocking operations implicitly causes a Compact(). - using (realm.BlockAllOperations(@"compact")) + Text = @"Compact realm", + Action = () => { + // Blocking operations implicitly causes a Compact(). + using (realm.BlockAllOperations(@"compact")) + { + } + } + }, + blockAction = new SettingsButton + { + Text = @"Block realm", + }, + unblockAction = new SettingsButton + { + Text = @"Unblock realm", + } + }); + + blockAction.Action = () => + { + try + { + IDisposable? token = realm.BlockAllOperations(@"maintenance"); + + blockAction.Enabled.Value = false; + + // As a safety measure, unblock after 10 seconds. + // This is to handle the case where a dev may block, but then something on the update thread + // accesses realm and blocks for eternity. + Task.Factory.StartNew(() => + { + Thread.Sleep(10000); + unblock(); + }); + + unblockAction.Action = unblock; + + void unblock() + { + if (token.IsNull()) + return; + + token.Dispose(); + token = null; + + Scheduler.Add(() => + { + blockAction.Enabled.Value = true; + unblockAction.Action = null; + }); } } - }, - blockAction = new SettingsButton - { - Text = @"Block realm", - }, - unblockAction = new SettingsButton - { - Text = @"Unblock realm", - }, - }; - - blockAction.Action = () => - { - try - { - IDisposable? token = realm.BlockAllOperations(@"maintenance"); - - blockAction.Enabled.Value = false; - - // As a safety measure, unblock after 10 seconds. - // This is to handle the case where a dev may block, but then something on the update thread - // accesses realm and blocks for eternity. - Task.Factory.StartNew(() => + catch (Exception e) { - Thread.Sleep(10000); - unblock(); - }); - - unblockAction.Action = unblock; - - void unblock() - { - if (token.IsNull()) - return; - - token.Dispose(); - token = null; - - Scheduler.Add(() => - { - blockAction.Enabled.Value = true; - unblockAction.Action = null; - }); + Logger.Error(e, @"Blocking realm failed"); } - } - catch (Exception e) - { - Logger.Error(e, @"Blocking realm failed"); - } - }; + }; + } + } + + private enum GCLatencyMode + { + Default, + Interactive, } } } diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index a498f2fe1f..3065a4d1bd 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Development; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -31,7 +30,7 @@ namespace osu.Game.Overlays protected override IEnumerable CreateSections() { - var sections = new List + return new List { // This list should be kept in sync with ScreenBehaviour. new GeneralSection(), @@ -44,12 +43,8 @@ namespace osu.Game.Overlays new GraphicsSection(), new OnlineSection(), new MaintenanceSection(), + new DebugSection() }; - - if (DebugUtils.IsDebugBuild) - sections.Add(new DebugSection()); - - return sections; } private readonly List subPanels = new List();