internal/ui: refactoring

This commit is contained in:
Hajime Hoshi 2023-05-09 00:35:54 +09:00
parent 20edb04e5e
commit 0785502be3

View File

@ -92,6 +92,7 @@ type userInterfaceImpl struct {
initWindowFloating bool initWindowFloating bool
initWindowMaximized bool initWindowMaximized bool
// bufferOnceSwapped must be accessed from the main thread.
bufferOnceSwapped bool bufferOnceSwapped bool
origWindowPosX int origWindowPosX int
@ -113,6 +114,7 @@ type userInterfaceImpl struct {
glContextSetOnce sync.Once glContextSetOnce sync.Once
darwinInitOnce sync.Once darwinInitOnce sync.Once
bufferOnceSwappedOnce sync.Once
mainThread threadInterface mainThread threadInterface
renderThread threadInterface renderThread threadInterface
@ -1092,9 +1094,13 @@ func (u *userInterfaceImpl) updateGame() error {
// This works only for OpenGL. // This works only for OpenGL.
u.swapBuffersOnRenderThread() u.swapBuffersOnRenderThread()
})
u.bufferOnceSwappedOnce.Do(func() {
u.mainThread.Call(func() {
u.bufferOnceSwapped = true u.bufferOnceSwapped = true
}) })
})
if unfocused { if unfocused {
t2 = time.Now() t2 = time.Now()