client refactor

This commit is contained in:
Ilia Denisov
2026-03-09 13:26:17 +02:00
committed by GitHub
parent ac35360d60
commit bb2bb899de
10 changed files with 339 additions and 295 deletions
-32
View File
@@ -3,38 +3,6 @@ package client
/*
Fyne-friendly latest-wins coalescing for canvas.NewRaster(draw func(w,h int) image.Image).
How to use (integration sketch):
type editor struct {
w *world.World
drawer world.PrimitiveDrawer // wraps gg.Context over a backing *image.RGBA
raster *canvas.Raster
co *client.RasterCoalescer[world.RenderParams]
}
func (e *editor) initCoalescer() {
exec := client.FyneMainThreadExecutor{} // uses fyne.CurrentApp().Driver().RunOnMain
e.co = client.NewRasterCoalescer(exec, e.raster, func(wPx, hPx int, p world.RenderParams) image.Image {
// your existing draw pipeline:
// 1) ensure viewport/margins inside p are consistent with wPx/hPx if needed
// 2) call e.w.Render(e.drawer, p)
// 3) get image from gg.Context, crop margins, return
_ = e.w.Render(e.drawer, p)
return e.drawerImageCropped() // your code
})
}
// Call from input handlers (pan/zoom/etc). Can be from any goroutine.
func (e *editor) RefreshUI(p world.RenderParams) {
e.co.Request(p) // schedules raster.Refresh() on UI thread
}
// Raster draw callback:
func (e *editor) draw(wPx, hPx int) image.Image {
return e.co.Draw(wPx, hPx)
}
Key property:
- draw() renders at most once per invocation (never loops).
- if new requests arrived while drawing, we schedule exactly one extra Refresh.