mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
clock: Add comments
This commit is contained in:
parent
1e33cbb66f
commit
d8c0d88960
@ -99,13 +99,12 @@ func Update() int {
|
|||||||
lastSystemTime = n
|
lastSystemTime = n
|
||||||
}
|
}
|
||||||
|
|
||||||
t := n - lastSystemTime
|
diff := n - lastSystemTime
|
||||||
if t < 0 {
|
if diff < 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
syncWithSystemClock := false
|
syncWithSystemClock := false
|
||||||
|
|
||||||
if audioTimeInFrames > 0 && lastAudioTimeInFrames != audioTimeInFrames {
|
if audioTimeInFrames > 0 && lastAudioTimeInFrames != audioTimeInFrames {
|
||||||
@ -120,22 +119,24 @@ func Update() int {
|
|||||||
syncWithSystemClock = true
|
syncWithSystemClock = true
|
||||||
} else {
|
} else {
|
||||||
// Use system clock when the audio clock is not updated yet.
|
// Use system clock when the audio clock is not updated yet.
|
||||||
// As the audio clock can be updated discountinuously, the system clock is still needed.
|
// As the audio clock can be updated discountinuously,
|
||||||
|
// the system clock is still needed.
|
||||||
|
|
||||||
if t > 5*int64(time.Second)/FPS {
|
if diff > 5*int64(time.Second)/FPS {
|
||||||
// The previous time is too old.
|
// The previous time is too old.
|
||||||
// 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(t * FPS / int64(time.Second))
|
count = int(diff * FPS / int64(time.Second))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stabilize FPS.
|
// Stabilize FPS.
|
||||||
if count == 0 && (int64(time.Second)/FPS/2) < t {
|
// Without this adjustment, count can be unstable like 0, 2, 0, 2, ...
|
||||||
|
if count == 0 && (int64(time.Second)/FPS/2) < diff {
|
||||||
count = 1
|
count = 1
|
||||||
}
|
}
|
||||||
if count == 2 && (int64(time.Second)/FPS*3/2) > t {
|
if count == 2 && (int64(time.Second)/FPS*3/2) > diff {
|
||||||
count = 1
|
count = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user