internal/ui: refactoring: remove unnecessary hack for unfocusing

The sleeping for an unfocused state also happens in (*userInterfaceImpl).update().

Updates #982
Updates #987
This commit is contained in:
Hajime Hoshi 2022-12-30 00:41:43 +09:00
parent 7e7deeab22
commit 3f753b7086

View File

@ -1017,21 +1017,6 @@ func (u *userInterfaceImpl) loopGame() error {
} }
func (u *userInterfaceImpl) updateGame() error { func (u *userInterfaceImpl) updateGame() error {
var unfocused bool
// On Windows, the focusing state might be always false (#987).
// On Windows, even if a window is in another workspace, vsync seems to work.
// Then let's assume the window is always 'focused' as a workaround.
if runtime.GOOS != "windows" {
unfocused = u.window.GetAttrib(glfw.Focused) == glfw.False
}
var t1, t2 time.Time
if unfocused {
t1 = time.Now()
}
var outsideWidth, outsideHeight float64 var outsideWidth, outsideHeight float64
var deviceScaleFactor float64 var deviceScaleFactor float64
var err error var err error
@ -1053,20 +1038,6 @@ func (u *userInterfaceImpl) updateGame() error {
u.mainThread.Call(u.swapBuffers) u.mainThread.Call(u.swapBuffers)
} }
if unfocused {
t2 = time.Now()
}
// When a window is not focused, SwapBuffers might return immediately and CPU might be busy.
// Mitigate this by sleeping (#982).
if unfocused {
d := t2.Sub(t1)
const wait = time.Second / 60
if d < wait {
time.Sleep(wait - d)
}
}
return nil return nil
} }