Fix IDE0032
This commit is contained in:
committed by
Pavel Penev
parent
e64c0a35c5
commit
98c4eaca83
@@ -107,12 +107,9 @@ namespace OpenRA.Network
|
||||
readonly Queue<OrderPacket> sentImmediateOrders = new Queue<OrderPacket>();
|
||||
readonly ConcurrentQueue<(int FromClient, byte[] Data)> receivedPackets = new ConcurrentQueue<(int, byte[])>();
|
||||
TcpClient tcp;
|
||||
IPEndPoint endpoint;
|
||||
|
||||
volatile ConnectionState connectionState = ConnectionState.Connecting;
|
||||
volatile int clientId;
|
||||
bool disposed;
|
||||
string errorMessage;
|
||||
|
||||
public NetworkConnection(ConnectionTarget target)
|
||||
{
|
||||
@@ -124,6 +121,12 @@ namespace OpenRA.Network
|
||||
}.Start();
|
||||
}
|
||||
|
||||
public ConnectionState ConnectionState => connectionState;
|
||||
|
||||
public IPEndPoint EndPoint { get; private set; }
|
||||
|
||||
public string ErrorMessage { get; private set; }
|
||||
|
||||
void NetworkConnectionConnect()
|
||||
{
|
||||
var queue = new BlockingCollection<TcpClient>();
|
||||
@@ -151,7 +154,7 @@ namespace OpenRA.Network
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = "Failed to connect";
|
||||
ErrorMessage = "Failed to connect";
|
||||
Log.Write("client", $"Failed to connect to {endpoint}: {ex.Message}");
|
||||
}
|
||||
})
|
||||
@@ -163,7 +166,7 @@ namespace OpenRA.Network
|
||||
|
||||
if (!atLeastOneEndpoint)
|
||||
{
|
||||
errorMessage = "Failed to resolve address";
|
||||
ErrorMessage = "Failed to resolve address";
|
||||
connectionState = ConnectionState.NotConnected;
|
||||
}
|
||||
|
||||
@@ -171,7 +174,7 @@ namespace OpenRA.Network
|
||||
else if (queue.TryTake(out tcp, 5000))
|
||||
{
|
||||
// Copy endpoint here to have it even after getting disconnected.
|
||||
endpoint = (IPEndPoint)tcp.Client.RemoteEndPoint;
|
||||
EndPoint = (IPEndPoint)tcp.Client.RemoteEndPoint;
|
||||
|
||||
new Thread(NetworkConnectionReceive)
|
||||
{
|
||||
@@ -215,8 +218,8 @@ namespace OpenRA.Network
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = "Connection failed";
|
||||
Log.Write("client", $"Connection to {endpoint} failed: {ex.Message}");
|
||||
ErrorMessage = "Connection failed";
|
||||
Log.Write("client", $"Connection to {EndPoint} failed: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -367,12 +370,6 @@ namespace OpenRA.Network
|
||||
Recorder = new ReplayRecorder(chooseFilename);
|
||||
}
|
||||
|
||||
public ConnectionState ConnectionState => connectionState;
|
||||
|
||||
public IPEndPoint EndPoint => endpoint;
|
||||
|
||||
public string ErrorMessage => errorMessage;
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
if (disposed)
|
||||
|
||||
@@ -329,6 +329,8 @@ namespace OpenRA
|
||||
|
||||
case OrderType.Fields:
|
||||
{
|
||||
var targetState = Target.SerializableState;
|
||||
|
||||
var fields = OrderFields.None;
|
||||
if (Subject != null)
|
||||
fields |= OrderFields.Subject;
|
||||
@@ -339,7 +341,7 @@ namespace OpenRA
|
||||
if (ExtraData != 0)
|
||||
fields |= OrderFields.ExtraData;
|
||||
|
||||
if (Target.SerializableType != TargetType.Invalid)
|
||||
if (targetState.Type != TargetType.Invalid)
|
||||
fields |= OrderFields.Target;
|
||||
|
||||
if (Queued)
|
||||
@@ -354,7 +356,7 @@ namespace OpenRA
|
||||
if (ExtraLocation != CPos.Zero)
|
||||
fields |= OrderFields.ExtraLocation;
|
||||
|
||||
if (Target.SerializableCell != null)
|
||||
if (targetState.Cell != null)
|
||||
fields |= OrderFields.TargetIsCell;
|
||||
|
||||
w.Write((short)fields);
|
||||
@@ -364,12 +366,12 @@ namespace OpenRA
|
||||
|
||||
if (fields.HasField(OrderFields.Target))
|
||||
{
|
||||
w.Write((byte)Target.SerializableType);
|
||||
switch (Target.SerializableType)
|
||||
w.Write((byte)targetState.Type);
|
||||
switch (targetState.Type)
|
||||
{
|
||||
case TargetType.Actor:
|
||||
w.Write(UIntFromActor(Target.SerializableActor));
|
||||
w.Write(Target.SerializableGeneration);
|
||||
w.Write(UIntFromActor(targetState.Actor));
|
||||
w.Write(targetState.Generation);
|
||||
break;
|
||||
case TargetType.FrozenActor:
|
||||
w.Write(Target.FrozenActor.Viewer.PlayerActor.ActorID);
|
||||
@@ -378,14 +380,14 @@ namespace OpenRA
|
||||
case TargetType.Terrain:
|
||||
if (fields.HasField(OrderFields.TargetIsCell))
|
||||
{
|
||||
w.Write(Target.SerializableCell.Value.Bits);
|
||||
w.Write((byte)Target.SerializableSubCell);
|
||||
w.Write(targetState.Cell.Value.Bits);
|
||||
w.Write((byte)targetState.SubCell);
|
||||
}
|
||||
else
|
||||
{
|
||||
w.Write(Target.SerializablePos.X);
|
||||
w.Write(Target.SerializablePos.Y);
|
||||
w.Write(Target.SerializablePos.Z);
|
||||
w.Write(targetState.Pos.X);
|
||||
w.Write(targetState.Pos.Y);
|
||||
w.Write(targetState.Pos.Z);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -17,19 +17,13 @@ namespace OpenRA.Network
|
||||
{
|
||||
readonly Func<int> timestep;
|
||||
|
||||
long lastTickTime;
|
||||
|
||||
public TickTime(Func<int> timestep, long lastTickTime)
|
||||
{
|
||||
this.timestep = timestep;
|
||||
this.lastTickTime = lastTickTime;
|
||||
Value = lastTickTime;
|
||||
}
|
||||
|
||||
public long Value
|
||||
{
|
||||
get => lastTickTime;
|
||||
set => lastTickTime = value;
|
||||
}
|
||||
public long Value { get; set; }
|
||||
|
||||
public bool ShouldAdvance(long tick)
|
||||
{
|
||||
@@ -38,18 +32,18 @@ namespace OpenRA.Network
|
||||
if (i == 0)
|
||||
return false;
|
||||
|
||||
var tickDelta = tick - lastTickTime;
|
||||
var tickDelta = tick - Value;
|
||||
return tickDelta >= i;
|
||||
}
|
||||
|
||||
public void AdvanceTickTime(long tick)
|
||||
{
|
||||
var tickDelta = tick - lastTickTime;
|
||||
var tickDelta = tick - Value;
|
||||
|
||||
var currentTimestep = timestep();
|
||||
|
||||
var integralTickTimestep = tickDelta / currentTimestep * currentTimestep;
|
||||
lastTickTime += integralTickTimestep >= Game.TimestepJankThreshold
|
||||
Value += integralTickTimestep >= Game.TimestepJankThreshold
|
||||
? integralTickTimestep
|
||||
: currentTimestep;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user