add Sync.AssertUnsynced. use it in OrderGenerator.set
This commit is contained in:
@@ -132,19 +132,31 @@ namespace OpenRA
|
||||
|
||||
public static void CheckSyncUnchanged( World world, Action fn )
|
||||
{
|
||||
int sync = world.SyncHash();
|
||||
fn();
|
||||
if( sync != world.SyncHash() )
|
||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
||||
CheckSyncUnchanged( world, () => { fn(); return true; } );
|
||||
}
|
||||
|
||||
static bool inUnsyncedCode = false;
|
||||
|
||||
public static T CheckSyncUnchanged<T>( World world, Func<T> fn )
|
||||
{
|
||||
int sync = world.SyncHash();
|
||||
var ret = fn();
|
||||
if( sync != world.SyncHash() )
|
||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
||||
return ret;
|
||||
inUnsyncedCode = true;
|
||||
try
|
||||
{
|
||||
return fn();
|
||||
}
|
||||
finally
|
||||
{
|
||||
inUnsyncedCode = false;
|
||||
if( sync != world.SyncHash() )
|
||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
||||
}
|
||||
}
|
||||
|
||||
public static void AssertUnsynced( string message )
|
||||
{
|
||||
if( !inUnsyncedCode )
|
||||
throw new InvalidOperationException( message );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user