mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
He reported a broken vertical slice at the right edge of the scape. I could not reproduce it in the byte stream: the renderer emits exactly 138 display cells per row at a 138-column terminal, and the host writes exactly 138 per row in every frame. Measured both. What the measurement did surface is a fragility that would make any such fault permanent. Damage tracking skips rows whose content has not changed, so if anything ever writes over a cell the tracker believes it already painted, that row is skipped for as long as its content stays the same -- and the sky and the beach can sit unchanged for minutes. "Until it changes" can mean "for the rest of the session". So the tracker now forgets everything every fiftieth frame and repaints in full. That costs one frame in fifty of the saving damage tracking was added for, and turns a whole class of stuck-pixel faults from permanent into momentary. Not a fix for a diagnosed cause. A guard that makes an undiagnosed one heal.
83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
package host
|
|
|
|
import "testing"
|
|
|
|
// The scape repaints every cell of every row, every frame: measured at ~30KB a
|
|
// frame, and at 20fps that is 0.6MB/s of fully-coloured cells poured into a
|
|
// terminal that is already rendering the agent. Most of those cells are
|
|
// identical to the frame before -- the sky and most of the beach do not move.
|
|
// Rows that did not change should not be sent at all.
|
|
|
|
func TestFirstFrameRepaintsEveryRow(t *testing.T) {
|
|
var d damage
|
|
got := d.changed([]string{"a", "b", "c"})
|
|
if len(got) != 3 {
|
|
t.Errorf("first frame repainted %v, want all three rows", got)
|
|
}
|
|
}
|
|
|
|
func TestUnchangedRowsAreNotRepainted(t *testing.T) {
|
|
var d damage
|
|
d.changed([]string{"sky", "sea", "sand"})
|
|
got := d.changed([]string{"sky", "SEA", "sand"})
|
|
if len(got) != 1 || got[0] != 1 {
|
|
t.Errorf("repainted %v, want only row 1", got)
|
|
}
|
|
}
|
|
|
|
func TestAnUnchangedFrameSendsNothing(t *testing.T) {
|
|
var d damage
|
|
rows := []string{"sky", "sea", "sand"}
|
|
d.changed(rows)
|
|
if got := d.changed(rows); len(got) != 0 {
|
|
t.Errorf("repainted %v on an identical frame, want nothing", got)
|
|
}
|
|
}
|
|
|
|
// The trap in every damage-tracked renderer: the screen is cleared or the
|
|
// window resized underneath the tracker, and it happily reports "nothing
|
|
// changed" onto rows that are now blank. Anything that touches the screen
|
|
// behind its back must reset it.
|
|
func TestResetForcesAFullRepaintEvenIfNothingChanged(t *testing.T) {
|
|
var d damage
|
|
rows := []string{"sky", "sea", "sand"}
|
|
d.changed(rows)
|
|
d.reset()
|
|
if got := d.changed(rows); len(got) != 3 {
|
|
t.Errorf("repainted %v after a reset, want all three rows", got)
|
|
}
|
|
}
|
|
|
|
func TestADifferentRowCountRepaintsEverything(t *testing.T) {
|
|
var d damage
|
|
d.changed([]string{"sky", "sea", "sand"})
|
|
got := d.changed([]string{"sky", "sea", "sand", "more"})
|
|
if len(got) != 4 {
|
|
t.Errorf("repainted %v when the row count changed, want all four", got)
|
|
}
|
|
}
|
|
|
|
// Damage tracking has one failure mode that never heals: if a cell on screen
|
|
// stops matching what the tracker believes is there -- anything at all wrote
|
|
// over it -- that row is skipped for as long as its content does not change,
|
|
// and the wrong pixels stay wrong. The sky and the beach can sit unchanged for
|
|
// minutes at a time, so "until it changes" can mean "forever".
|
|
//
|
|
// So the tracker forgets everything periodically and repaints in full.
|
|
func TestDamageForgetsPeriodicallySoStaleCellsHeal(t *testing.T) {
|
|
var d damage
|
|
rows := []string{"sky", "sea", "sand"}
|
|
full := 0
|
|
for i := 0; i < 200; i++ {
|
|
if len(d.changed(rows)) == len(rows) {
|
|
full++
|
|
}
|
|
}
|
|
if full < 2 {
|
|
t.Errorf("in 200 identical frames the tracker repainted in full %d times: stale cells would never heal", full)
|
|
}
|
|
if full > 20 {
|
|
t.Errorf("repainted in full %d times in 200 frames: that is most of what damage tracking was meant to save", full)
|
|
}
|
|
}
|