Fix incremental menu animation presentation
This commit is contained in:
@@ -33,6 +33,7 @@ internal class RecordingHost : IHost
|
||||
public readonly List<bool> WaitIndicatorEnabledChanges = new();
|
||||
public readonly List<int> PublishedAdvTextLayouts = new();
|
||||
public readonly List<long> SleptDurations = new();
|
||||
public readonly List<long> TimedCallbackWaitDurations = new();
|
||||
public readonly List<(long Resource, int Channel)> SfxLoads = new();
|
||||
public readonly List<long> Voices = new();
|
||||
public readonly List<(long Id, int PlaybackVariant)> VoiceRequests = new();
|
||||
@@ -148,6 +149,11 @@ internal class RecordingHost : IHost
|
||||
public void SetCursorResource(long resourceId) => CursorResources.Add(resourceId);
|
||||
public void ClearCursorResource() => CursorClearCount++;
|
||||
public virtual void Sleep(long duration) => SleptDurations.Add(duration);
|
||||
public virtual void WaitForTimedCallbackDeadline(long duration)
|
||||
{
|
||||
TimedCallbackWaitDurations.Add(duration);
|
||||
Sleep(duration);
|
||||
}
|
||||
public virtual void FrameYield() { }
|
||||
public void ResetSceneContext() => SceneContextResets++;
|
||||
public bool IsMessageSkipActive => MessageSkip;
|
||||
|
||||
@@ -22,6 +22,21 @@ public class TimedCallbackOpsTests
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class NonPresentingClockHost : RecordingHost
|
||||
{
|
||||
private long _now;
|
||||
public override long InputClockMilliseconds => _now;
|
||||
|
||||
public override void Sleep(long duration)
|
||||
=> throw new InvalidOperationException("Timed callback pacing used presentation-capable sleep.");
|
||||
|
||||
public override void WaitForTimedCallbackDeadline(long duration)
|
||||
{
|
||||
TimedCallbackWaitDurations.Add(duration);
|
||||
_now += duration;
|
||||
}
|
||||
}
|
||||
|
||||
private static Script BuildTwoEventSequence()
|
||||
=> ScriptAssembler.Assemble(Table, "TIMED_CALLBACKS",
|
||||
new List<(int, Operand[])>
|
||||
@@ -48,6 +63,7 @@ public class TimedCallbackOpsTests
|
||||
Assert.Equal(2, vm.Globals[0x100]);
|
||||
Assert.Equal(0, vm.Globals.GetValueOrDefault(0x101));
|
||||
Assert.Equal(new long[] { 10, 10 }, host.SleptDurations);
|
||||
Assert.Equal(new long[] { 10, 10 }, host.TimedCallbackWaitDurations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,5 +78,19 @@ public class TimedCallbackOpsTests
|
||||
Assert.Equal(1, vm.Globals[0x100]);
|
||||
Assert.Equal(1, vm.Globals[0x101]);
|
||||
Assert.Equal(new long[] { 10 }, host.SleptDurations);
|
||||
Assert.Equal(new long[] { 10 }, host.TimedCallbackWaitDurations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SequencePacingDoesNotUsePresentationCapableScriptSleep()
|
||||
{
|
||||
var host = new NonPresentingClockHost();
|
||||
var vm = new VirtualMachine(BuildTwoEventSequence(), Table, host);
|
||||
|
||||
vm.Run();
|
||||
|
||||
Assert.Equal("exit", vm.HaltReason);
|
||||
Assert.Equal(new long[] { 10, 10 }, host.TimedCallbackWaitDurations);
|
||||
Assert.Empty(host.SleptDurations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,9 @@ public interface IHost
|
||||
void SetCursorResource(long resourceId) { }
|
||||
void ClearCursorResource() { }
|
||||
void Sleep(long duration);
|
||||
// Native op-0xd5 pacing sleeps inside run-state 0x40 without publishing retained gfx state.
|
||||
// Interactive hosts must keep this distinct from presentation-capable script op-0xc8 sleep.
|
||||
void WaitForTimedCallbackDeadline(long duration) => Sleep(duration);
|
||||
void FrameYield();
|
||||
// Native op 0x9 resets scene-owned host services before reloading root script resource 0.
|
||||
// Global banks, engine configuration, decoded-asset caches, and persistent profile state survive.
|
||||
|
||||
@@ -2260,7 +2260,7 @@ public sealed class VirtualMachine
|
||||
long elapsedMs = _host.InputClockMilliseconds - _cur.TimedCallbackStartedAtMs.Value;
|
||||
if (elapsedMs < callback.DeadlineMs)
|
||||
{
|
||||
_host.Sleep(callback.DeadlineMs - elapsedMs);
|
||||
_host.WaitForTimedCallbackDeadline(callback.DeadlineMs - elapsedMs);
|
||||
elapsedMs = _host.InputClockMilliseconds - _cur.TimedCallbackStartedAtMs.Value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user