mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
It was one frame in fifty, 4.2 seconds at the hosted rate, which is how long the blank top rows of his 2026-09-17 screenshot stayed on screen after an agent's clear. The Filter confines those clears now; this is the insurance for whatever else writes over the scape, at about 30 KB/s more output. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
55 lines
2.3 KiB
Go
55 lines
2.3 KiB
Go
package host
|
|
|
|
// damage tracks which of the scape's rows changed since the last frame, so a
|
|
// frame sends only what moved.
|
|
//
|
|
// Measured before it existed: a frame was ~30KB and at 20fps that is 0.6MB/s of
|
|
// fully-coloured cells, every one of them rewritten whether or not it had
|
|
// changed, into a terminal that is also rendering the agent. Most of a scape
|
|
// does not move between frames -- the sky sits still, the beach only changes
|
|
// when a line is written into it -- so most of that traffic was redundant.
|
|
//
|
|
// Row granularity rather than cell: a row is one string that Render already
|
|
// produced, comparing them is a string compare, and the rows that do move (the
|
|
// sea) move along their whole length anyway.
|
|
type damage struct {
|
|
prev []string
|
|
n int
|
|
}
|
|
|
|
// refreshEvery is how often the tracker forgets everything and repaints in
|
|
// full, in frames. At the hosted 12 fps that is one second.
|
|
//
|
|
// Damage tracking has one failure mode that never heals on its own: if anything
|
|
// writes over a cell the tracker believes it already painted, that row is
|
|
// skipped for as long as its content does not change -- and the sky and the
|
|
// beach can sit unchanged for minutes. A periodic full repaint makes every
|
|
// such fault temporary instead of permanent. It was one frame in fifty, 4.2
|
|
// seconds, which is how long the blank top rows of his 2026-09-17 screenshot
|
|
// stayed on screen after an agent's clear (the Filter confines those now;
|
|
// this is the insurance for whatever else writes over the scape). One frame
|
|
// in twelve costs about 30 KB/s more output and heals anything in a second.
|
|
const refreshEvery = 12
|
|
|
|
// changed returns the indices of the rows that need painting.
|
|
func (d *damage) changed(rows []string) []int {
|
|
d.n++
|
|
full := len(d.prev) != len(rows) || d.n%refreshEvery == 0
|
|
out := make([]int, 0, len(rows))
|
|
for i, r := range rows {
|
|
if full || d.prev[i] != r {
|
|
out = append(out, i)
|
|
}
|
|
}
|
|
d.prev = append(d.prev[:0:0], rows...)
|
|
return out
|
|
}
|
|
|
|
// reset forces the next frame to repaint everything.
|
|
//
|
|
// This is the whole safety of the thing. Anything that touches the screen
|
|
// behind the tracker's back -- a resize, a clear, re-establishing the band --
|
|
// leaves it believing rows are painted that are now blank, and it would
|
|
// cheerfully skip them forever.
|
|
func (d *damage) reset() { d.prev = nil }
|