Fix bogus pause logic.

This commit is contained in:
Paul Chote
2013-04-07 21:52:49 +12:00
parent 3272b6725e
commit 096d95f391
13 changed files with 57 additions and 69 deletions

View File

@@ -174,20 +174,20 @@ namespace OpenRA
{ {
var isNetTick = LocalTick % NetTickScale == 0; var isNetTick = LocalTick % NetTickScale == 0;
if ((!isNetTick || orderManager.IsReadyForNextFrame) && !orderManager.GamePaused ) if (!isNetTick || orderManager.IsReadyForNextFrame)
{ {
++orderManager.LocalFrameNumber; ++orderManager.LocalFrameNumber;
Log.Write("debug", "--Tick: {0} ({1})", LocalTick, isNetTick ? "net" : "local"); Log.Write("debug", "--Tick: {0} ({1})", LocalTick, isNetTick ? "net" : "local");
if (isNetTick) orderManager.Tick(); if (isNetTick)
orderManager.Tick();
Sync.CheckSyncUnchanged(world, () => Sync.CheckSyncUnchanged(world, () =>
{ {
world.OrderGenerator.Tick(world); world.OrderGenerator.Tick(world);
world.Selection.Tick(world); world.Selection.Tick(world);
}); });
world.Tick(); world.Tick();

View File

@@ -200,17 +200,11 @@ namespace OpenRA
return new Order("HandshakeResponse", null, false) { IsImmediate = true, TargetString = text }; return new Order("HandshakeResponse", null, false) { IsImmediate = true, TargetString = text };
} }
public static Order PauseRequest() public static Order PauseGame(bool paused)
{ {
return new Order("PauseRequest", null, false) { IsImmediate = true, TargetString="" }; //TODO: targetbool? return new Order("PauseGame", null, false) { TargetString = paused ? "Pause" : "UnPause" };
}
public static Order PauseGame()
{
return new Order("PauseGame", null, false) { IsImmediate = true, TargetString=""}; //TODO: targetbool?
} }
public static Order Command(string text) public static Order Command(string text)
{ {
return new Order("Command", null, false) { IsImmediate = true, TargetString = text }; return new Order("Command", null, false) { IsImmediate = true, TargetString = text };

View File

@@ -36,7 +36,6 @@ namespace OpenRA.Network
public int LastTickTime = Environment.TickCount; public int LastTickTime = Environment.TickCount;
public bool GameStarted { get { return NetFrameNumber != 0; } } public bool GameStarted { get { return NetFrameNumber != 0; } }
public bool GamePaused {get; set;}
public IConnection Connection { get; private set; } public IConnection Connection { get; private set; }
public readonly int SyncHeaderSize = 9; public readonly int SyncHeaderSize = 9;

View File

@@ -95,16 +95,20 @@ namespace OpenRA.Network
Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map, false); Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map, false);
break; break;
} }
case "PauseGame": case "PauseGame":
{ {
var client = orderManager.LobbyInfo.ClientWithIndex(clientId); var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
if (client != null)
if(client != null)
{ {
orderManager.GamePaused = !orderManager.GamePaused; var pause = order.TargetString == "Pause";
var pausetext = "The game is {0} by {1}".F( orderManager.GamePaused ? "paused" : "un-paused", client.Name ); if (orderManager.world.Paused != pause && !world.LobbyInfo.IsSinglePlayer)
Game.AddChatLine(Color.White, "", pausetext); {
var pausetext = "The game is {0} by {1}".F(pause ? "paused" : "un-paused", client.Name);
Game.AddChatLine(Color.White, "", pausetext);
}
orderManager.world.Paused = pause;
} }
break; break;
} }

View File

