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

@@ -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");
}
}