diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index d088a8a75b..0e72be2991 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -45,17 +45,17 @@ namespace OpenRA.Orders foreach (var a in world.Selection.Actors) if (!a.Destroyed) foreach (var t in a.TraitsImplementing()) - t.RenderBeforeWorld(a); - + t.RenderBeforeWorld(a); + Game.Renderer.Flush(); } public void RenderAfterWorld( World world ) { - foreach (var a in world.Selection.Actors) + foreach (var a in world.Selection.Actors) if (!a.Destroyed) foreach (var t in a.TraitsImplementing()) - t.RenderAfterWorld(a); + t.RenderAfterWorld(a); Game.Renderer.Flush(); } diff --git a/OpenRA.Game/Sync.cs b/OpenRA.Game/Sync.cs index 6ed32a3498..efe072cefd 100755 --- a/OpenRA.Game/Sync.cs +++ b/OpenRA.Game/Sync.cs @@ -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( World world, Func 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 ); } } } diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 90496cffcc..7a57be92df 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -54,8 +54,18 @@ namespace OpenRA public readonly TileSet TileSet; 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];