Implement pausing.

This commit is contained in:
2023-02-07 16:23:16 +08:00
parent f683d61298
commit eb53c3465b
3 changed files with 42 additions and 7 deletions

View File

@@ -142,6 +142,7 @@ namespace Cryville.Crtr {
step = autoRenderStep ? Time.smoothDeltaTime : renderStep;
}
inputProxy.ForceTick();
if (paused) return;
cbus.ForwardByTime(dt);
bbus.ForwardByTime(dt);
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
@@ -262,11 +263,12 @@ namespace Cryville.Crtr {
cbus.ActiveStateCount, bbus.ActiveStateCount
);
statusbuf.AppendFormat(
"\nSTime: {0:G17}s {3}\ndATime: {1:+0.0ms;-0.0ms;0} {3}\ndITime: {2:+0.0ms;-0.0ms;0} {3}",
"\nSTime: {0:G17}s {3} {4}\ndATime: {1:+0.0ms;-0.0ms;0} {3} {4}\ndITime: {2:+0.0ms;-0.0ms;0} {3}",
cbus.Time,
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
forceSyncFrames != 0 ? "(force sync)" : ""
forceSyncFrames != 0 ? "(force sync)" : "",
paused ? "(paused)" : ""
);
if (judge != null) {
statusbuf.Append("\n== Scores ==\n");
@@ -319,6 +321,20 @@ namespace Cryville.Crtr {
else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading");
}
}
bool paused = false;
public void TogglePause() {
paused = !paused;
if (!paused) {
forceSyncFrames = Settings.Default.ForceSyncFrames;
Game.AudioClient.Start();
inputProxy.UnlockTime();
}
else {
Game.AudioClient.Pause();
inputProxy.LockTime();
}
}
#endregion
#region Load
@@ -448,6 +464,7 @@ namespace Cryville.Crtr {
public void Stop() {
try {
Logger.Log("main", 1, "Game", "Stopping");
Game.AudioClient.Start();
Game.AudioSession = Game.AudioSequencer.NewSession();
inputProxy.Deactivate();
if (nbus != null) { nbus.Dispose(); nbus = null; }
@@ -534,7 +551,7 @@ namespace Cryville.Crtr {
LoadSkin(info.skinFile);
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input");
judge = new Judge(pruleset);
judge = new Judge(this, pruleset);
etor.ContextJudge = judge;
inputProxy = new InputProxy(pruleset, judge);