Rework and rename Sync.CheckSyncUnchanged

This commit is contained in:
Paul Chote
2018-12-23 22:37:45 +00:00
committed by reaperrr
parent b41c178cb9
commit 83e44bee66
7 changed files with 18 additions and 19 deletions

View File

@@ -570,7 +570,7 @@ namespace OpenRA
var integralTickTimestep = (uiTickDelta / Timestep) * Timestep; var integralTickTimestep = (uiTickDelta / Timestep) * Timestep;
Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Timestep; Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Timestep;
Sync.CheckSyncUnchanged(world, Ui.Tick); Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, Ui.Tick);
Cursor.Tick(); Cursor.Tick();
} }
@@ -588,7 +588,7 @@ namespace OpenRA
orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep; orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;
Sound.Tick(); Sound.Tick();
Sync.CheckSyncUnchanged(world, orderManager.TickImmediate); Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, orderManager.TickImmediate);
if (world == null) if (world == null)
return; return;
@@ -607,7 +607,7 @@ namespace OpenRA
if (isNetTick) if (isNetTick)
orderManager.Tick(); orderManager.Tick();
Sync.CheckSyncUnchanged(world, () => Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () =>
{ {
world.OrderGenerator.Tick(world); world.OrderGenerator.Tick(world);
world.Selection.Tick(world); world.Selection.Tick(world);
@@ -622,7 +622,7 @@ namespace OpenRA
// Wait until we have done our first world Tick before TickRendering // Wait until we have done our first world Tick before TickRendering
if (orderManager.LocalFrameNumber > 0) if (orderManager.LocalFrameNumber > 0)
Sync.CheckSyncUnchanged(world, () => world.TickRender(worldRenderer)); Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer));
} }
} }
} }

View File

@@ -37,17 +37,17 @@ namespace OpenRA
public void OnKeyInput(KeyInput input) 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) 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) public void OnMouseInput(MouseInput input)
{ {
Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input)); Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleInput(input));
} }
} }

View File

@@ -95,7 +95,7 @@ namespace OpenRA
[Desc("Amount of time required for triggering perf.log output.")] [Desc("Amount of time required for triggering perf.log output.")]
public float LongTickThresholdMs = 1; public float LongTickThresholdMs = 1;
public bool SanityCheckUnsyncedCode = false; public bool SyncCheckUnsyncedCode = false;
public int Samples = 25; public int Samples = 25;
public bool StrictActivityChecking = false; public bool StrictActivityChecking = false;

View File

@@ -161,20 +161,19 @@ namespace OpenRA
return t.GetHashCode(); 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; static bool inUnsyncedCode = false;
public static T CheckSyncUnchanged<T>(World world, Func<T> fn) public static T RunUnsynced<T>(bool checkSyncHash, World world, Func<T> fn)
{ {
if (world == null) if (world == null)
return fn(); return fn();
var shouldCheckSync = Game.Settings.Debug.SanityCheckUnsyncedCode; var sync = checkSyncHash ? world.SyncHash() : 0;
var sync = shouldCheckSync ? world.SyncHash() : 0;
var prevInUnsyncedCode = inUnsyncedCode; var prevInUnsyncedCode = inUnsyncedCode;
inUnsyncedCode = true; inUnsyncedCode = true;
@@ -185,8 +184,8 @@ namespace OpenRA
finally finally
{ {
inUnsyncedCode = prevInUnsyncedCode; inUnsyncedCode = prevInUnsyncedCode;
if (shouldCheckSync && sync != world.SyncHash()) if (checkSyncHash && sync != world.SyncHash())
throw new InvalidOperationException("CheckSyncUnchanged: sync-changing code may not run here"); throw new InvalidOperationException("RunUnsynced: sync-changing code may not run here");
} }
} }

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var optionsButton = playerRoot.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON"); var optionsButton = playerRoot.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
if (optionsButton != null) if (optionsButton != null)
Sync.CheckSyncUnchanged(world, optionsButton.OnClick); Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, optionsButton.OnClick);
}; };
} }
} }

View File

@@ -483,7 +483,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
BindCheckboxPref(panel, "NAT_DISCOVERY", ss, "DiscoverNatDevices"); BindCheckboxPref(panel, "NAT_DISCOVERY", ss, "DiscoverNatDevices");
BindCheckboxPref(panel, "PERFTEXT_CHECKBOX", ds, "PerfText"); BindCheckboxPref(panel, "PERFTEXT_CHECKBOX", ds, "PerfText");
BindCheckboxPref(panel, "PERFGRAPH_CHECKBOX", ds, "PerfGraph"); 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, "BOTDEBUG_CHECKBOX", ds, "BotDebug");
BindCheckboxPref(panel, "FETCH_NEWS_CHECKBOX", gs, "FetchNews"); BindCheckboxPref(panel, "FETCH_NEWS_CHECKBOX", gs, "FetchNews");
BindCheckboxPref(panel, "LUADEBUG_CHECKBOX", ds, "LuaDebug"); BindCheckboxPref(panel, "LUADEBUG_CHECKBOX", ds, "LuaDebug");
@@ -509,7 +509,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
ss.DiscoverNatDevices = dss.DiscoverNatDevices; ss.DiscoverNatDevices = dss.DiscoverNatDevices;
ds.PerfText = dds.PerfText; ds.PerfText = dds.PerfText;
ds.PerfGraph = dds.PerfGraph; ds.PerfGraph = dds.PerfGraph;
ds.SanityCheckUnsyncedCode = dds.SanityCheckUnsyncedCode; ds.SyncCheckUnsyncedCode = dds.SyncCheckUnsyncedCode;
ds.BotDebug = dds.BotDebug; ds.BotDebug = dds.BotDebug;
ds.LuaDebug = dds.LuaDebug; ds.LuaDebug = dds.LuaDebug;
ds.SendSystemInformation = dds.SendSystemInformation; ds.SendSystemInformation = dds.SendSystemInformation;

View File

@@ -225,7 +225,7 @@ namespace OpenRA.Mods.Common.Widgets
public override string GetCursor(int2 screenPos) public override string GetCursor(int2 screenPos)
{ {
return Sync.CheckSyncUnchanged(World, () => return Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, World, () =>
{ {
// Always show an arrow while selecting // Always show an arrow while selecting
if (IsValidDragbox) if (IsValidDragbox)