extract SyncReport class from Game
This commit is contained in:
@@ -149,58 +149,6 @@ namespace OpenRA
|
|||||||
internal static int RenderFrame = 0;
|
internal static int RenderFrame = 0;
|
||||||
internal static int LocalTick = 0;
|
internal static int LocalTick = 0;
|
||||||
const int NetTickScale = 3; // 120ms net tick for 40ms local tick
|
const int NetTickScale = 3; // 120ms net tick for 40ms local tick
|
||||||
|
|
||||||
static Queue<Pair<int, string>> syncReports = new Queue<Pair<int, string>>();
|
|
||||||
const int numSyncReports = 5;
|
|
||||||
|
|
||||||
internal static void UpdateSyncReport()
|
|
||||||
{
|
|
||||||
if (!Settings.RecordSyncReports)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (syncReports.Count >= numSyncReports) syncReports.Dequeue();
|
|
||||||
syncReports.Enqueue(Pair.New(orderManager.FrameNumber, GenerateSyncReport()));
|
|
||||||
}
|
|
||||||
|
|
||||||
static string GenerateSyncReport()
|
|
||||||
{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.AppendLine("Actors:");
|
|
||||||
foreach (var a in world.Actors)
|
|
||||||
sb.AppendLine("\t {0} {1} {2} ({3})".F(
|
|
||||||
a.ActorID,
|
|
||||||
a.Info.Name,
|
|
||||||
(a.Owner == null) ? "null" : a.Owner.InternalName,
|
|
||||||
Sync.CalculateSyncHash(a)));
|
|
||||||
|
|
||||||
sb.AppendLine("Tick Actors:");
|
|
||||||
foreach (var a in world.Queries.WithTraitMultiple<object>())
|
|
||||||
{
|
|
||||||
var sync = Sync.CalculateSyncHash(a.Trait);
|
|
||||||
if (sync != 0)
|
|
||||||
sb.AppendLine("\t {0} {1} {2} {3} ({4})".F(
|
|
||||||
a.Actor.ActorID,
|
|
||||||
a.Actor.Info.Name,
|
|
||||||
(a.Actor.Owner == null) ? "null" : a.Actor.Owner.InternalName,
|
|
||||||
a.Trait.GetType().Name,
|
|
||||||
sync));
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void DumpSyncReport(int frame)
|
|
||||||
{
|
|
||||||
var f = syncReports.FirstOrDefault(a => a.First == frame);
|
|
||||||
if (f == default(Pair<int, string>))
|
|
||||||
{
|
|
||||||
Log.Write("sync", "No sync report available!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Write("sync", "Sync for net frame {0} -------------", f.First);
|
|
||||||
Log.Write("sync", "{0}", f.Second);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static event Action ConnectionStateChanged = () => { };
|
public static event Action ConnectionStateChanged = () => { };
|
||||||
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
|
static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
class OrderManager : IDisposable
|
class OrderManager : IDisposable
|
||||||
{
|
{
|
||||||
|
SyncReport syncReport = new SyncReport();
|
||||||
|
|
||||||
public int FrameNumber { get; private set; }
|
public int FrameNumber { get; private set; }
|
||||||
|
|
||||||
public int FramesAhead = 0;
|
public int FramesAhead = 0;
|
||||||
@@ -109,7 +111,7 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
if (packet.Length != existingSync.Length)
|
if (packet.Length != existingSync.Length)
|
||||||
{
|
{
|
||||||
Game.DumpSyncReport(frame);
|
syncReport.DumpSyncReport(frame);
|
||||||
OutOfSync(frame);
|
OutOfSync(frame);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -118,7 +120,7 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
if (packet[i] != existingSync[i])
|
if (packet[i] != existingSync[i])
|
||||||
{
|
{
|
||||||
Game.DumpSyncReport(frame);
|
syncReport.DumpSyncReport(frame);
|
||||||
|
|
||||||
if (i < SyncHeaderSize)
|
if (i < SyncHeaderSize)
|
||||||
OutOfSync(frame, "Tick");
|
OutOfSync(frame, "Tick");
|
||||||
@@ -189,7 +191,7 @@ namespace OpenRA.Network
|
|||||||
Connection.Send( ss );
|
Connection.Send( ss );
|
||||||
WriteToReplay( frameData, ss );
|
WriteToReplay( frameData, ss );
|
||||||
|
|
||||||
Game.UpdateSyncReport();
|
syncReport.UpdateSyncReport();
|
||||||
|
|
||||||
CheckSync( ss );
|
CheckSync( ss );
|
||||||
|
|
||||||
|
|||||||
63
OpenRA.Game/Network/SyncReport.cs
Executable file
63
OpenRA.Game/Network/SyncReport.cs
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRA.Network
|
||||||
|
{
|
||||||
|
class SyncReport
|
||||||
|
{
|
||||||
|
Queue<Pair<int, string>> syncReports = new Queue<Pair<int, string>>();
|
||||||
|
const int numSyncReports = 5;
|
||||||
|
|
||||||
|
internal void UpdateSyncReport()
|
||||||
|
{
|
||||||
|
if (!Game.Settings.RecordSyncReports)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (syncReports.Count >= numSyncReports) syncReports.Dequeue();
|
||||||
|
syncReports.Enqueue(Pair.New(Game.orderManager.FrameNumber, GenerateSyncReport()));
|
||||||
|
}
|
||||||
|
|
||||||
|
string GenerateSyncReport()
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine("Actors:");
|
||||||
|
foreach (var a in Game.world.Actors)
|
||||||
|
sb.AppendLine("\t {0} {1} {2} ({3})".F(
|
||||||
|
a.ActorID,
|
||||||
|
a.Info.Name,
|
||||||
|
(a.Owner == null) ? "null" : a.Owner.InternalName,
|
||||||
|
Sync.CalculateSyncHash(a)));
|
||||||
|
|
||||||
|
sb.AppendLine("Tick Actors:");
|
||||||
|
foreach (var a in Game.world.Queries.WithTraitMultiple<object>())
|
||||||
|
{
|
||||||
|
var sync = Sync.CalculateSyncHash(a.Trait);
|
||||||
|
if (sync != 0)
|
||||||
|
sb.AppendLine("\t {0} {1} {2} {3} ({4})".F(
|
||||||
|
a.Actor.ActorID,
|
||||||
|
a.Actor.Info.Name,
|
||||||
|
(a.Actor.Owner == null) ? "null" : a.Actor.Owner.InternalName,
|
||||||
|
a.Trait.GetType().Name,
|
||||||
|
sync));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void DumpSyncReport(int frame)
|
||||||
|
{
|
||||||
|
var f = syncReports.FirstOrDefault(a => a.First == frame);
|
||||||
|
if (f == default(Pair<int, string>))
|
||||||
|
{
|
||||||
|
Log.Write("sync", "No sync report available!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Write("sync", "Sync for net frame {0} -------------", f.First);
|
||||||
|
Log.Write("sync", "{0}", f.Second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -235,6 +235,7 @@
|
|||||||
<Compile Include="ModData.cs" />
|
<Compile Include="ModData.cs" />
|
||||||
<Compile Include="Map.cs" />
|
<Compile Include="Map.cs" />
|
||||||
<Compile Include="ObjectCreator.cs" />
|
<Compile Include="ObjectCreator.cs" />
|
||||||
|
<Compile Include="Network\SyncReport.cs" />
|
||||||
<Compile Include="Traits\PrimaryBuilding.cs" />
|
<Compile Include="Traits\PrimaryBuilding.cs" />
|
||||||
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user