diff --git a/core/Engine.go b/core/Engine.go index e8efe2d9..84762be6 100644 --- a/core/Engine.go +++ b/core/Engine.go @@ -5,6 +5,7 @@ import ( "math" "path" "runtime" + "strconv" "strings" "sync" "time" @@ -21,6 +22,8 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/ui" "github.com/hajimehoshi/ebiten" + "github.com/hajimehoshi/ebiten/ebitenutil" + "github.com/hajimehoshi/ebiten/inpututil" ) // Engine is the core OpenDiablo2 engine @@ -39,6 +42,7 @@ type Engine struct { nextScene scenes.Scene // The next scene to be loaded at the end of the game loop fullscreenKey bool // When true, the fullscreen toggle is still being pressed lastTime float64 // Last time we updated the scene + showFPS bool } // CreateEngine creates and instance of the OpenDiablo2 engine @@ -173,6 +177,14 @@ func (v *Engine) Update() { v.fullscreenKey = false } + if inpututil.IsKeyJustPressed(ebiten.KeyF6) { + v.showFPS = !v.showFPS + } + + if inpututil.IsKeyJustPressed(ebiten.KeyF8) { + ebiten.SetVsyncEnabled(!ebiten.IsVsyncEnabled()) + } + v.updateScene() if v.CurrentScene == nil { log.Fatal("no scene loaded") @@ -203,6 +215,9 @@ func (v *Engine) Draw(screen *ebiten.Image) { v.CurrentScene.Render(screen) v.UIManager.Draw(screen) } + if v.showFPS == true { + ebitenutil.DebugPrintAt(screen, "vsync:"+strconv.FormatBool(ebiten.IsVsyncEnabled())+"\nFPS:"+strconv.Itoa(int(ebiten.CurrentFPS())), 5, 565) + } } // SetNextScene tells the engine what scene to load on the next update cycle diff --git a/main.go b/main.go index f0490f82..0313b400 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "image" "log" - "strconv" "github.com/hajimehoshi/ebiten/ebitenutil" @@ -53,6 +52,5 @@ func update(screen *ebiten.Image) error { return nil } d2Engine.Draw(screen) - ebitenutil.DebugPrintAt(screen, "vsync:"+strconv.FormatBool(ebiten.IsVsyncEnabled())+"\nFPS:"+strconv.Itoa(int(ebiten.CurrentFPS())), 5, 565) return nil } diff --git a/scenes/MapEngineTest.go b/scenes/MapEngineTest.go index 4aee7c98..5c851f05 100644 --- a/scenes/MapEngineTest.go +++ b/scenes/MapEngineTest.go @@ -91,13 +91,6 @@ func (v *MapEngineTest) Render(screen *ebiten.Image) { } func (v *MapEngineTest) Update(tickTime float64) { - if v.uiManager.KeyPressed(ebiten.KeyF8) { - if ebiten.IsVsyncEnabled() == true { - ebiten.SetVsyncEnabled(false) - } else { - ebiten.SetVsyncEnabled(true) - } - } if v.uiManager.KeyPressed(ebiten.KeyDown) { v.mapEngine.OffsetY -= tickTime * 800 }