Rework and rename Sync.CheckSyncUnchanged
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T>(World world, Func<T> fn)
|
||||
public static T RunUnsynced<T>(bool checkSyncHash, World world, Func<T> 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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user