Change Game.RunTime to a long to prevent overflow.

This commit is contained in:
RoosterDragon
2016-09-20 19:06:10 +01:00
parent 57ceda3025
commit 2ffea5db54
12 changed files with 25 additions and 20 deletions

View File

@@ -489,6 +489,11 @@ namespace OpenRA
return int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i); return int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i);
} }
public static bool TryParseInt64Invariant(string s, out long i)
{
return long.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i);
}
public static bool IsTraitEnabled(this object trait) public static bool IsTraitEnabled(this object trait)
{ {
return trait as IDisabledTrait == null || !(trait as IDisabledTrait).IsTraitDisabled; return trait as IDisabledTrait == null || !(trait as IDisabledTrait).IsTraitDisabled;

View File

@@ -96,7 +96,7 @@ namespace OpenRA
// More accurate replacement for Environment.TickCount // More accurate replacement for Environment.TickCount
static Stopwatch stopwatch = Stopwatch.StartNew(); static Stopwatch stopwatch = Stopwatch.StartNew();
public static int RunTime { get { return (int)stopwatch.ElapsedMilliseconds; } } public static long RunTime { get { return stopwatch.ElapsedMilliseconds; } }
public static int RenderFrame = 0; public static int RenderFrame = 0;
public static int NetFrameNumber { get { return OrderManager.NetFrameNumber; } } public static int NetFrameNumber { get { return OrderManager.NetFrameNumber; } }
@@ -735,7 +735,7 @@ namespace OpenRA
} }
} }
else else
Thread.Sleep(nextUpdate - now); Thread.Sleep((int)(nextUpdate - now));
} }
} }

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Graphics
} }
} }
public static int TicksSinceLastMove = 0; public static long TicksSinceLastMove = 0;
public static int2 LastMousePos; public static int2 LastMousePos;
float ClosestTo(float[] collection, float target) float ClosestTo(float[] collection, float target)

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Network
public int LocalFrameNumber; public int LocalFrameNumber;
public int FramesAhead = 0; public int FramesAhead = 0;
public int LastTickTime = Game.RunTime; public long LastTickTime = Game.RunTime;
public bool GameStarted { get { return NetFrameNumber != 0; } } public bool GameStarted { get { return NetFrameNumber != 0; } }
public IConnection Connection { get; private set; } public IConnection Connection { get; private set; }

View File

@@ -135,9 +135,9 @@ namespace OpenRA.Network
public class ClientPing public class ClientPing
{ {
public int Index; public int Index;
public int Latency = -1; public long Latency = -1;
public int LatencyJitter = -1; public long LatencyJitter = -1;
public int[] LatencyHistory = { }; public long[] LatencyHistory = { };
public static ClientPing Deserialize(MiniYaml data) public static ClientPing Deserialize(MiniYaml data)
{ {

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Primitives
{ {
readonly List<DelayedAction> actions = new List<DelayedAction>(); readonly List<DelayedAction> actions = new List<DelayedAction>();
public void Add(Action a, int desiredTime) public void Add(Action a, long desiredTime)
{ {
if (a == null) if (a == null)
throw new ArgumentNullException("a"); throw new ArgumentNullException("a");
@@ -34,7 +34,7 @@ namespace OpenRA.Primitives
} }
} }
public void PerformActions(int currentTime) public void PerformActions(long currentTime)
{ {
DelayedAction[] pendingActions; DelayedAction[] pendingActions;
lock (actions) lock (actions)
@@ -67,10 +67,10 @@ namespace OpenRA.Primitives
struct DelayedAction : IComparable<DelayedAction> struct DelayedAction : IComparable<DelayedAction>
{ {
public readonly int Time; public readonly long Time;
public readonly Action Action; public readonly Action Action;
public DelayedAction(Action action, int time) public DelayedAction(Action action, long time)
{ {
Action = action; Action = action;
Time = time; Time = time;

View File

@@ -26,9 +26,9 @@ namespace OpenRA.Server
public int Frame = 0; public int Frame = 0;
public int MostRecentFrame = 0; public int MostRecentFrame = 0;
public int TimeSinceLastResponse { get { return Game.RunTime - lastReceivedTime; } } public long TimeSinceLastResponse { get { return Game.RunTime - lastReceivedTime; } }
public bool TimeoutMessageShown = false; public bool TimeoutMessageShown = false;
int lastReceivedTime = 0; long lastReceivedTime = 0;
/* client data */ /* client data */
public int PlayerIndex; public int PlayerIndex;

View File

@@ -501,8 +501,8 @@ namespace OpenRA.Server
break; break;
case "Pong": case "Pong":
{ {
int pingSent; long pingSent;
if (!OpenRA.Exts.TryParseIntegerInvariant(so.Data, out pingSent)) if (!OpenRA.Exts.TryParseInt64Invariant(so.Data, out pingSent))
{ {
Log.Write("server", "Invalid order pong payload: {0}", so.Data); Log.Write("server", "Invalid order pong payload: {0}", so.Data);
break; break;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Widgets
{ {
public static Widget Root = new RootWidget(); public static Widget Root = new RootWidget();
public static int LastTickTime = Game.RunTime; public static long LastTickTime = Game.RunTime;
static readonly Stack<Widget> WindowList = new Stack<Widget>(); static readonly Stack<Widget> WindowList = new Stack<Widget>();

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Server
public void GameStarted(S server) { PingMasterServer(server); } public void GameStarted(S server) { PingMasterServer(server); }
public void GameEnded(S server) { PingMasterServer(server); } public void GameEnded(S server) { PingMasterServer(server); }
int lastPing = 0; long lastPing = 0;
bool isInitialPing = true; bool isInitialPing = true;
volatile bool isBusy; volatile bool isBusy;

View File

@@ -24,8 +24,8 @@ namespace OpenRA.Mods.Common.Server
// TickTimeout is in microseconds // TickTimeout is in microseconds
public int TickTimeout { get { return PingInterval * 100; } } public int TickTimeout { get { return PingInterval * 100; } }
int lastPing = 0; long lastPing = 0;
int lastConnReport = 0; long lastConnReport = 0;
bool isInitialPing = true; bool isInitialPing = true;
public void Tick(S server) public void Tick(S server)

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Widgets
tooltipContainer.Value.RemoveTooltip(); tooltipContainer.Value.RemoveTooltip();
} }
int lastScrollTime = 0; long lastScrollTime = 0;
public override void Draw() public override void Draw()
{ {
if (IsJoystickScrolling) if (IsJoystickScrolling)