diff --git a/cmd/panorama/main.go b/cmd/panorama/main.go index 22b0092..dbe8bbc 100644 --- a/cmd/panorama/main.go +++ b/cmd/panorama/main.go @@ -8,7 +8,6 @@ import ( "github.com/alexflint/go-arg" "github.com/lord-server/panorama/internal/config" "github.com/lord-server/panorama/internal/game" - "github.com/lord-server/panorama/internal/generator" "github.com/lord-server/panorama/internal/generator/flat" "github.com/lord-server/panorama/internal/generator/tile" "github.com/lord-server/panorama/internal/server" @@ -83,7 +82,7 @@ func fullrender(config config.Config) error { slog.Info("performing a full render", "workers", config.Renderer.Workers, "region", config.Region) - tiler.FullRender(&game, &wd, config.Renderer.Workers, config.Region, func() generator.Renderer { + tiler.FullRender(&game, &wd, config.Renderer.Workers, config.Region, func() tile.Renderer { return flat.NewRenderer(config.Region, &game) }) diff --git a/internal/generator/flat/renderer.go b/internal/generator/flat/renderer.go index f294d7c..7ac4ae8 100644 --- a/internal/generator/flat/renderer.go +++ b/internal/generator/flat/renderer.go @@ -5,8 +5,8 @@ import ( "log/slog" "github.com/lord-server/panorama/internal/game" - "github.com/lord-server/panorama/internal/generator" "github.com/lord-server/panorama/internal/generator/rasterizer" + "github.com/lord-server/panorama/internal/generator/tile" "github.com/lord-server/panorama/internal/world" "github.com/lord-server/panorama/pkg/geom" "github.com/lord-server/panorama/pkg/lm" @@ -28,7 +28,7 @@ func NewRenderer(region geom.Region, game *game.Game) *FlatRenderer { } func (r *FlatRenderer) RenderTile( - tilePos generator.TilePosition, + tilePos tile.TilePosition, wd *world.World, game *game.Game, ) *rasterizer.RenderBuffer { diff --git a/internal/generator/isometric/renderer.go b/internal/generator/isometric/renderer.go index 6027fb1..c902f98 100644 --- a/internal/generator/isometric/renderer.go +++ b/internal/generator/isometric/renderer.go @@ -5,10 +5,10 @@ import ( "math" "github.com/lord-server/panorama/internal/game" - "github.com/lord-server/panorama/internal/generator" "github.com/lord-server/panorama/internal/generator/light" "github.com/lord-server/panorama/internal/generator/nn" "github.com/lord-server/panorama/internal/generator/rasterizer" + "github.com/lord-server/panorama/internal/generator/tile" "github.com/lord-server/panorama/internal/world" "github.com/lord-server/panorama/pkg/geom" "github.com/lord-server/panorama/pkg/lm" @@ -160,7 +160,7 @@ func (r *IsometricRenderer) renderBlock( } func (r *IsometricRenderer) RenderTile( - tilePos generator.TilePosition, + tilePos tile.TilePosition, world *world.World, game *game.Game, ) *rasterizer.RenderBuffer { diff --git a/internal/generator/renderer.go b/internal/generator/renderer.go index 84fc283..cc1b290 100644 --- a/internal/generator/renderer.go +++ b/internal/generator/renderer.go @@ -1,19 +1 @@ package generator - -import ( - "github.com/lord-server/panorama/internal/game" - "github.com/lord-server/panorama/internal/generator/rasterizer" - "github.com/lord-server/panorama/internal/world" - "github.com/lord-server/panorama/pkg/geom" -) - -type TilePosition struct { - X, Y int -} - -type Renderer interface { - RenderTile(pos TilePosition, w *world.World, game *game.Game) *rasterizer.RenderBuffer - ProjectRegion(region geom.Region) geom.ProjectedRegion - // ListTilesWithBlock(x, y, z int) []TilePosition - // ListTilesInsideRegion(region config.Region) []TilePosition -} diff --git a/internal/generator/tile/downscale.go b/internal/generator/tile/downscale.go index 8eda422..6d4e0ae 100644 --- a/internal/generator/tile/downscale.go +++ b/internal/generator/tile/downscale.go @@ -8,12 +8,11 @@ import ( "github.com/nfnt/resize" - "github.com/lord-server/panorama/internal/generator" "github.com/lord-server/panorama/pkg/imageutil" "github.com/lord-server/panorama/pkg/lm" ) -func uniquePositions(input []generator.TilePosition) []generator.TilePosition { +func uniquePositions(input []TilePosition) []TilePosition { // Slices with zero or one element always contain unique elements if len(input) < 2 { return input @@ -58,10 +57,10 @@ func uniquePositions(input []generator.TilePosition) []generator.TilePosition { } // downscalePositions produces downscaled images for given zoom level and returns a list of produced tile positions -func (t *Tiler) downscalePositions(zoom int, positions []generator.TilePosition) []generator.TilePosition { +func (t *Tiler) downscalePositions(zoom int, positions []TilePosition) []TilePosition { const quadrantSize = 128 - var nextPositions []generator.TilePosition + var nextPositions []TilePosition for _, pos := range positions { target := image.NewNRGBA(image.Rect(0, 0, 256, 256)) @@ -88,7 +87,7 @@ func (t *Tiler) downscalePositions(zoom int, positions []generator.TilePosition) slog.Error("unable to save image", "err", err, "path", imagePath) } - nextPositions = append(nextPositions, generator.TilePosition{ + nextPositions = append(nextPositions, TilePosition{ X: lm.FloorDiv(pos.X, 2), Y: lm.FloorDiv(pos.Y, 2), }) diff --git a/internal/generator/tile/tiler.go b/internal/generator/tile/tiler.go index 5c541a6..2a52be6 100644 --- a/internal/generator/tile/tiler.go +++ b/internal/generator/tile/tiler.go @@ -12,13 +12,22 @@ import ( "sync" "github.com/lord-server/panorama/internal/game" - "github.com/lord-server/panorama/internal/generator" + "github.com/lord-server/panorama/internal/generator/rasterizer" "github.com/lord-server/panorama/internal/world" "github.com/lord-server/panorama/pkg/geom" "github.com/lord-server/panorama/pkg/imageutil" "github.com/lord-server/panorama/pkg/lm" ) +type TilePosition struct { + X, Y int +} + +type Renderer interface { + RenderTile(pos TilePosition, w *world.World, game *game.Game) *rasterizer.RenderBuffer + ProjectRegion(region geom.Region) geom.ProjectedRegion +} + type Tiler struct { region geom.Region zoomLevels int @@ -37,7 +46,7 @@ func (t *Tiler) tilePath(x, y, zoom int) string { return fmt.Sprintf("%v/%v/%v/%v.png", t.tilesPath, -zoom, x, y) } -func (t *Tiler) worker(wg *sync.WaitGroup, game *game.Game, world *world.World, renderer generator.Renderer, positions <-chan generator.TilePosition) { +func (t *Tiler) worker(wg *sync.WaitGroup, game *game.Game, world *world.World, renderer Renderer, positions <-chan TilePosition) { for position := range positions { output := renderer.RenderTile(position, world, game) // Don't save empty tiles @@ -58,12 +67,12 @@ func (t *Tiler) worker(wg *sync.WaitGroup, game *game.Game, world *world.World, wg.Done() } -type CreateRendererFunc func() generator.Renderer +type CreateRendererFunc func() Renderer func (t *Tiler) FullRender(game *game.Game, world *world.World, workers int, region geom.Region, createRenderer CreateRendererFunc) { var wg sync.WaitGroup - positions := make(chan generator.TilePosition) + positions := make(chan TilePosition) projectedRegion := geom.ProjectedRegion{} for i := 0; i < workers; i++ { @@ -82,7 +91,7 @@ func (t *Tiler) FullRender(game *game.Game, world *world.World, workers int, reg } for y := projectedRegion.YBounds.Min; y < projectedRegion.YBounds.Max; y++ { - positions <- generator.TilePosition{X: x, Y: y} + positions <- TilePosition{X: x, Y: y} } } @@ -101,7 +110,7 @@ func (t *Tiler) DownscaleTiles() { } // Collect tile positions - var positions []generator.TilePosition + var positions []TilePosition err = filepath.WalkDir(tileDir, func(path string, d fs.DirEntry, _ error) error { if d == nil || d.IsDir() { @@ -124,7 +133,7 @@ func (t *Tiler) DownscaleTiles() { return nil } - positions = append(positions, generator.TilePosition{ + positions = append(positions, TilePosition{ X: lm.FloorDiv(x, 2), Y: lm.FloorDiv(y, 2), })