Use the term 'TPS' ticks per second

This commit is contained in:
Hajime Hoshi 2018-07-16 04:36:47 +09:00
parent bbb777eecc
commit 88e6768a30
2 changed files with 14 additions and 10 deletions

View File

@ -64,7 +64,7 @@ func updateFPS(now int64) {
// Update updates the inner clock state and returns an integer value // Update updates the inner clock state and returns an integer value
// indicating how many game frames the game should update. // indicating how many game frames the game should update.
func Update(logicFPS int) int { func Update(tps int) int {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
@ -95,15 +95,15 @@ func Update(logicFPS int) int {
// Let's force to sync the game time with the system clock. // Let's force to sync the game time with the system clock.
syncWithSystemClock = true syncWithSystemClock = true
} else { } else {
count = int(diff * int64(logicFPS) / int64(time.Second)) count = int(diff * int64(tps) / int64(time.Second))
} }
// Stabilize FPS. // Stabilize FPS.
// Without this adjustment, count can be unstable like 0, 2, 0, 2, ... // 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 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 count = 1
} }
@ -111,7 +111,7 @@ func Update(logicFPS int) int {
if syncWithSystemClock { if syncWithSystemClock {
lastSystemTime = n lastSystemTime = n
} else { } else {
lastSystemTime += int64(count) * int64(time.Second) / int64(logicFPS) lastSystemTime += int64(count) * int64(time.Second) / int64(tps)
} }
updateFPS(n) updateFPS(n)

14
run.go
View File

@ -30,13 +30,15 @@ import (
) )
// FPS represents how many times game updating happens in a second (60). // FPS represents how many times game updating happens in a second (60).
//
// BUG: This actually represents TPS, not FPS.
const FPS = 60 const FPS = 60
// CurrentFPS returns the current number of frames per second of rendering. // CurrentFPS returns the current number of frames per second of rendering.
// //
// The returned value represents how many times rendering happens in a second and // The returned value FPS (frames per second) that represents how many times rendering happens in a
// NOT how many times logical game updating (a passed function to Run) happens. // second and NOT TPS (ticks per second) that represents how many times logical game updating (a
// Note that logical game updating is assured to happen 60 times in a second. // passed function to Run) happens in a second.
// //
// CurrentFPS is concurrent-safe. // CurrentFPS is concurrent-safe.
func CurrentFPS() float64 { func CurrentFPS() float64 {
@ -250,8 +252,10 @@ func (i *imageDumper) update(screen *Image) error {
// Run must be called from the OS main thread. // Run must be called from the OS main thread.
// Note that Ebiten bounds the main goroutine to the main OS thread by runtime.LockOSThread. // 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 // Ebiten tries to call f 60 times a second. In other words,
// even if a rendering frame is skipped. // 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. // f is not called when the window is in background by default.
// This setting is configurable with SetRunnableInBackground. // This setting is configurable with SetRunnableInBackground.
// //