mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
ui: Use frame counter to update device scale
This commit is contained in:
parent
78f2946797
commit
fce82e1502
@ -52,6 +52,7 @@ type userInterface struct {
|
|||||||
vsync bool
|
vsync bool
|
||||||
|
|
||||||
deviceScale float64
|
deviceScale float64
|
||||||
|
frame int64
|
||||||
deviceScaleUpdated int64
|
deviceScaleUpdated int64
|
||||||
lastActualScale float64
|
lastActualScale float64
|
||||||
|
|
||||||
@ -544,14 +545,10 @@ func (u *userInterface) getScale() float64 {
|
|||||||
|
|
||||||
// actualScreenScale must be called from the main thread.
|
// actualScreenScale must be called from the main thread.
|
||||||
func (u *userInterface) actualScreenScale() float64 {
|
func (u *userInterface) actualScreenScale() float64 {
|
||||||
n := time.Now().UnixNano()
|
|
||||||
// As devicescale.DeviceScale accesses OS API, not call this too often.
|
// As devicescale.DeviceScale accesses OS API, not call this too often.
|
||||||
//
|
if u.deviceScale == 0 || u.frame-u.deviceScaleUpdated > 30 {
|
||||||
// TODO: This function might return different values in one frame. Instead of using time, can we use frames
|
|
||||||
// or tick?
|
|
||||||
if u.deviceScale == 0 || n-u.deviceScaleUpdated > int64(time.Second/4) {
|
|
||||||
u.deviceScale = devicescale.DeviceScale()
|
u.deviceScale = devicescale.DeviceScale()
|
||||||
u.deviceScaleUpdated = n
|
u.deviceScaleUpdated = u.frame
|
||||||
}
|
}
|
||||||
return u.getScale() * u.deviceScale
|
return u.getScale() * u.deviceScale
|
||||||
}
|
}
|
||||||
@ -643,6 +640,7 @@ func (u *userInterface) loop(g GraphicsContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
|
u.frame++
|
||||||
vsync := u.vsync
|
vsync := u.vsync
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user