-
Hello! I'm sure questions regarding Ebiten's timing system have been asked many, many times before, but after seeing some odd FPS values when I've been testing my game, I have a question to ask. It seems like Here's an example of the behavior I'm seeing in the form of a simple program. package main
import (
"fmt"
"time"
"github.com/hajimehoshi/ebiten/v2"
)
type Game struct{}
func (g *Game) Update() error {
t := time.Now()
time.Sleep(time.Millisecond * 16)
fmt.Println("Update:", time.Since(t))
fmt.Println("FPS: ", ebiten.CurrentFPS())
fmt.Println("TPS: ", ebiten.CurrentTPS())
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {}
func (g *Game) Layout(w, h int) (int, int) {
return 320, 240
}
func main() {
game := &Game{}
ebiten.SetFPSMode(ebiten.FPSModeVsyncOffMaximum)
ebiten.SetMaxTPS(60)
ebiten.RunGame(game)
} With this simple example, I would expect that;
However, instead I get this output:
And can see that This seems to mean that if a Oddly, if I sleep for 17 milliseconds instead of 16, then FPS goes up:
This makes me feel like there might be either a timing issue of some sort, or an issue with EDIT: As an aside, I'm asking this because in my game, I'm seeing times where the FPS drops below the monitor's refresh rate while timing my game shows that the game's |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
So, responding to your expectations:
Finally, about FPS going up despite updates taking more time...
|
Beta Was this translation helpful? Give feedback.
So, responding to your expectations:
Update
, but it will always callDraw
after updates are done. See the GLFW main loop function at ui/context#L107. There's no conditional to callDraw
, no additional timing check there. After updating, Ebiten always makes the game draw.FPSModeVsyncOffMaximum
, the only difference is (as far as I understand) that draws / buffer swaps won't block. If the game is taking too much time onUpdate
, you can't callDraw
faster anyway, as the calls are not done concurrently. And in fact, depending on the exact moment at whichUpdate
calls end, yo…