From c3e9ca6b805ea06ac1393355aefb3818e1aa9113 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 7 Jun 2026 04:39:12 +0100 Subject: [PATCH] Render Gjallar marquee as continuous ribbon --- docs/architecture.md | 6 +- src/Gjallar/Program.cs | 126 +++++++++++++++++++++++++++++++++++++---- state/gjallar-state.md | 18 +++--- 3 files changed, 126 insertions(+), 24 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index 66ce2c3..eb8229e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -17,8 +17,8 @@ regions may use different text resolutions. - Outputs: `gjallar.overview` composition state, visible framebuffer frames, and renderer telemetry. - Derived state: pane weights, pixel rectangles, chosen font sizes, one-row - gutter blocks, alternating scroll offsets, readable marquee glyph positions, - dirty rectangles, glyph runs, and compact agent-readable projections. + gutter blocks, continuous readable marquee ribbon positions, dirty rectangles, + glyph runs, and compact agent-readable projections. - Forbidden writers: discovery systems do not decide Gjallar layout; providers do not tune themselves for Nightwing; framebuffer backends do not invent provider truth; Gjallar does not derive marquee content from provider status @@ -40,7 +40,7 @@ Odin provider catalog -> EveNode panel extraction -> weighted AABB packing -> one-row gutter cell plan - -> alternating readable marquee block offsets + -> continuous readable marquee ribbon path -> per-panel text pressure estimate -> PSF font selection -> frame draw commands diff --git a/src/Gjallar/Program.cs b/src/Gjallar/Program.cs index 2e9b6c9..ae3524a 100644 --- a/src/Gjallar/Program.cs +++ b/src/Gjallar/Program.cs @@ -508,7 +508,7 @@ internal sealed class GjallarRenderer : IDisposable gutterCells = sceneCache?.GutterCells.Count ?? 0, gutterRows = sceneCache?.GutterCells.Select(static cell => cell.Row).Distinct().Count() ?? 0, gutterPolicy = "single-row-top-between-panels-bottom", - gutterFlow = "alternating-scroll-readable-blocks", + gutterFlow = "continuous-readable-ribbon", marqueeChars = sceneCache?.MarqueeTape.Length ?? 0, marqueeSample = Sample(sceneCache?.MarqueeTape ?? "", 160), visibleMarqueeRows, @@ -945,28 +945,39 @@ internal sealed class FrameDocument private static IReadOnlyList VisibleGutterGlyphs(IReadOnlyList cells, int frameIndex, string tape) { const int framesPerScrollCell = 8; - var scroll = (frameIndex / framesPerScrollCell) % Math.Max(1, tape.Length); - var blocks = cells + var rows = cells .GroupBy(static cell => cell.Row) .OrderBy(static group => group.Key) - .Select(static group => group.OrderBy(static cell => cell.LaneColumn).ToArray()) + .Select(static group => new GutterRowBlock(group.Key, group.First().Forward, group.OrderBy(static cell => cell.LaneColumn).ToArray())) .ToArray(); + var pathLength = rows.Sum(static row => row.Cells.Length); + if (pathLength <= 0) + { + return []; + } + + var maxBlockLength = Math.Clamp(rows.Min(static row => row.Cells.Length) / 5, 18, 42); + var blocks = RibbonBlocks(tape, maxBlockLength); + var cycleLength = blocks.Sum(static block => block.Length); + if (cycleLength <= 0) + { + return []; + } + + var scroll = (frameIndex / framesPerScrollCell) % cycleLength; var glyphs = new List(); var blockStart = 0; foreach (var block in blocks) { - if (block.Length == 0) + var firstStart = PositiveMod(blockStart + scroll, cycleLength); + for (var pathStart = firstStart; pathStart < pathLength; pathStart += cycleLength) { - continue; + AddRibbonBlockGlyphs(glyphs, rows, pathLength, block, pathStart); } - var direction = block[0].Forward ? 1 : -1; - for (var index = 0; index < block.Length; index++) + for (var pathStart = firstStart - cycleLength; pathStart > -block.Length; pathStart -= cycleLength) { - var cell = block[index]; - var tapeIndex = blockStart + index + direction * scroll; - var character = tape[((tapeIndex % tape.Length) + tape.Length) % tape.Length]; - glyphs.Add(new VisibleGutterGlyph(cell, character)); + AddRibbonBlockGlyphs(glyphs, rows, pathLength, block, pathStart); } blockStart += block.Length; @@ -975,6 +986,96 @@ internal sealed class FrameDocument return glyphs; } + private static void AddRibbonBlockGlyphs(List glyphs, IReadOnlyList rows, int pathLength, string block, int pathStart) + { + var blockIndex = 0; + var path = pathStart; + while (blockIndex < block.Length && path < pathLength) + { + if (path < 0) + { + var skip = Math.Min(block.Length - blockIndex, -path); + blockIndex += skip; + path += skip; + continue; + } + + var rowStart = 0; + GutterRowBlock? row = null; + foreach (var candidate in rows) + { + var rowEnd = rowStart + candidate.Cells.Length; + if (path < rowEnd) + { + row = candidate; + break; + } + rowStart = rowEnd; + } + + if (row is null) + { + return; + } + + var rowOffset = path - rowStart; + var take = Math.Min(block.Length - blockIndex, row.Cells.Length - rowOffset); + var visualStart = row.Forward + ? rowOffset + : row.Cells.Length - rowOffset - take; + for (var index = 0; index < take; index++) + { + var cell = row.Cells[visualStart + index]; + glyphs.Add(new VisibleGutterGlyph(cell, block[blockIndex + index])); + } + + blockIndex += take; + path += take; + } + } + + private static IReadOnlyList RibbonBlocks(string tape, int maxBlockLength) + { + var blocks = new List(); + var builder = new StringBuilder(); + foreach (var word in tape.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + { + var token = $"{word} "; + if (builder.Length > 0 && builder.Length + token.Length > maxBlockLength) + { + blocks.Add(builder.ToString()); + builder.Clear(); + } + + if (token.Length > maxBlockLength) + { + if (builder.Length > 0) + { + blocks.Add(builder.ToString()); + builder.Clear(); + } + + for (var index = 0; index < token.Length; index += maxBlockLength) + { + blocks.Add(token.Substring(index, Math.Min(maxBlockLength, token.Length - index))); + } + continue; + } + + builder.Append(token); + } + + if (builder.Length > 0) + { + blocks.Add(builder.ToString()); + } + + return blocks; + } + + private static int PositiveMod(int value, int modulus) => + ((value % modulus) + modulus) % modulus; + private static string MarketPoetryTape(string marqueeTape) { var tape = string.IsNullOrWhiteSpace(marqueeTape) ? "" : marqueeTape.Replace('\r', ' ').Replace('\n', ' ').Trim(); @@ -1718,6 +1819,7 @@ internal sealed record FillCommand(RectI Rect, int ColorIndex); internal sealed record TextCommand(PsfFont Font, int X, int Y, string Text, int MaxWidth, int ColorIndex); internal sealed record GlyphCommand(int X, int Y, char Character, int ColorIndex); internal sealed record VisibleGutterGlyph(GutterCell Cell, char Character); +internal sealed record GutterRowBlock(int Row, bool Forward, GutterCell[] Cells); internal sealed record GutterCell(int X, int Y, int Row, int LaneColumn, bool Forward); internal sealed class ToneBatch(int resolutionY, int frameIndex) diff --git a/state/gjallar-state.md b/state/gjallar-state.md index 19bc449..76d3ed7 100644 --- a/state/gjallar-state.md +++ b/state/gjallar-state.md @@ -45,7 +45,7 @@ Observed live status after marquee/gutter cut: "panels": 6, "gutterRows": 3, "gutterPolicy": "single-row-top-between-panels-bottom", - "gutterFlow": "alternating-scroll-readable-blocks", + "gutterFlow": "continuous-readable-ribbon", "marqueeChars": 3101, "visibleMarqueeRows": ["..."] } @@ -63,8 +63,8 @@ Observed live status after marquee/gutter cut: - Outputs: `gjallar.overview` composition state, framebuffer frames, sparse refresh streams, and agent-readable panel captures. - Derived state: pane weights, pixel rectangles, selected fonts, one-row gutter - blocks, alternating scroll offsets, readable marquee glyph positions, dirty - rectangles, glyph runs, and compact text projections. + blocks, a continuous readable marquee ribbon path, dirty rectangles, glyph + runs, and compact text projections. - Forbidden writers: discovery systems must not decide Gjallar layout; providers must not tune themselves for Nightwing; framebuffer backends must not invent provider truth; Gjallar must not synthesize status-noise marquee content from @@ -154,9 +154,9 @@ Source: `https://en.wikipedia.org/wiki/Linux_framebuffer` - `FontAtlas.ForTextBox` picks a font per panel based on available pixel area and text pressure. - `FrameDocument` draws text, panels, gutters, marquee glyphs, and fills. It - lowers the incoming marquee as readable text inside each gutter block. - Adjacent gutter blocks alternate scroll direction, but glyph order remains - left-to-right inside every block. + lowers the incoming marquee as a continuous ribbon of readable text chunks. + Adjacent gutter blocks alternate direction by changing chunk placement along + the path; letters inside each chunk keep normal left-to-right order. - `visibleMarqueeRows` in `/var/log/gjallar.status` samples the actual gutter rows produced by the render math. Use it when the framebuffer symptom differs from the received `marqueeSample`. @@ -173,9 +173,9 @@ Source: `https://en.wikipedia.org/wiki/Linux_framebuffer` ticker segments. Odin publishes the canonical tape; Gjallar consumes it from the provider catalog and enforces one glyph row for top padding, one per inter-panel gutter band, and one for bottom padding. -- 2026-06-07 gutter flow correction: the marquee is split into gutter blocks - again. Blocks alternate scroll direction without reversing glyph order inside - right-to-left blocks. +- 2026-06-07 ribbon correction: the marquee is a single continuous ribbon path + through the gutter blocks. A phrase or quote leaving one gutter continues in + the next gutter, while chunk text remains readable. - Transport debt remains explicit: the live Nightwing body still consumes the compatibility Eve deck bridge. The target input organ is native CultNet / CultMesh typed state over the real GameCult transport, not a web-shaped