engine: materialize live ADV glyphs
This commit is contained in:
@@ -216,6 +216,48 @@ public class AdvTextOpsTests
|
||||
host.LiveTextRuns.Select(emitted => emitted.Run.Text));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetainedGlyphMetricsAdvanceCanonicalCursorBetweenRuns()
|
||||
{
|
||||
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
|
||||
static Operand I(long value) => new(0, value);
|
||||
static Operand S(int index) => new(2, index);
|
||||
var script = ScriptAssembler.Assemble(table, "RETAINED_CURSOR",
|
||||
new List<(int, Operand[])>
|
||||
{
|
||||
(0x70, new[] { I(1), I(100), I(50), I(10), I(20) }),
|
||||
(0x79, new[] { I(1), I(2), I(3) }),
|
||||
(0x71, new[] { I(1) }),
|
||||
(0x213, new[] { I(1), I(100), I(10) }),
|
||||
(0x6e, new[] { I(0), S(0) }),
|
||||
(0x6e, new[] { I(0), S(1) }),
|
||||
(0x2, Array.Empty<Operand>()),
|
||||
},
|
||||
new[] { "A", "BC" });
|
||||
var host = new RecordingHost
|
||||
{
|
||||
OnRetainedText = run => new AdvRetainedTextRunResult(
|
||||
run.Layout.Slot,
|
||||
FirstGlyphIndex: 0,
|
||||
GlyphCount: run.Text.Length,
|
||||
CursorX: run.Layout.CursorX + run.Text.Length * 4,
|
||||
CursorY: run.Layout.CursorY),
|
||||
};
|
||||
var vm = new VirtualMachine(script, table, host);
|
||||
|
||||
vm.Run();
|
||||
|
||||
Assert.Equal(new[] { (2, 3), (6, 3) },
|
||||
host.LiveTextRuns.Select(run =>
|
||||
(run.Run.Layout.CursorX, run.Run.Layout.CursorY)));
|
||||
Assert.Equal(new[] { (2, 3), (6, 3) },
|
||||
vm.TextHistory.Records.Select(record =>
|
||||
(record.Layout.CursorX, record.Layout.CursorY)));
|
||||
Assert.Equal((14, 3),
|
||||
(vm.TextHistory.GetLayoutSnapshot(1).CursorX,
|
||||
vm.TextHistory.GetLayoutSnapshot(1).CursorY));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RealMamesResearchDescriptionUsesImmediateRetainedTextPath()
|
||||
{
|
||||
|
||||
@@ -116,7 +116,7 @@ public class NativeNumberedSaveCodecTests
|
||||
new AdvTextLayoutSnapshot(3, 320, 90, 20, 400, 0, 0, 300, 80),
|
||||
liveHistory.GetLayoutSnapshot(3));
|
||||
Assert.Equal(
|
||||
new AdvTextLayoutPresentationBinding(3, 0x17, 0x2000, 500, 0x1234),
|
||||
new AdvTextLayoutPresentationBinding(3, 0x17, 0x2000, 500, 0x1234, 45, 42),
|
||||
liveHistory.GetPresentationBinding(3));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
using Age.Engine.Model;
|
||||
using Age.Engine.Text;
|
||||
|
||||
public class RetainedAdvTextLayoutPresentationTests
|
||||
{
|
||||
[Fact]
|
||||
public void PublishesNativeRectsInHandleOrderAndStopsAtCapacity()
|
||||
{
|
||||
var binding = new AdvTextLayoutPresentationBinding(
|
||||
1, 21, 100, 2, 900, 10, 20);
|
||||
var presentation = new RetainedAdvTextLayoutPresentation(binding);
|
||||
presentation.Append(
|
||||
[
|
||||
new AdvRetainedGlyphRecord(0, 1, 2, 5, 8),
|
||||
new AdvRetainedGlyphRecord(0, 5, 2, 9, 8),
|
||||
],
|
||||
layoutOriginX: 30,
|
||||
layoutOriginY: 40);
|
||||
presentation.Append(
|
||||
[new AdvRetainedGlyphRecord(0, 10, 3, 14, 9)],
|
||||
layoutOriginX: 50,
|
||||
layoutOriginY: 60);
|
||||
var gfx = new GfxState();
|
||||
gfx.CreateSurface(21);
|
||||
|
||||
Assert.Equal(2, presentation.PublishThrough(gfx, 3));
|
||||
|
||||
Assert.Collection(
|
||||
gfx.SnapshotVisibleObjects(),
|
||||
first => Assert.Equal(
|
||||
(100L, 1, 2, 4, 6, 31, 42),
|
||||
(first.Handle, first.SrcX, first.SrcY, first.W, first.H,
|
||||
first.DstX, first.DstY)),
|
||||
second => Assert.Equal(
|
||||
(101L, 5, 2, 4, 6, 35, 42),
|
||||
(second.Handle, second.SrcX, second.SrcY, second.W, second.H,
|
||||
second.DstX, second.DstY)));
|
||||
Assert.Null(gfx.TryGet(102));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RepublishRestoresPartialEraseWithoutAdvancingReveal()
|
||||
{
|
||||
var presentation = Presentation(capacity: 4);
|
||||
var gfx = new GfxState();
|
||||
gfx.CreateSurface(21);
|
||||
presentation.PublishThrough(gfx, 2);
|
||||
gfx.EraseRange(101, 1);
|
||||
|
||||
Assert.Single(gfx.SnapshotVisibleObjects());
|
||||
Assert.Equal(2, presentation.Republish(gfx));
|
||||
Assert.Equal(new long[] { 100, 101 },
|
||||
gfx.SnapshotVisibleObjects().Select(item => item.Handle));
|
||||
|
||||
presentation.ErasePublished(gfx);
|
||||
Assert.Empty(gfx.SnapshotVisibleObjects());
|
||||
Assert.Equal(2, presentation.PublishedGlyphCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConsecutiveRunsRetainTheirOwnLayoutOrigins()
|
||||
{
|
||||
var binding = new AdvTextLayoutPresentationBinding(
|
||||
7, 27, 200, 10, -1, 53, 10);
|
||||
var presentation = new RetainedAdvTextLayoutPresentation(binding);
|
||||
presentation.Append(
|
||||
[new AdvRetainedGlyphRecord(0, 3, 4, 7, 10)],
|
||||
275, 90);
|
||||
presentation.Append(
|
||||
[new AdvRetainedGlyphRecord(0, 7, 4, 11, 10)],
|
||||
275, 135);
|
||||
var gfx = new GfxState();
|
||||
gfx.CreateSurface(27);
|
||||
|
||||
presentation.PublishThrough(gfx, 2);
|
||||
|
||||
Assert.Equal(
|
||||
new[] { (278, 94), (282, 139) },
|
||||
gfx.SnapshotVisibleObjects().Select(item => (item.DstX, item.DstY)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SavedFrameStyleReconstructionRebuildsTheSameBindings()
|
||||
{
|
||||
RetainedAdvTextLayoutPresentation before = Presentation(capacity: 4);
|
||||
var gfx = new GfxState();
|
||||
gfx.CreateSurface(21);
|
||||
before.PublishThrough(gfx, 3);
|
||||
RenderObject[] expected = gfx.SnapshotVisibleObjects().ToArray();
|
||||
|
||||
gfx.EraseRange(
|
||||
before.Binding.FirstObjectHandle,
|
||||
before.Binding.ObjectCapacity);
|
||||
RetainedAdvTextLayoutPresentation reconstructed =
|
||||
Presentation(capacity: 4);
|
||||
reconstructed.PublishThrough(gfx, 3);
|
||||
|
||||
Assert.Equal(expected, gfx.SnapshotVisibleObjects());
|
||||
}
|
||||
|
||||
private static RetainedAdvTextLayoutPresentation Presentation(int capacity)
|
||||
{
|
||||
var presentation = new RetainedAdvTextLayoutPresentation(
|
||||
new AdvTextLayoutPresentationBinding(
|
||||
1, 21, 100, capacity, -1, 10, 20));
|
||||
presentation.Append(
|
||||
[
|
||||
new AdvRetainedGlyphRecord(0, 1, 2, 5, 8),
|
||||
new AdvRetainedGlyphRecord(0, 5, 2, 9, 8),
|
||||
new AdvRetainedGlyphRecord(0, 9, 2, 13, 8),
|
||||
],
|
||||
30,
|
||||
40);
|
||||
return presentation;
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,16 @@ internal class RecordingHost : IHost
|
||||
Lines.Add((run.SourceOffset, run.Text));
|
||||
LiveTextRuns.Add((run, glyphDelayMilliseconds));
|
||||
}
|
||||
public Func<AdvLiveTextRun, AdvRetainedTextRunResult?>? OnRetainedText;
|
||||
public virtual AdvRetainedTextRunResult? ShowText(
|
||||
GfxState gfx,
|
||||
AdvTextLayoutPresentationBinding binding,
|
||||
AdvLiveTextRun run,
|
||||
int glyphDelayMilliseconds)
|
||||
{
|
||||
ShowText(run, glyphDelayMilliseconds);
|
||||
return OnRetainedText?.Invoke(run);
|
||||
}
|
||||
public void SetMessageGlyphDelayMilliseconds(int milliseconds)
|
||||
=> MessageGlyphDelayMilliseconds = milliseconds;
|
||||
public RgbaImage? CaptureSurfacePixels(int slot)
|
||||
|
||||
Reference in New Issue
Block a user