mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-19 02:46:35 -05:00
make game update at 25fps, ui update at max fps (#389)
This commit is contained in:
parent
e81450b9d5
commit
95621a8262
23
main.go
23
main.go
@ -57,9 +57,10 @@ const (
|
||||
)
|
||||
|
||||
var singleton struct {
|
||||
lastTime float64
|
||||
showFPS bool
|
||||
timeScale float64
|
||||
lastTime float64
|
||||
lastScreenAdvance float64
|
||||
showFPS bool
|
||||
timeScale float64
|
||||
|
||||
captureState captureState
|
||||
capturePath string
|
||||
@ -99,6 +100,7 @@ func main() {
|
||||
func initialize() error {
|
||||
singleton.timeScale = 1.0
|
||||
singleton.lastTime = d2common.Now()
|
||||
singleton.lastScreenAdvance = singleton.lastTime
|
||||
|
||||
if err := d2config.Load(); err != nil {
|
||||
return err
|
||||
@ -210,7 +212,7 @@ func update(target d2render.Surface) error {
|
||||
elapsedTime := (currentTime - singleton.lastTime) * singleton.timeScale
|
||||
singleton.lastTime = currentTime
|
||||
|
||||
if err := advance(elapsedTime); err != nil {
|
||||
if err := advance(elapsedTime, currentTime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -225,9 +227,16 @@ func update(target d2render.Surface) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func advance(elapsed float64) error {
|
||||
if err := d2screen.Advance(elapsed); err != nil {
|
||||
return err
|
||||
const FPS_25 = 0.04 // 1/25
|
||||
|
||||
func advance(elapsed, current float64) error {
|
||||
elapsedLastScreenAdvance := (current - singleton.lastScreenAdvance) * singleton.timeScale
|
||||
|
||||
if elapsedLastScreenAdvance > FPS_25 {
|
||||
singleton.lastScreenAdvance = current
|
||||
if err := d2screen.Advance(elapsedLastScreenAdvance); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
d2ui.Advance(elapsed)
|
||||
|
Loading…
Reference in New Issue
Block a user