A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Advisors: an advisor clip no longer freezes on its first frame when a seek does not take (Refs #1484) (#1623)
Eyal Golane42afc3840f1
diff --git a/changelog.d/advisor-clip-unseekable.md b/changelog.d/advisor-clip-unseekable.mdnew file mode 100644index 000000000..f1d4f60e5--- /dev/null+++ b/changelog.d/advisor-clip-unseekable.md@@ -0,0 +1,3 @@+### Fixed+- An advisor clip no longer freezes on its first frame while the narration and captions run on, when the clip falls+ behind and the web host cannot seek in it: one seek that does not take is not repeated.diff --git a/unity/Assets/Scripts/UI/AdvisorMedia.cs b/unity/Assets/Scripts/UI/AdvisorMedia.csindex 318c14dde..e6ec17a14 100644--- a/unity/Assets/Scripts/UI/AdvisorMedia.cs+++ b/unity/Assets/Scripts/UI/AdvisorMedia.cs@@ -40,7 +40,8 @@ namespace Statecraft.Game.UIAction? ended;Action<string>? failed;string file = "", stem = "";- bool started, heard, moving, disposed;+ bool started, heard, moving, disposed, unseekable;+ double sought = -1;int generation, loadingMs, stalledMs, decodingMs, startingMs, pictureMs, pictureStalledMs;ulong bytes, pictureBytes;@@ -136,7 +137,15 @@ namespace Statecraft.Game.UI}int cue = AdvisorCaptions.At(cues, output.Position);if (caption != null) caption.text = cue < 0 ? "" : text[stem + ".cue." + (cue + 1)];- if (moving && picture != null && Math.Abs(picture.Time - output.Position) > DriftS) picture.Seek(output.Position);+ if (moving && picture != null && !unseekable)+ {+ // A seek that did not take is not repeated: a host that serves no byte ranges cannot seek, so the browser puts+ // the clip back at its start, and seeking again every tick held the picture on its first frame (v0.3.0 release+ // check). The picture then plays on unsynced.+ if (sought >= 0 && picture.Time < sought - DriftS) unseekable = true;+ else if (Math.Abs(picture.Time - output.Position) > DriftS) { sought = output.Position; picture.Seek(sought); }+ else sought = -1;+ }}void Fail(string why)@@ -156,7 +165,7 @@ namespace Statecraft.Game.UIoutput.Stop(); Release(narration); narration = null;if (caption != null) caption.text = "";caption = null; ended = null; failed = null;- started = heard = false;+ started = heard = unseekable = false; sought = -1;loadingMs = stalledMs = decodingMs = startingMs = pictureMs = pictureStalledMs = 0; bytes = pictureBytes = 0;}diff --git a/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs b/unity/Assets/Tests/EditMode/AdvisorMediaTests.csindex 51423c356..cb8f48efa 100644--- a/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs+++ b/unity/Assets/Tests/EditMode/AdvisorMediaTests.cs@@ -24,7 +24,9 @@ public class AdvisorMediaTestspublic void Load(string url, VisualElement target, Action<string> failed) { Loads++; }public void Start() { Started = true; Stopped = false; }public void Stop() => Stopped = true;- public void Seek(double t) { Seeks.Add(t); Time = t; }+ /// <summary>False: as a browser whose host serves no byte ranges, every seek puts the clip back at its start.</summary>+ public bool Seekable = true;+ public void Seek(double t) { Seeks.Add(t); Time = Seekable ? t : 0; }}sealed class FakeOutput : DeclarationRecording.IOutput@@ -83,6 +85,36 @@ public class AdvisorMediaTestsAssert.AreEqual(1, pic.Seeks.Count, "within 0.1 s: left alone");}+ /// <summary>The v0.3.0 release check: a host without byte ranges cannot seek, so each seek put the clip back at 0 and the+ /// next tick seeked again, holding the picture on its first frame while the narration ran. One seek that does not take+ /// ends the correction for that clip, and the picture plays on.</summary>+ [Test]+ public void ASeekThatDoesNotTakeIsNotRepeated()+ {+ var (media, pic, output, _) = Make();+ pic.Seekable = false; pic.Ready = true; media.Tick();+ output.Position = 0.3f; media.Tick(); // started late: 0.3 s behind+ Assert.AreEqual(1, pic.Seeks.Count, "the first drift is corrected");+ for (int i = 0; i < 100; i++)+ {+ output.Position += AdvisorMedia.TickMs / 1000f; pic.Time += AdvisorMedia.TickMs / 1000.0;+ media.Tick();+ }+ Assert.AreEqual(1, pic.Seeks.Count, "a seek that came back at the start is not repeated every tick");+ Assert.Greater(pic.Time, 4.9, "the picture advances");+ }++ [Test]+ public void ASeekThatTakesLeavesTheCorrectionOn()+ {+ var (media, pic, output, _) = Make();+ pic.Ready = true; media.Tick();+ output.Position = 1.0f; pic.Time = 0.5; media.Tick();+ output.Position = 1.05f; pic.Time = 1.05; media.Tick();+ output.Position = 3.0f; pic.Time = 2.5; media.Tick();+ CollectionAssert.AreEqual(new[] { 1.0, 3.0 }, pic.Seeks);+ }+[Test]public void CaptionsFollowTheNarrationsPosition(){