committed by
Oliver Brakmann
parent
150439d215
commit
3a9b35980c
@@ -38,8 +38,6 @@ namespace OpenRA.Network
|
|||||||
public int NetFrameNumber { get; private set; }
|
public int NetFrameNumber { get; private set; }
|
||||||
public int LocalFrameNumber;
|
public int LocalFrameNumber;
|
||||||
public int FramesAhead = 0;
|
public int FramesAhead = 0;
|
||||||
public bool IsReadyForNextFrame { get; private set; }
|
|
||||||
int lastFrameSent;
|
|
||||||
|
|
||||||
public long LastTickTime = Game.RunTime;
|
public long LastTickTime = Game.RunTime;
|
||||||
|
|
||||||
@@ -76,9 +74,9 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
NetFrameNumber = 1;
|
NetFrameNumber = 1;
|
||||||
|
|
||||||
// Technically redundant since we will attempt to send orders before the next frame
|
if (GameSaveLastFrame < 0)
|
||||||
SendOrders();
|
for (var i = NetFrameNumber; i <= FramesAhead; i++)
|
||||||
IsReadyForNextFrame = false;
|
Connection.Send(i, new List<byte[]>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderManager(ConnectionTarget endpoint, string password, IConnection conn)
|
public OrderManager(ConnectionTarget endpoint, string password, IConnection conn)
|
||||||
@@ -111,17 +109,8 @@ namespace OpenRA.Network
|
|||||||
chatCache.Add(new ChatLine(name, nameColor, text, textColor));
|
chatCache.Add(new ChatLine(name, nameColor, text, textColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Send all frame orders that are ready if we can (game is started and our next available send frame is free),
|
|
||||||
* Send all immediate orders,
|
|
||||||
* Receive and dispatch immediate orders, check incoming sync matchs, and buffer received frame orders,
|
|
||||||
* Update our ready status for the next frame for Tick().
|
|
||||||
*/
|
|
||||||
public void TickImmediate()
|
public void TickImmediate()
|
||||||
{
|
{
|
||||||
// Send our frame orders if we should
|
|
||||||
SendOrders();
|
|
||||||
|
|
||||||
if (localImmediateOrders.Count != 0 && GameSaveLastFrame < NetFrameNumber + FramesAhead)
|
if (localImmediateOrders.Count != 0 && GameSaveLastFrame < NetFrameNumber + FramesAhead)
|
||||||
Connection.SendImmediate(localImmediateOrders.Select(o => o.Serialize()));
|
Connection.SendImmediate(localImmediateOrders.Select(o => o.Serialize()));
|
||||||
localImmediateOrders.Clear();
|
localImmediateOrders.Clear();
|
||||||
@@ -153,9 +142,6 @@ namespace OpenRA.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsReadyForNextFrame)
|
|
||||||
IsReadyForNextFrame = NetFrameNumber >= 1 && frameData.IsReadyForFrame(NetFrameNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
|
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
|
||||||
@@ -177,6 +163,11 @@ namespace OpenRA.Network
|
|||||||
syncForFrame.Add(frame, packet);
|
syncForFrame.Add(frame, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsReadyForNextFrame
|
||||||
|
{
|
||||||
|
get { return NetFrameNumber >= 1 && frameData.IsReadyForFrame(NetFrameNumber); }
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<Session.Client> GetClientsNotReadyForNextFrame
|
public IEnumerable<Session.Client> GetClientsNotReadyForNextFrame
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -188,31 +179,16 @@ namespace OpenRA.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendOrders()
|
|
||||||
{
|
|
||||||
if (NetFrameNumber < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Loop exists to ensure we never miss a frame, since that would stall the game.
|
|
||||||
// This loop also sends the initial blank frames to get to the correct order latency.
|
|
||||||
while (lastFrameSent < NetFrameNumber + FramesAhead)
|
|
||||||
{
|
|
||||||
lastFrameSent++;
|
|
||||||
if (GameSaveLastFrame < NetFrameNumber + FramesAhead)
|
|
||||||
Connection.Send(lastFrameSent, localOrders.Select(o => o.Serialize()).ToList());
|
|
||||||
localOrders.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Only available if TickImmediate() is called first and we are ready to dispatch received orders locally.
|
|
||||||
* Process all incoming orders for this frame, handle sync hashes and step our net frame.
|
|
||||||
*/
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
if (!IsReadyForNextFrame)
|
if (!IsReadyForNextFrame)
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
|
|
||||||
|
if (GameSaveLastFrame < NetFrameNumber + FramesAhead)
|
||||||
|
Connection.Send(NetFrameNumber + FramesAhead, localOrders.Select(o => o.Serialize()).ToList());
|
||||||
|
|
||||||
|
localOrders.Clear();
|
||||||
|
|
||||||
foreach (var order in frameData.OrdersForFrame(World, NetFrameNumber))
|
foreach (var order in frameData.OrdersForFrame(World, NetFrameNumber))
|
||||||
UnitOrders.ProcessOrder(this, World, order.Client, order.Order);
|
UnitOrders.ProcessOrder(this, World, order.Client, order.Order);
|
||||||
|
|
||||||
@@ -226,7 +202,6 @@ namespace OpenRA.Network
|
|||||||
syncReport.UpdateSyncReport();
|
syncReport.UpdateSyncReport();
|
||||||
|
|
||||||
++NetFrameNumber;
|
++NetFrameNumber;
|
||||||
IsReadyForNextFrame = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -1005,7 +1005,7 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
// HACK: Turn down the latency if there is only one real player
|
// HACK: Turn down the latency if there is only one real player
|
||||||
if (LobbyInfo.NonBotClients.Count() == 1)
|
if (LobbyInfo.NonBotClients.Count() == 1)
|
||||||
LobbyInfo.GlobalSettings.OrderLatency = 0;
|
LobbyInfo.GlobalSettings.OrderLatency = 1;
|
||||||
|
|
||||||
// Enable game saves for singleplayer missions only
|
// Enable game saves for singleplayer missions only
|
||||||
// TODO: Enable for multiplayer (non-dedicated servers only) once the lobby UI has been created
|
// TODO: Enable for multiplayer (non-dedicated servers only) once the lobby UI has been created
|
||||||
|
|||||||
Reference in New Issue
Block a user