@@ -488,11 +488,9 @@ namespace OpenRA.Server
DispatchOrdersToClient(c, fromIndex, 0, so.Serialize()); DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
break; break;
case "PauseRequest": case "PauseGame":
foreach (var c in conns.ToArray()) foreach (var c in conns.Except(conn).ToArray())
{ var x = Order.PauseGame(); DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
DispatchOrdersToClient(c, fromIndex, 0, x.Serialize());
}
break; break;
} }
} }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Widgets
var font = Game.Renderer.Fonts["Title"]; var font = Game.Renderer.Fonts["Title"];
var rb = RenderBounds; var rb = RenderBounds;
var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.GamePaused?" (paused)":""); var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.world.Paused?" (paused)":"");
var pos = new float2(rb.Left - font.Measure(s).X / 2, rb.Top); var pos = new float2(rb.Left - font.Measure(s).X / 2, rb.Top);
font.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1); font.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
} }

View File

@@ -175,13 +175,7 @@ namespace OpenRA.Widgets
return true; return true;
} }
else if (e.KeyName == Game.Settings.Keys.PauseKey) else if (e.KeyName == Game.Settings.Keys.PauseKey)
{ world.IssueOrder(Order.PauseGame(!world.Paused));
world.IssueOrder(Order.PauseRequest());
}
bool handled = false;
if (handled) return true;
} }
return false; return false;
} }

View File

@@ -158,37 +158,29 @@ namespace OpenRA
public event Action<Actor> ActorAdded = _ => { }; public event Action<Actor> ActorAdded = _ => { };
public event Action<Actor> ActorRemoved = _ => { }; public event Action<Actor> ActorRemoved = _ => { };
// Will do bad things in multiplayer games public bool Paused = false;
public bool EnableTick = true;
public bool IsShellmap = false; public bool IsShellmap = false;
bool ShouldTick()
{
if (!EnableTick) return false;
return !IsShellmap || Game.Settings.Game.ShowShellmap;
}
public void Tick() public void Tick()
{ {
// TODO: Expose this as an order so it can be synced if (!Paused && (!IsShellmap || Game.Settings.Game.ShowShellmap))
if (ShouldTick())
{ {
using( new PerfSample("tick_idle") ) using (new PerfSample("tick_idle"))
foreach( var ni in ActorsWithTrait<INotifyIdle>() ) foreach (var ni in ActorsWithTrait<INotifyIdle>())
if (ni.Actor.IsIdle) if (ni.Actor.IsIdle)
ni.Trait.TickIdle(ni.Actor); ni.Trait.TickIdle(ni.Actor);
using( new PerfSample("tick_activities") ) using (new PerfSample("tick_activities"))
foreach( var a in actors ) foreach(var a in actors)
a.Tick(); a.Tick();
ActorsWithTrait<ITick>().DoTimed( x => ActorsWithTrait<ITick>().DoTimed(x => x.Trait.Tick(x.Actor),
{ "[{2}] Trait: {0} ({1:0.000} ms)",
x.Trait.Tick( x.Actor ); Game.Settings.Debug.LongTickThreshold);
}, "[{2}] Trait: {0} ({1:0.000} ms)", Game.Settings.Debug.LongTickThreshold );
effects.DoTimed( e => e.Tick( this ), "[{2}] Effect: {0} ({1:0.000} ms)", effects.DoTimed(e => e.Tick(this),
Game.Settings.Debug.LongTickThreshold ); "[{2}] Effect: {0} ({1:0.000} ms)",
Game.Settings.Debug.LongTickThreshold);
} }
while (frameEndActions.Count != 0) while (frameEndActions.Count != 0)

View File

@@ -85,6 +85,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public void OptionsClicked() public void OptionsClicked()
{ {
var cachedPause = world.Paused;
if (menu != MenuType.None) if (menu != MenuType.None)
{ {
Ui.CloseWindow(); Ui.CloseWindow();
@@ -93,14 +95,15 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
ingameRoot.IsVisible = () => false; ingameRoot.IsVisible = () => false;
if (world.LobbyInfo.IsSinglePlayer) if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame()); world.IssueOrder(Order.PauseGame(true));
Game.LoadWidget(world, "INGAME_MENU", Ui.Root, new WidgetArgs() Game.LoadWidget(world, "INGAME_MENU", Ui.Root, new WidgetArgs()
{ {
{ "onExit", () => { "onExit", () =>
{ {
ingameRoot.IsVisible = () => true; ingameRoot.IsVisible = () => true;
if (world.LobbyInfo.IsSinglePlayer) if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame()); world.IssueOrder(Order.PauseGame(cachedPause));
} }
} }
}); });

View File

@@ -86,7 +86,6 @@ namespace OpenRA.Mods.RA
case "Chat": case "Chat":
case "TeamChat": case "TeamChat":
case "HandshakeResponse": case "HandshakeResponse":
case "PauseRequest":
case "PauseGame": case "PauseGame":
case "StartGame": case "StartGame":
case "Disconnected": case "Disconnected":
@@ -94,7 +93,8 @@ namespace OpenRA.Mods.RA
case "SyncInfo": case "SyncInfo":
return; return;
} }
if (order.OrderString.StartsWith("Dev")) return; if (order.OrderString.StartsWith("Dev"))
return;
OrderCount++; OrderCount++;
} }
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Scripting
return; return;
} }
w.EnableTick = false; w.Paused = true;
// Mute world sounds // Mute world sounds
var oldModifier = Sound.SoundVolumeModifier; var oldModifier = Sound.SoundVolumeModifier;
@@ -51,7 +51,7 @@ namespace OpenRA.Scripting
Ui.CloseWindow(); Ui.CloseWindow();
Sound.SoundVolumeModifier = oldModifier; Sound.SoundVolumeModifier = oldModifier;
w.EnableTick = true; w.Paused = false;
onComplete(); onComplete();
}); });
} }

