From 88e6768a305ac5e4a44ea518bd2dd08e7517a4d0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 16 Jul 2018 04:36:47 +0900 Subject: [PATCH] Use the term 'TPS' ticks per second --- internal/clock/clock.go | 10 +++++----- run.go | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/clock/clock.go b/internal/clock/clock.go index 742c77c8c..10f5a3dc2 100644 --- a/internal/clock/clock.go +++ b/internal/clock/clock.go @@ -64,7 +64,7 @@ func updateFPS(now int64) { // Update updates the inner clock state and returns an integer value // indicating how many game frames the game should update. -func Update(logicFPS int) int { +func Update(tps int) int { m.Lock() defer m.Unlock() @@ -95,15 +95,15 @@ func Update(logicFPS int) int { // Let's force to sync the game time with the system clock. syncWithSystemClock = true } else { - count = int(diff * int64(logicFPS) / int64(time.Second)) + count = int(diff * int64(tps) / int64(time.Second)) } // Stabilize FPS. // Without this adjustment, count can be unstable like 0, 2, 0, 2, ... - if count == 0 && (int64(time.Second)/int64(logicFPS)/2) < diff { + if count == 0 && (int64(time.Second)/int64(tps)/2) < diff { count = 1 } - if count == 2 && (int64(time.Second)/int64(logicFPS)*3/2) > diff { + if count == 2 && (int64(time.Second)/int64(tps)*3/2) > diff { count = 1 } @@ -111,7 +111,7 @@ func Update(logicFPS int) int { if syncWithSystemClock { lastSystemTime = n } else { - lastSystemTime += int64(count) * int64(time.Second) / int64(logicFPS) + lastSystemTime += int64(count) * int64(time.Second) / int64(tps) } updateFPS(n) diff --git a/run.go b/run.go index d5b704546..fc2c2489e 100644 --- a/run.go +++ b/run.go @@ -30,13 +30,15 @@ import ( ) // FPS represents how many times game updating happens in a second (60). +// +// BUG: This actually represents TPS, not FPS. const FPS = 60 // CurrentFPS returns the current number of frames per second of rendering. // -// The returned value represents how many times rendering happens in a second and -// NOT how many times logical game updating (a passed function to Run) happens. -// Note that logical game updating is assured to happen 60 times in a second. +// The returned value FPS (frames per second) that represents how many times rendering happens in a +// second and NOT TPS (ticks per second) that represents how many times logical game updating (a +// passed function to Run) happens in a second. // // CurrentFPS is concurrent-safe. func CurrentFPS() float64 { @@ -250,8 +252,10 @@ func (i *imageDumper) update(screen *Image) error { // Run must be called from the OS main thread. // Note that Ebiten bounds the main goroutine to the main OS thread by runtime.LockOSThread. // -// The given function f is guaranteed to be called 60 times a second -// even if a rendering frame is skipped. +// Ebiten tries to call f 60 times a second. In other words, +// TPS (ticks per second) is 60. +// This is not related to framerate (display's frashrate). +// // f is not called when the window is in background by default. // This setting is configurable with SetRunnableInBackground. //