Add time debug info. Fix sleep duration for audio sync.

This commit is contained in:
2022-11-12 17:02:21 +08:00
parent a47faf0049
commit 252853f4d4
2 changed files with 16 additions and 2 deletions

View File

@@ -105,6 +105,7 @@ namespace Cryville.Crtr {
bool texloaddone; bool texloaddone;
diag::Stopwatch texloadtimer = new diag::Stopwatch(); diag::Stopwatch texloadtimer = new diag::Stopwatch();
bool firstFrame; bool firstFrame;
double atime0;
void Update() { void Update() {
// if (Input.GetKeyDown(KeyCode.Return)) TogglePlay(); // if (Input.GetKeyDown(KeyCode.Return)) TogglePlay();
if (started) { if (started) {
@@ -238,6 +239,12 @@ namespace Cryville.Crtr {
UnityEngine.Profiling.Profiler.GetTotalReservedMemory() UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
#endif #endif
); );
if (started) sttext += string.Format(
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
cbus.Time,
Game.AudioClient.Position - atime0,
inputProxy.GetTimestampAverage()
);
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString(); if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString();
status.text = sttext; status.text = sttext;
} }
@@ -401,8 +408,8 @@ namespace Cryville.Crtr {
timer.Stop(); timer.Stop();
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds); Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds);
Game.AudioSequencer.Playing = true; Game.AudioSequencer.Playing = true;
Thread.Sleep((int)(Game.AudioClient.BufferPosition - Game.AudioClient.Position)); atime0 = Game.AudioClient.BufferPosition;
// TODO SyncTime(cbus.Time); Thread.Sleep((int)((atime0 - Game.AudioClient.Position) * 1000));
inputProxy.SyncTime(cbus.Time); inputProxy.SyncTime(cbus.Time);
started = true; started = true;
} }

View File

@@ -194,6 +194,13 @@ namespace Cryville.Crtr {
} }
} }
} }
public double GetTimestampAverage() {
double result = 0;
foreach (var src in _sproxies.Keys) {
result += src.Handler.GetCurrentTimestamp() - _timeOrigins[src.Handler];
}
return result / _sproxies.Count;
}
#endregion #endregion
} }