apply worl loading ui

This commit is contained in:
IliaDenisov
2026-03-08 09:05:00 +02:00
parent c076347d70
commit 672e4a00b4
5 changed files with 77 additions and 66 deletions
+7 -15
View File
@@ -4,8 +4,6 @@ import (
"image"
"fyne.io/fyne/v2"
// adjust import path to your world package
// "your/module/world"
"github.com/fogleman/gg"
"github.com/iliadenisov/galaxy/client/world"
)
@@ -30,6 +28,10 @@ This adapter enforces:
- IndexOnViewportChange is called when viewport sizes changed (you can also include zoom if desired)
*/
var (
blankImage = image.NewRGBA(image.Rect(0, 0, 0, 0))
)
// FyneExecutor posts functions onto the Fyne UI thread.
type FyneExecutor struct{}
@@ -76,25 +78,15 @@ func (e *editor) RequestRefresh() {
// draw is the raster callback. It must be cheap and must not block on multiple re-renders.
// It delegates coalescing + rendering decision to RasterCoalescer.
func (e *editor) draw(wPx, hPx int) image.Image {
// Snapshot latest params and render once.
// e.mu.RLock()
// p := e.wp
// e.mu.RUnlock()
// Request() already scheduled refreshes; Draw() actually renders for this callback.
// We bypass co.Draw(w,h) because we need to pass our snapshot to coalescer in a controlled way.
// The simplest pattern: keep coalescer as the sole driver: call co.Draw(w,h) here.
// But then coalescer uses its internal latest. So make sure we always call co.Request on updates.
//
// In normal operation you can just: return e.co.Draw(wPx,hPx)
// and never use p above. We'll do that to keep a single source of truth.
// _ = p
return e.co.Draw(wPx, hPx)
}
// renderRasterImage renders the expanded canvas into the GGDrawer backing image,
// then copies only the viewport ROI into a reusable viewport buffer and returns it.
func (e *editor) renderRasterImage(viewportW, viewportH int, p world.RenderParams) image.Image {
if e.world == nil {
return blankImage
}
// 1) Viewport sizes come from raster draw callback.
p.ViewportWidthPx = viewportW
p.ViewportHeightPx = viewportH