-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (74 loc) · 2.32 KB
/
Copy pathmain.go
File metadata and controls
98 lines (74 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"flag"
"log/slog"
"os"
"path"
"github.com/lord-server/panorama/internal/config"
"github.com/lord-server/panorama/internal/game"
"github.com/lord-server/panorama/internal/render"
"github.com/lord-server/panorama/internal/render/isometric"
"github.com/lord-server/panorama/internal/tile"
"github.com/lord-server/panorama/internal/web"
"github.com/lord-server/panorama/internal/world"
)
type Args struct {
ConfigPath string
}
var args Args
func fullrender(config config.Config) error {
descPath := path.Join(config.System.WorldPath, "nodes_dump.json")
slog.Info("loading game description", "game", config.System.GamePath, "mods", config.System.ModPath, "desc", descPath)
game, err := game.LoadGame(descPath, config.System.GamePath, config.System.ModPath)
if err != nil {
slog.Error("unable to load game description", "error", err)
return err
}
backend, err := world.NewPostgresBackend(config.System.WorldDSN)
if err != nil {
slog.Error("unable to connect to world DB", "error", err)
return err
}
world := world.NewWorldWithBackend(backend)
tiler := tile.NewTiler(config.Region, config.Renderer.ZoomLevels, config.System.TilesPath)
slog.Info("performing a full render", "workers", config.Renderer.Workers, "region", config.Region)
tiler.FullRender(&game, &world, config.Renderer.Workers, config.Region, func() render.Renderer {
return isometric.NewRenderer(config.Region, &game)
})
tiler.DownscaleTiles()
return nil
}
func run(config config.Config) error {
quit := make(chan bool)
slog.Info("starting web server", "address", config.Web.ListenAddress)
go func() {
web.Serve(&config)
quit <- true
}()
<-quit
return nil
}
func main() {
if len(os.Args) < 2 {
slog.Error("expected a subcommand: (available subcommands: run, fullrender)")
os.Exit(1)
}
subcommand := os.Args[1]
commonFlags := flag.NewFlagSet("common flags", flag.ExitOnError)
commonFlags.StringVar(&args.ConfigPath, "config", "config.toml", "Path to config file")
commonFlags.Parse(os.Args[2:])
slog.Info("loading config", "config_path", args.ConfigPath)
config, err := config.LoadConfig(args.ConfigPath)
if err != nil {
slog.Error("unable to load config", "error", err)
}
switch subcommand {
case "run":
err = run(config)
case "fullrender":
err = fullrender(config)
}
if err != nil {
os.Exit(1)
}
}