diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 93f4470a6f..651b377732 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -570,7 +570,7 @@ namespace OpenRA var integralTickTimestep = (uiTickDelta / Timestep) * Timestep; Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Timestep; - Sync.CheckSyncUnchanged(world, Ui.Tick); + Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, Ui.Tick); Cursor.Tick(); } @@ -588,7 +588,7 @@ namespace OpenRA orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep; Sound.Tick(); - Sync.CheckSyncUnchanged(world, orderManager.TickImmediate); + Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, orderManager.TickImmediate); if (world == null) return; @@ -607,7 +607,7 @@ namespace OpenRA if (isNetTick) orderManager.Tick(); - Sync.CheckSyncUnchanged(world, () => + Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => { world.OrderGenerator.Tick(world); world.Selection.Tick(world); @@ -622,7 +622,7 @@ namespace OpenRA // Wait until we have done our first world Tick before TickRendering if (orderManager.LocalFrameNumber > 0) - Sync.CheckSyncUnchanged(world, () => world.TickRender(worldRenderer)); + Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer)); } } } diff --git a/OpenRA.Game/Input/InputHandler.cs b/OpenRA.Game/Input/InputHandler.cs index 71aeaba0ea..df4d359323 100644 --- a/OpenRA.Game/Input/InputHandler.cs +++ b/OpenRA.Game/Input/InputHandler.cs @@ -37,17 +37,17 @@ namespace OpenRA public void OnKeyInput(KeyInput input) { - Sync.CheckSyncUnchanged(world, () => Ui.HandleKeyPress(input)); + Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleKeyPress(input)); } public void OnTextInput(string text) { - Sync.CheckSyncUnchanged(world, () => Ui.HandleTextInput(text)); + Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleTextInput(text)); } public void OnMouseInput(MouseInput input) { - Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input)); + Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleInput(input)); } } diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index d2591225aa..d9c2748991 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -95,7 +95,7 @@ namespace OpenRA [Desc("Amount of time required for triggering perf.log output.")] public float LongTickThresholdMs = 1; - public bool SanityCheckUnsyncedCode = false; + public bool SyncCheckUnsyncedCode = false; public int Samples = 25; public bool StrictActivityChecking = false; diff --git a/OpenRA.Game/Sync.cs b/OpenRA.Game/Sync.cs index 0a67da696d..1a3cb08230 100644 --- a/OpenRA.Game/Sync.cs +++ b/OpenRA.Game/Sync.cs @@ -161,20 +161,19 @@ namespace OpenRA return t.GetHashCode(); } - public static void CheckSyncUnchanged(World world, Action fn) + public static void RunUnsynced(bool checkSyncHash, World world, Action fn) { - CheckSyncUnchanged(world, () => { fn(); return true; }); + RunUnsynced(checkSyncHash, world, () => { fn(); return true; }); } static bool inUnsyncedCode = false; - public static T CheckSyncUnchanged(World world, Func fn) + public static T RunUnsynced(bool checkSyncHash, World world, Func fn) { if (world == null) return fn(); - var shouldCheckSync = Game.Settings.Debug.SanityCheckUnsyncedCode; - var sync = shouldCheckSync ? world.SyncHash() : 0; + var sync = checkSyncHash ? world.SyncHash() : 0; var prevInUnsyncedCode = inUnsyncedCode; inUnsyncedCode = true; @@ -185,8 +184,8 @@ namespace OpenRA finally { inUnsyncedCode = prevInUnsyncedCode; - if (shouldCheckSync && sync != world.SyncHash()) - throw new InvalidOperationException("CheckSyncUnchanged: sync-changing code may not run here"); + if (checkSyncHash && sync != world.SyncHash()) + throw new InvalidOperationException("RunUnsynced: sync-changing code may not run here"); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs index 5e46527ddd..efe5a09664 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var optionsButton = playerRoot.GetOrNull("OPTIONS_BUTTON"); if (optionsButton != null) - Sync.CheckSyncUnchanged(world, optionsButton.OnClick); + Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, optionsButton.OnClick); }; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index c48c7aadeb..6932b8ba6e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -483,7 +483,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic BindCheckboxPref(panel, "NAT_DISCOVERY", ss, "DiscoverNatDevices"); BindCheckboxPref(panel, "PERFTEXT_CHECKBOX", ds, "PerfText"); BindCheckboxPref(panel, "PERFGRAPH_CHECKBOX", ds, "PerfGraph"); - BindCheckboxPref(panel, "CHECKUNSYNCED_CHECKBOX", ds, "SanityCheckUnsyncedCode"); + BindCheckboxPref(panel, "CHECKUNSYNCED_CHECKBOX", ds, "SyncCheckUnsyncedCode"); BindCheckboxPref(panel, "BOTDEBUG_CHECKBOX", ds, "BotDebug"); BindCheckboxPref(panel, "FETCH_NEWS_CHECKBOX", gs, "FetchNews"); BindCheckboxPref(panel, "LUADEBUG_CHECKBOX", ds, "LuaDebug"); @@ -509,7 +509,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ss.DiscoverNatDevices = dss.DiscoverNatDevices; ds.PerfText = dds.PerfText; ds.PerfGraph = dds.PerfGraph; - ds.SanityCheckUnsyncedCode = dds.SanityCheckUnsyncedCode; + ds.SyncCheckUnsyncedCode = dds.SyncCheckUnsyncedCode; ds.BotDebug = dds.BotDebug; ds.LuaDebug = dds.LuaDebug; ds.SendSystemInformation = dds.SendSystemInformation; diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index 7d76fc8ac9..1e2634b698 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -225,7 +225,7 @@ namespace OpenRA.Mods.Common.Widgets public override string GetCursor(int2 screenPos) { - return Sync.CheckSyncUnchanged(World, () => + return Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, World, () => { // Always show an arrow while selecting if (IsValidDragbox)