Merge pull request #2991 from pchote/sane-pause-logic
Fix pause logic and C&C cheats menu
This commit is contained in:
@@ -174,20 +174,20 @@ namespace OpenRA
|
||||
{
|
||||
var isNetTick = LocalTick % NetTickScale == 0;
|
||||
|
||||
if ((!isNetTick || orderManager.IsReadyForNextFrame) && !orderManager.GamePaused )
|
||||
if (!isNetTick || orderManager.IsReadyForNextFrame)
|
||||
{
|
||||
++orderManager.LocalFrameNumber;
|
||||
|
||||
Log.Write("debug", "--Tick: {0} ({1})", LocalTick, isNetTick ? "net" : "local");
|
||||
|
||||
if (isNetTick) orderManager.Tick();
|
||||
|
||||
if (isNetTick)
|
||||
orderManager.Tick();
|
||||
|
||||
Sync.CheckSyncUnchanged(world, () =>
|
||||
{
|
||||
world.OrderGenerator.Tick(world);
|
||||
world.Selection.Tick(world);
|
||||
});
|
||||
{
|
||||
world.OrderGenerator.Tick(world);
|
||||
world.Selection.Tick(world);
|
||||
});
|
||||
|
||||
world.Tick();
|
||||
|
||||
|
||||
@@ -200,17 +200,11 @@ namespace OpenRA
|
||||
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?
|
||||
}
|
||||
|
||||
public static Order PauseGame()
|
||||
{
|
||||
return new Order("PauseGame", null, false) { IsImmediate = true, TargetString=""}; //TODO: targetbool?
|
||||
return new Order("PauseGame", null, false) { TargetString = paused ? "Pause" : "UnPause" };
|
||||
}
|
||||
|
||||
|
||||
public static Order Command(string text)
|
||||
{
|
||||
return new Order("Command", null, false) { IsImmediate = true, TargetString = text };
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace OpenRA.Network
|
||||
public int LastTickTime = Environment.TickCount;
|
||||
|
||||
public bool GameStarted { get { return NetFrameNumber != 0; } }
|
||||
public bool GamePaused {get; set;}
|
||||
public IConnection Connection { get; private set; }
|
||||
|
||||
public readonly int SyncHeaderSize = 9;
|
||||
|
||||
@@ -95,16 +95,20 @@ namespace OpenRA.Network
|
||||
Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map, false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case "PauseGame":
|
||||
{
|
||||
{
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
||||
|
||||
if(client != null)
|
||||
if (client != null)
|
||||
{
|
||||
orderManager.GamePaused = !orderManager.GamePaused;
|
||||
var pausetext = "The game is {0} by {1}".F( orderManager.GamePaused ? "paused" : "un-paused", client.Name );
|
||||
Game.AddChatLine(Color.White, "", pausetext);
|
||||
var pause = order.TargetString == "Pause";
|
||||
if (orderManager.world.Paused != pause && !world.LobbyInfo.IsSinglePlayer)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -222,6 +222,7 @@
|
||||
<Compile Include="WorldUtils.cs" />
|
||||
<Compile Include="Network\ReplayRecorderConnection.cs" />
|
||||
<Compile Include="Widgets\TooltipContainerWidget.cs" />
|
||||
<Compile Include="Traits\DebugPauseState.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -488,11 +488,9 @@ namespace OpenRA.Server
|
||||
DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
|
||||
break;
|
||||
|
||||
case "PauseRequest":
|
||||
foreach (var c in conns.ToArray())
|
||||
{ var x = Order.PauseGame();
|
||||
DispatchOrdersToClient(c, fromIndex, 0, x.Serialize());
|
||||
}
|
||||
case "PauseGame":
|
||||
foreach (var c in conns.Except(conn).ToArray())
|
||||
DispatchOrdersToClient(c, fromIndex, 0, so.Serialize());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
27
OpenRA.Game/Traits/DebugPauseState.cs
Normal file
27
OpenRA.Game/Traits/DebugPauseState.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class DebugPauseStateInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new DebugPauseState(init.world); }
|
||||
}
|
||||
|
||||
public class DebugPauseState : ISync
|
||||
{
|
||||
World world;
|
||||
[Sync] public bool Paused { get { return world.Paused; } }
|
||||
public DebugPauseState(World world) { this.world = world; }
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace OpenRA.Widgets
|
||||
var font = Game.Renderer.Fonts["Title"];
|
||||
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);
|
||||
font.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
|
||||
}
|
||||
|
||||
@@ -175,13 +175,7 @@ namespace OpenRA.Widgets
|
||||
return true;
|
||||
}
|
||||
else if (e.KeyName == Game.Settings.Keys.PauseKey)
|
||||
{
|
||||
world.IssueOrder(Order.PauseRequest());
|
||||
}
|
||||
|
||||
bool handled = false;
|
||||
|
||||
if (handled) return true;
|
||||
world.IssueOrder(Order.PauseGame(!world.Paused));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,37 +158,29 @@ namespace OpenRA
|
||||
public event Action<Actor> ActorAdded = _ => { };
|
||||
public event Action<Actor> ActorRemoved = _ => { };
|
||||
|
||||
// Will do bad things in multiplayer games
|
||||
public bool EnableTick = true;
|
||||
public bool Paused = false;
|
||||
public bool IsShellmap = false;
|
||||
|
||||
bool ShouldTick()
|
||||
{
|
||||
if (!EnableTick) return false;
|
||||
return !IsShellmap || Game.Settings.Game.ShowShellmap;
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
// TODO: Expose this as an order so it can be synced
|
||||
if (ShouldTick())
|
||||
if (!Paused && (!IsShellmap || Game.Settings.Game.ShowShellmap))
|
||||
{
|
||||
using( new PerfSample("tick_idle") )
|
||||
foreach( var ni in ActorsWithTrait<INotifyIdle>() )
|
||||
using (new PerfSample("tick_idle"))
|
||||
foreach (var ni in ActorsWithTrait<INotifyIdle>())
|
||||
if (ni.Actor.IsIdle)
|
||||
ni.Trait.TickIdle(ni.Actor);
|
||||
|
||||
using( new PerfSample("tick_activities") )
|
||||
foreach( var a in actors )
|
||||
using (new PerfSample("tick_activities"))
|
||||
foreach(var a in actors)
|
||||
a.Tick();
|
||||
|
||||
ActorsWithTrait<ITick>().DoTimed( x =>
|
||||
{
|
||||
x.Trait.Tick( x.Actor );
|
||||
}, "[{2}] Trait: {0} ({1:0.000} ms)", Game.Settings.Debug.LongTickThreshold );
|
||||
ActorsWithTrait<ITick>().DoTimed(x => x.Trait.Tick(x.Actor),
|
||||
"[{2}] Trait: {0} ({1:0.000} ms)",
|
||||
Game.Settings.Debug.LongTickThreshold);
|
||||
|
||||
effects.DoTimed( e => e.Tick( this ), "[{2}] Effect: {0} ({1:0.000} ms)",
|
||||
Game.Settings.Debug.LongTickThreshold );
|
||||
effects.DoTimed(e => e.Tick(this),
|
||||
"[{2}] Effect: {0} ({1:0.000} ms)",
|
||||
Game.Settings.Debug.LongTickThreshold);
|
||||
}
|
||||
|
||||
while (frameEndActions.Count != 0)
|
||||
|
||||
Reference in New Issue
Block a user