From 0adbfaa57382b2c47e1a01460d095e96d3c2f6cd Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sun, 22 Mar 2020 22:12:20 +0000 Subject: [PATCH] Remove the -win-x and -win-y options for the ordoor binary --- cmd/view-map/main.go | 5 ++++- cmd/view-menu/main.go | 5 ++++- cmd/view-minimap/main.go | 5 ++++- cmd/view-obj/main.go | 5 ++++- cmd/view-set/main.go | 5 ++++- internal/ui/window.go | 19 ++++++++++--------- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/cmd/view-map/main.go b/cmd/view-map/main.go index 7b68290..40da688 100644 --- a/cmd/view-map/main.go +++ b/cmd/view-map/main.go @@ -17,6 +17,9 @@ import ( var ( gamePath = flag.String("game-path", "./orig", "Path to a WH40K: Chaos Gate installation") gameMap = flag.String("map", "", "Name of a map, e.g., Chapter01") + + winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension") + winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension") ) type env struct { @@ -69,7 +72,7 @@ func main() { lastState: state, } - win, err := ui.NewWindow(env, "View Map "+*gameMap) + win, err := ui.NewWindow(env, "View Map "+*gameMap, *winX, *winY) if err != nil { log.Fatal("Couldn't create window: %v", err) } diff --git a/cmd/view-menu/main.go b/cmd/view-menu/main.go index 588c315..cef7aba 100644 --- a/cmd/view-menu/main.go +++ b/cmd/view-menu/main.go @@ -12,6 +12,9 @@ import ( var ( gamePath = flag.String("game-path", "./orig", "Path to a WH40K: Chaos Gate installation") menuName = flag.String("menu", "", "Name of a menu, e.g. Main") + + winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension") + winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension") ) func main() { @@ -37,7 +40,7 @@ func main() { log.Fatalf("Couldn't initialize interface: %v", err) } - win, err := ui.NewWindow(iface, "View Menu: "+*menuName) + win, err := ui.NewWindow(iface, "View Menu: "+*menuName, *winX, *winY) if err != nil { log.Fatal("Couldn't create window: %v", err) } diff --git a/cmd/view-minimap/main.go b/cmd/view-minimap/main.go index 2052163..524ffd5 100644 --- a/cmd/view-minimap/main.go +++ b/cmd/view-minimap/main.go @@ -21,6 +21,9 @@ var ( gamePath = flag.String("game-path", "./orig", "Path to a WH40K: Chaos Gate installation") mapFile = flag.String("map", "", "Prefix path to a .map file, e.g. ./orig/Maps/Chapter01.MAP") txtFile = flag.String("txt", "", "Prefix path to a .txt file, e.g. ./orig/Maps/Chapter01.txt") + + winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension") + winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension") ) type env struct { @@ -71,7 +74,7 @@ func main() { } env := &env{gameMap: gameMap, set: mapSet, state: state, lastState: state} - win, err := ui.NewWindow(env, "View Map "+*mapFile) + win, err := ui.NewWindow(env, "View Map "+*mapFile, *winX, *winY) if err != nil { log.Fatal("Couldn't create window: %v", err) } diff --git a/cmd/view-obj/main.go b/cmd/view-obj/main.go index 670323e..eb5afbc 100644 --- a/cmd/view-obj/main.go +++ b/cmd/view-obj/main.go @@ -17,6 +17,9 @@ var ( gamePath = flag.String("game-path", "./orig", "Path to a WH40K: Chaos Gate installation") objFile = flag.String("obj-file", "", "Path of an .obj file, e.g. ./orig/Obj/TZEENTCH.OBJ") objName = flag.String("obj-name", "", "Name of an .obj file, e.g. TZEENTCH") + + winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension") + winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension") ) type env struct { @@ -68,7 +71,7 @@ func main() { lastState: state, } - win, err := ui.NewWindow(env, "View Object: "+*objName) + win, err := ui.NewWindow(env, "View Object: "+*objName, *winX, *winY) if err != nil { log.Fatal(err) } diff --git a/cmd/view-set/main.go b/cmd/view-set/main.go index f824a5d..784623c 100644 --- a/cmd/view-set/main.go +++ b/cmd/view-set/main.go @@ -16,6 +16,9 @@ import ( var ( gamePath = flag.String("game-path", "./orig", "Path to a WH40K: Chaos Gate installation") setName = flag.String("set", "", "Name of a set, e.g., map01") + + winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension") + winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension") ) type env struct { @@ -58,7 +61,7 @@ func main() { lastState: state, } - win, err := ui.NewWindow(env, "View Set: "+*setName) + win, err := ui.NewWindow(env, "View Set: "+*setName, *winX, *winY) if err != nil { log.Fatal("Couldn't create window: %v", err) } diff --git a/internal/ui/window.go b/internal/ui/window.go index e0ec5f3..cb6bd8b 100644 --- a/internal/ui/window.go +++ b/internal/ui/window.go @@ -19,11 +19,7 @@ type Game interface { var ( screenScale = flag.Float64("screen-scale", 1.0, "Scale the window by this factor") - - winX = flag.Int("win-x", 1280, "Pre-scaled window X dimension") - winY = flag.Int("win-y", 1024, "Pre-scaled window Y dimension") - - cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`") + cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`") ) type Window struct { @@ -36,12 +32,15 @@ type Window struct { debug bool firstRun bool + + xRes int + yRes int } // 0,0 is the *top left* of the window // // ebiten assumes a single window, so only call this once... -func NewWindow(game Game, title string) (*Window, error) { +func NewWindow(game Game, title string, xRes int, yRes int) (*Window, error) { ebiten.SetRunnableInBackground(true) return &Window{ @@ -50,6 +49,8 @@ func NewWindow(game Game, title string) (*Window, error) { debug: true, firstRun: true, game: game, + xRes: xRes, + yRes: yRes, }, nil } @@ -63,7 +64,7 @@ func (w *Window) OnMouseWheel(f func(x, y float64)) { } func (w *Window) Layout(_, _ int) (int, int) { - return *winX, *winY + return w.xRes, w.yRes } func (w *Window) Update(screen *ebiten.Image) error { @@ -120,7 +121,7 @@ func (w *Window) Run() error { defer pprof.StopCPUProfile() } - ebiten.SetWindowSize(int(float64(*winX)**screenScale), int(float64(*winY)**screenScale)) + ebiten.SetWindowSize(int(float64(w.xRes)*(*screenScale)), int(float64(w.yRes)*(*screenScale))) ebiten.SetWindowTitle(w.Title) - return ebiten.RunGame(w) // Native game resolution: 640x480 + return ebiten.RunGame(w) }