3x faster syncreport
This commit is contained in:
@@ -3,63 +3,86 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Support;
|
||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
{
|
{
|
||||||
class SyncReport
|
class SyncReport
|
||||||
{
|
{
|
||||||
Queue<Pair<int, string>> syncReports = new Queue<Pair<int, string>>();
|
|
||||||
const int numSyncReports = 5;
|
const int numSyncReports = 5;
|
||||||
|
Report[] syncReports = new Report[numSyncReports];
|
||||||
|
int curIndex = 0;
|
||||||
|
|
||||||
|
public SyncReport()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < numSyncReports; i++)
|
||||||
|
syncReports[i] = new SyncReport.Report();
|
||||||
|
}
|
||||||
|
|
||||||
internal void UpdateSyncReport()
|
internal void UpdateSyncReport()
|
||||||
{
|
{
|
||||||
if (!Game.Settings.Debug.RecordSyncReports)
|
if (!Game.Settings.Debug.RecordSyncReports)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (syncReports.Count >= numSyncReports) syncReports.Dequeue();
|
GenerateSyncReport(syncReports[curIndex]);
|
||||||
syncReports.Enqueue(Pair.New(Game.orderManager.FrameNumber, GenerateSyncReport()));
|
curIndex = ++curIndex % numSyncReports;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GenerateSyncReport()
|
void GenerateSyncReport(Report report)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
report.Frame = Game.orderManager.FrameNumber;
|
||||||
sb.AppendLine("SharedRandom: "+Game.world.SharedRandom.Last);
|
report.Traits.Clear();
|
||||||
|
|
||||||
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>())
|
foreach (var a in Game.world.Queries.WithTraitMultiple<object>())
|
||||||
{
|
{
|
||||||
var sync = Sync.CalculateSyncHash(a.Trait);
|
var sync = Sync.CalculateSyncHash(a.Trait);
|
||||||
if (sync != 0)
|
if (sync != 0)
|
||||||
sb.AppendLine("\t {0} {1} {2} {3} ({4})".F(
|
report.Traits.Add(new TraitReport()
|
||||||
a.Actor.ActorID,
|
{
|
||||||
a.Actor.Info.Name,
|
ActorID = a.Actor.ActorID,
|
||||||
(a.Actor.Owner == null) ? "null" : a.Actor.Owner.InternalName,
|
Type = a.Actor.Info.Name,
|
||||||
a.Trait.GetType().Name,
|
Owner = (a.Actor.Owner == null) ? "null" : a.Actor.Owner.InternalName,
|
||||||
sync));
|
Trait = a.Trait.GetType().Name,
|
||||||
|
Hash = sync
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DumpSyncReport(int frame)
|
internal void DumpSyncReport(int frame)
|
||||||
{
|
{
|
||||||
var f = syncReports.FirstOrDefault(a => a.First == frame);
|
foreach (var r in syncReports)
|
||||||
if (f == default(Pair<int, string>))
|
if (r.Frame == frame)
|
||||||
{
|
{
|
||||||
Log.Write("sync", "No sync report available!");
|
Log.Write("sync", "Sync for net frame {0} -------------", r.Frame);
|
||||||
|
Log.Write("sync", "SharedRandom: "+r.SyncedRandom);
|
||||||
|
Log.Write("sync", "Synced Traits:");
|
||||||
|
foreach (var a in r.Traits)
|
||||||
|
Log.Write("sync", "\t {0} {1} {2} {3} ({4})".F(
|
||||||
|
a.ActorID,
|
||||||
|
a.Type,
|
||||||
|
a.Owner,
|
||||||
|
a.Trait,
|
||||||
|
a.Hash
|
||||||
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Log.Write("sync", "No sync report available!");
|
||||||
Log.Write("sync", "Sync for net frame {0} -------------", f.First);
|
|
||||||
Log.Write("sync", "{0}", f.Second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Report
|
||||||
|
{
|
||||||
|
public int Frame;
|
||||||
|
public int SyncedRandom;
|
||||||
|
public List<TraitReport> Traits = new List<TraitReport>();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TraitReport
|
||||||
|
{
|
||||||
|
public uint ActorID;
|
||||||
|
public string Type;
|
||||||
|
public string Owner;
|
||||||
|
public string Trait;
|
||||||
|
public int Hash;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user