add Sync.AssertUnsynced. use it in OrderGenerator.set
This commit is contained in:
@@ -45,17 +45,17 @@ namespace OpenRA.Orders
|
|||||||
foreach (var a in world.Selection.Actors)
|
foreach (var a in world.Selection.Actors)
|
||||||
if (!a.Destroyed)
|
if (!a.Destroyed)
|
||||||
foreach (var t in a.TraitsImplementing<IPreRenderSelection>())
|
foreach (var t in a.TraitsImplementing<IPreRenderSelection>())
|
||||||
t.RenderBeforeWorld(a);
|
t.RenderBeforeWorld(a);
|
||||||
|
|
||||||
Game.Renderer.Flush();
|
Game.Renderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderAfterWorld( World world )
|
public void RenderAfterWorld( World world )
|
||||||
{
|
{
|
||||||
foreach (var a in world.Selection.Actors)
|
foreach (var a in world.Selection.Actors)
|
||||||
if (!a.Destroyed)
|
if (!a.Destroyed)
|
||||||
foreach (var t in a.TraitsImplementing<IPostRenderSelection>())
|
foreach (var t in a.TraitsImplementing<IPostRenderSelection>())
|
||||||
t.RenderAfterWorld(a);
|
t.RenderAfterWorld(a);
|
||||||
|
|
||||||
Game.Renderer.Flush();
|
Game.Renderer.Flush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,19 +132,31 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static void CheckSyncUnchanged( World world, Action fn )
|
public static void CheckSyncUnchanged( World world, Action fn )
|
||||||
{
|
{
|
||||||
int sync = world.SyncHash();
|
CheckSyncUnchanged( world, () => { fn(); return true; } );
|
||||||
fn();
|
|
||||||
if( sync != world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool inUnsyncedCode = false;
|
||||||
|
|
||||||
public static T CheckSyncUnchanged<T>( World world, Func<T> fn )
|
public static T CheckSyncUnchanged<T>( World world, Func<T> fn )
|
||||||
{
|
{
|
||||||
int sync = world.SyncHash();
|
int sync = world.SyncHash();
|
||||||
var ret = fn();
|
inUnsyncedCode = true;
|
||||||
if( sync != world.SyncHash() )
|
try
|
||||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
{
|
||||||
return ret;
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,18 @@ namespace OpenRA
|
|||||||
public readonly TileSet TileSet;
|
public readonly TileSet TileSet;
|
||||||
|
|
||||||
public readonly WorldRenderer WorldRenderer;
|
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 Selection Selection = new Selection();
|
||||||
|
|
||||||
public void CancelInputMode() { OrderGenerator = new UnitOrderGenerator(); }
|
public void CancelInputMode() { OrderGenerator = new UnitOrderGenerator(); }
|
||||||
@@ -76,6 +86,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public World(Manifest manifest, Map map)
|
public World(Manifest manifest, Map map)
|
||||||
{
|
{
|
||||||
|
orderGenerator_ = new UnitOrderGenerator();
|
||||||
Map = map;
|
Map = map;
|
||||||
|
|
||||||
TileSet = Rules.TileSets[Map.Tileset];
|
TileSet = Rules.TileSets[Map.Tileset];
|
||||||
|
|||||||
Reference in New Issue
Block a user