Implement pausing.
This commit is contained in:
@@ -142,6 +142,7 @@ namespace Cryville.Crtr {
|
|||||||
step = autoRenderStep ? Time.smoothDeltaTime : renderStep;
|
step = autoRenderStep ? Time.smoothDeltaTime : renderStep;
|
||||||
}
|
}
|
||||||
inputProxy.ForceTick();
|
inputProxy.ForceTick();
|
||||||
|
if (paused) return;
|
||||||
cbus.ForwardByTime(dt);
|
cbus.ForwardByTime(dt);
|
||||||
bbus.ForwardByTime(dt);
|
bbus.ForwardByTime(dt);
|
||||||
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
||||||
@@ -262,11 +263,12 @@ namespace Cryville.Crtr {
|
|||||||
cbus.ActiveStateCount, bbus.ActiveStateCount
|
cbus.ActiveStateCount, bbus.ActiveStateCount
|
||||||
);
|
);
|
||||||
statusbuf.AppendFormat(
|
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,
|
cbus.Time,
|
||||||
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
|
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
|
||||||
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
|
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
|
||||||
forceSyncFrames != 0 ? "(force sync)" : ""
|
forceSyncFrames != 0 ? "(force sync)" : "",
|
||||||
|
paused ? "(paused)" : ""
|
||||||
);
|
);
|
||||||
if (judge != null) {
|
if (judge != null) {
|
||||||
statusbuf.Append("\n== Scores ==\n");
|
statusbuf.Append("\n== Scores ==\n");
|
||||||
@@ -319,6 +321,20 @@ namespace Cryville.Crtr {
|
|||||||
else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading");
|
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
|
#endregion
|
||||||
|
|
||||||
#region Load
|
#region Load
|
||||||
@@ -448,6 +464,7 @@ namespace Cryville.Crtr {
|
|||||||
public void Stop() {
|
public void Stop() {
|
||||||
try {
|
try {
|
||||||
Logger.Log("main", 1, "Game", "Stopping");
|
Logger.Log("main", 1, "Game", "Stopping");
|
||||||
|
Game.AudioClient.Start();
|
||||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||||
inputProxy.Deactivate();
|
inputProxy.Deactivate();
|
||||||
if (nbus != null) { nbus.Dispose(); nbus = null; }
|
if (nbus != null) { nbus.Dispose(); nbus = null; }
|
||||||
@@ -534,7 +551,7 @@ namespace Cryville.Crtr {
|
|||||||
LoadSkin(info.skinFile);
|
LoadSkin(info.skinFile);
|
||||||
|
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input");
|
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input");
|
||||||
judge = new Judge(pruleset);
|
judge = new Judge(this, pruleset);
|
||||||
etor.ContextJudge = judge;
|
etor.ContextJudge = judge;
|
||||||
|
|
||||||
inputProxy = new InputProxy(pruleset, judge);
|
inputProxy = new InputProxy(pruleset, judge);
|
||||||
|
|||||||
@@ -180,12 +180,13 @@ namespace Cryville.Crtr {
|
|||||||
readonly Dictionary<InputIdentifier, float> _vect = new Dictionary<InputIdentifier, float>();
|
readonly Dictionary<InputIdentifier, float> _vect = new Dictionary<InputIdentifier, float>();
|
||||||
readonly Dictionary<ProxiedInputIdentifier, PropSrc> _vecs = new Dictionary<ProxiedInputIdentifier, PropSrc>();
|
readonly Dictionary<ProxiedInputIdentifier, PropSrc> _vecs = new Dictionary<ProxiedInputIdentifier, PropSrc>();
|
||||||
static readonly PropSrc.Arbitrary _nullsrc = new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]);
|
static readonly PropSrc.Arbitrary _nullsrc = new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]);
|
||||||
|
double? _lockTime = null;
|
||||||
unsafe void OnInput(InputIdentifier id, InputVector vec) {
|
unsafe void OnInput(InputIdentifier id, InputVector vec) {
|
||||||
lock (_lock) {
|
lock (_lock) {
|
||||||
InputProxyEntry proxy;
|
InputProxyEntry proxy;
|
||||||
if (_sproxies.TryGetValue(id.Source, out proxy)) {
|
if (_sproxies.TryGetValue(id.Source, out proxy)) {
|
||||||
_etor.ContextCascadeInsert();
|
_etor.ContextCascadeInsert();
|
||||||
float ft, tt = (float)(vec.Time - _timeOrigins[id.Source.Handler]);
|
float ft, tt = (float)(_lockTime != null ? _lockTime.Value : (vec.Time - _timeOrigins[id.Source.Handler]));
|
||||||
if (!_vect.TryGetValue(id, out ft)) ft = tt;
|
if (!_vect.TryGetValue(id, out ft)) ft = tt;
|
||||||
if (vec.IsNull) {
|
if (vec.IsNull) {
|
||||||
_etor.ContextCascadeUpdate(_var_value, _nullsrc);
|
_etor.ContextCascadeUpdate(_var_value, _nullsrc);
|
||||||
@@ -243,7 +244,7 @@ namespace Cryville.Crtr {
|
|||||||
public void ForceTick() {
|
public void ForceTick() {
|
||||||
foreach (var src in _sproxies.Keys) {
|
foreach (var src in _sproxies.Keys) {
|
||||||
if (_activeCounts[src] == 0) {
|
if (_activeCounts[src] == 0) {
|
||||||
OnInput(new InputIdentifier { Source = src, Id = 0 }, new InputVector(src.Handler.GetCurrentTimestamp()));
|
OnInput(new InputIdentifier { Source = src, Id = 0 }, new InputVector(_lockTime != null ? _lockTime.Value : src.Handler.GetCurrentTimestamp()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,6 +255,8 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
return result / _sproxies.Count;
|
return result / _sproxies.Count;
|
||||||
}
|
}
|
||||||
|
public void LockTime() { _lockTime = GetTimestampAverage(); }
|
||||||
|
public void UnlockTime() { _lockTime = null; }
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,15 @@ using System.Text.Formatting;
|
|||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Judge {
|
public class Judge {
|
||||||
#region Data
|
#region Data
|
||||||
|
readonly ChartPlayer _sys;
|
||||||
readonly PdtEvaluator _etor;
|
readonly PdtEvaluator _etor;
|
||||||
readonly PdtRuleset _rs;
|
readonly PdtRuleset _rs;
|
||||||
readonly Dictionary<Identifier, List<JudgeEvent>> evs
|
readonly Dictionary<Identifier, List<JudgeEvent>> evs
|
||||||
= new Dictionary<Identifier, List<JudgeEvent>>();
|
= new Dictionary<Identifier, List<JudgeEvent>>();
|
||||||
readonly Dictionary<Identifier, List<JudgeEvent>> activeEvs
|
readonly Dictionary<Identifier, List<JudgeEvent>> activeEvs
|
||||||
= new Dictionary<Identifier, List<JudgeEvent>>();
|
= new Dictionary<Identifier, List<JudgeEvent>>();
|
||||||
|
static readonly int _var_pause = IdentifierManager.SharedInstance.Request("pause");
|
||||||
|
readonly JudgeDefinition _judgePause;
|
||||||
public struct JudgeEvent {
|
public struct JudgeEvent {
|
||||||
public double StartTime { get; set; }
|
public double StartTime { get; set; }
|
||||||
public double EndTime { get; set; }
|
public double EndTime { get; set; }
|
||||||
@@ -30,22 +33,33 @@ namespace Cryville.Crtr {
|
|||||||
return x.StartClip.CompareTo(y.StartClip);
|
return x.StartClip.CompareTo(y.StartClip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Judge(PdtRuleset rs) {
|
public Judge(ChartPlayer sys, PdtRuleset rs) {
|
||||||
|
_sys = sys;
|
||||||
_etor = ChartPlayer.etor;
|
_etor = ChartPlayer.etor;
|
||||||
_rs = rs;
|
_rs = rs;
|
||||||
_numsrc1 = new PropSrc.Float(() => _numbuf1);
|
_numsrc1 = new PropSrc.Float(() => _numbuf1);
|
||||||
_numsrc2 = new PropSrc.Float(() => _numbuf2);
|
_numsrc2 = new PropSrc.Float(() => _numbuf2);
|
||||||
_numsrc3 = new PropSrc.Float(() => _numbuf3);
|
_numsrc3 = new PropSrc.Float(() => _numbuf3);
|
||||||
_numsrc4 = new PropSrc.Float(() => _numbuf4);
|
_numsrc4 = new PropSrc.Float(() => _numbuf4);
|
||||||
|
_rs.judges.TryGetValue(new Identifier(_var_pause), out _judgePause);
|
||||||
foreach (var i in rs.inputs.Keys) {
|
foreach (var i in rs.inputs.Keys) {
|
||||||
evs.Add(i, new List<JudgeEvent>());
|
var l = new List<JudgeEvent>();
|
||||||
|
evs.Add(i, l);
|
||||||
activeEvs.Add(i, new List<JudgeEvent>());
|
activeEvs.Add(i, new List<JudgeEvent>());
|
||||||
|
if (_judgePause != null && i.Key == _var_pause) {
|
||||||
|
l.Add(new JudgeEvent {
|
||||||
|
StartTime = double.NegativeInfinity, EndTime = double.PositiveInfinity,
|
||||||
|
StartClip = double.NegativeInfinity, EndClip = double.PositiveInfinity,
|
||||||
|
Definition = _judgePause,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
InitJudges();
|
InitJudges();
|
||||||
InitScores();
|
InitScores();
|
||||||
}
|
}
|
||||||
public void Prepare(StampedEvent sev, NoteHandler handler) {
|
public void Prepare(StampedEvent sev, NoteHandler handler) {
|
||||||
var tev = (Chart.Judge)sev.Unstamped;
|
var tev = (Chart.Judge)sev.Unstamped;
|
||||||
|
if (tev.Id.Key == _var_pause) throw new InvalidOperationException("Cannot assign the special judge \"pause\" to notes");
|
||||||
Identifier input = default(Identifier);
|
Identifier input = default(Identifier);
|
||||||
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => input = new Identifier(v)), _rs.judges[tev.Id].input);
|
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => input = new Identifier(v)), _rs.judges[tev.Id].input);
|
||||||
double st = sev.Time, et = st + sev.Duration;
|
double st = sev.Time, et = st + sev.Duration;
|
||||||
@@ -127,6 +141,7 @@ namespace Cryville.Crtr {
|
|||||||
if (def.hit != null) _etor.Evaluate(_flagop, def.hit);
|
if (def.hit != null) _etor.Evaluate(_flagop, def.hit);
|
||||||
else _flag = true;
|
else _flag = true;
|
||||||
if (_flag) {
|
if (_flag) {
|
||||||
|
if (ev.Definition == _judgePause) _sys.TogglePause();
|
||||||
if (def.scores != null) UpdateScore(def.scores);
|
if (def.scores != null) UpdateScore(def.scores);
|
||||||
if (def.pass != null) Pass(ev, (ft + tt) / 2, def.pass);
|
if (def.pass != null) Pass(ev, (ft + tt) / 2, def.pass);
|
||||||
actlist.RemoveAt(index);
|
actlist.RemoveAt(index);
|
||||||
|
|||||||
Reference in New Issue
Block a user