View File

@@ -8,10 +8,11 @@
*/ */
#endregion #endregion
using OpenRA.Traits;
using System.Linq;
using OpenRA.Widgets;
using System.Drawing; using System.Drawing;
using System.Linq;
using OpenRA.Network;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic
{ {
@@ -26,11 +27,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
gameRoot = r.Get("INGAME_ROOT"); gameRoot = r.Get("INGAME_ROOT");
var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG"); var optionsBG = gameRoot.Get("INGAME_OPTIONS_BG");
// TODO: RA's broken UI wiring makes it unreasonably difficult to
// cache and restore the previous pause state, so opening/closing
// the menu in a paused singleplayer game will un-pause the game.
r.Get<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnClick = () => r.Get<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnClick = () =>
{ {
optionsBG.Visible = !optionsBG.Visible; optionsBG.Visible = !optionsBG.Visible;
if (world.LobbyInfo.IsSinglePlayer) if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame()); world.IssueOrder(Order.PauseGame(true));
}; };
var cheatsButton = gameRoot.Get<ButtonWidget>("CHEATS_BUTTON"); var cheatsButton = gameRoot.Get<ButtonWidget>("CHEATS_BUTTON");
@@ -65,7 +69,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
optionsBG.Visible = false; optionsBG.Visible = false;
if (world.LobbyInfo.IsSinglePlayer) if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame()); world.IssueOrder(Order.PauseGame(false));
}; };
optionsBG.Get<ButtonWidget>("SURRENDER").OnClick = () => optionsBG.Get<ButtonWidget>("SURRENDER").OnClick = () =>

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
optionsBG.Visible = !optionsBG.Visible; optionsBG.Visible = !optionsBG.Visible;
if (world.LobbyInfo.IsSinglePlayer) if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame()); world.IssueOrder(Order.PauseGame(true));
}; };
optionsBG.Get<ButtonWidget>("DISCONNECT").OnClick = () => optionsBG.Get<ButtonWidget>("DISCONNECT").OnClick = () =>
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
optionsBG.Visible = false; optionsBG.Visible = false;
if (world.LobbyInfo.IsSinglePlayer) if (world.LobbyInfo.IsSinglePlayer)
world.IssueOrder(Order.PauseGame()); world.IssueOrder(Order.PauseGame(false));
}; };
optionsBG.Get<ButtonWidget>("SURRENDER").IsVisible = () => false; optionsBG.Get<ButtonWidget>("SURRENDER").IsVisible = () => false;