add Sync.AssertUnsynced. use it in OrderGenerator.set

This commit is contained in:
Bob
2010-10-02 10:30:56 +12:00
committed by Paul Chote
parent 26d1db778e
commit d6110b9ef0
3 changed files with 37 additions and 14 deletions

View File

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

View File

@@ -55,7 +55,17 @@ namespace OpenRA
public readonly WorldRenderer WorldRenderer;
public IOrderGenerator OrderGenerator = new UnitOrderGenerator();
IOrderGenerator orderGenerator_;
public IOrderGenerator OrderGenerator
{
get { return orderGenerator_; }
set
{
Sync.AssertUnsynced( "The current order generator may not be changed from synced code" );
orderGenerator_ = value;
}
}
public Selection Selection = new Selection();
public void CancelInputMode() { OrderGenerator = new UnitOrderGenerator(); }
@@ -76,6 +86,7 @@ namespace OpenRA
public World(Manifest manifest, Map map)
{
orderGenerator_ = new UnitOrderGenerator();
Map = map;
TileSet = Rules.TileSets[Map.Tileset];