Merge pull request #9022 from RoosterDragon/less-sync
Sync only once per tick
This commit is contained in:
@@ -19,6 +19,11 @@ namespace OpenRA.Network
|
||||
{
|
||||
public int Client;
|
||||
public Order Order;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ClientId: {0} {1}".F(Client, Order);
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<int, int> clientQuitTimes = new Dictionary<int, int>();
|
||||
|
||||
@@ -35,14 +35,13 @@ namespace OpenRA.Network
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static byte[] SerializeSync(this List<int> sync)
|
||||
public static byte[] SerializeSync(int sync)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using (var writer = new BinaryWriter(ms))
|
||||
{
|
||||
writer.Write((byte)0x65);
|
||||
foreach (var s in sync)
|
||||
writer.Write(s);
|
||||
writer.Write(sync);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
|
||||
@@ -43,8 +43,6 @@ namespace OpenRA.Network
|
||||
public bool GameStarted { get { return NetFrameNumber != 0; } }
|
||||
public IConnection Connection { get; private set; }
|
||||
|
||||
public readonly int SyncHeaderSize = 9;
|
||||
|
||||
List<Order> localOrders = new List<Order>();
|
||||
|
||||
List<ChatLine> chatCache = new List<ChatLine>();
|
||||
@@ -53,16 +51,12 @@ namespace OpenRA.Network
|
||||
|
||||
bool disposed;
|
||||
|
||||
static void OutOfSync(int frame)
|
||||
void OutOfSync(int frame)
|
||||
{
|
||||
syncReport.DumpSyncReport(frame, frameData.OrdersForFrame(World, frame));
|
||||
throw new InvalidOperationException("Out of sync in frame {0}.\n Compare syncreport.log with other players.".F(frame));
|
||||
}
|
||||
|
||||
static void OutOfSync(int frame, string blame)
|
||||
{
|
||||
throw new InvalidOperationException("Out of sync in frame {0}: Blame {1}.\n Compare syncreport.log with other players.".F(frame, blame));
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
if (GameStarted) return;
|
||||
@@ -145,41 +139,16 @@ namespace OpenRA.Network
|
||||
if (syncForFrame.TryGetValue(frame, out existingSync))
|
||||
{
|
||||
if (packet.Length != existingSync.Length)
|
||||
{
|
||||
syncReport.DumpSyncReport(frame);
|
||||
OutOfSync(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < packet.Length; i++)
|
||||
{
|
||||
if (packet[i] != existingSync[i])
|
||||
{
|
||||
syncReport.DumpSyncReport(frame);
|
||||
|
||||
if (i < SyncHeaderSize)
|
||||
OutOfSync(frame, "Tick");
|
||||
else
|
||||
OutOfSync(frame, (i - SyncHeaderSize) / 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
OutOfSync(frame);
|
||||
}
|
||||
else
|
||||
syncForFrame.Add(frame, packet);
|
||||
}
|
||||
|
||||
void OutOfSync(int frame, int index)
|
||||
{
|
||||
var orders = frameData.OrdersForFrame(World, frame);
|
||||
|
||||
// Invalid index
|
||||
if (index >= orders.Count())
|
||||
OutOfSync(frame);
|
||||
|
||||
throw new InvalidOperationException("Out of sync in frame {0}.\n {1}\n Compare syncreport.log with other players.".F(frame, orders.ElementAt(index).Order.ToString()));
|
||||
}
|
||||
|
||||
public bool IsReadyForNextFrame
|
||||
{
|
||||
get { return NetFrameNumber >= 1 && frameData.IsReadyForFrame(NetFrameNumber); }
|
||||
@@ -204,17 +173,10 @@ namespace OpenRA.Network
|
||||
Connection.Send(NetFrameNumber + FramesAhead, localOrders.Select(o => o.Serialize()).ToList());
|
||||
localOrders.Clear();
|
||||
|
||||
var sync = new List<int>();
|
||||
sync.Add(World.SyncHash());
|
||||
|
||||
foreach (var order in frameData.OrdersForFrame(World, NetFrameNumber))
|
||||
{
|
||||
UnitOrders.ProcessOrder(this, World, order.Client, order.Order);
|
||||
sync.Add(World.SyncHash());
|
||||
}
|
||||
|
||||
var ss = sync.SerializeSync();
|
||||
Connection.SendSync(NetFrameNumber, ss);
|
||||
Connection.SendSync(NetFrameNumber, OrderIO.SerializeSync(World.SyncHash()));
|
||||
|
||||
syncReport.UpdateSyncReport();
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Network
|
||||
}
|
||||
}
|
||||
|
||||
internal void DumpSyncReport(int frame)
|
||||
internal void DumpSyncReport(int frame, IEnumerable<FrameData.ClientOrder> orders)
|
||||
{
|
||||
foreach (var r in syncReports)
|
||||
{
|
||||
@@ -128,6 +128,10 @@ namespace OpenRA.Network
|
||||
Log.Write("sync", "\t\t {0}: {1}".F(nvp.First[i], nvp.Second[i]));
|
||||
}
|
||||
|
||||
Log.Write("sync", "Orders Issued:");
|
||||
foreach (var o in orders)
|
||||
Log.Write("sync", "\t {0}", o.ToString());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user