internal/ui: merge init functions

The Go specification doesn't determine the order of init functions.
In order to reduce unexpected behavior, merge some init functions.
This commit is contained in:
Hajime Hoshi 2023-10-15 00:15:20 +09:00
parent 567e2fa04c
commit 2a8d8d71fc
2 changed files with 11 additions and 22 deletions

View File

@ -121,6 +121,9 @@ const (
)
func init() {
// Lock the main thread.
runtime.LockOSThread()
theUI.userInterfaceImpl = userInterfaceImpl{
runnableOnUnfocused: true,
minWindowWidthInDIP: glfw.DontCare,
@ -140,9 +143,7 @@ func init() {
savedCursorY: math.NaN(),
}
theUI.iwindow.ui = &theUI.userInterfaceImpl
}
func init() {
hideConsoleWindowOnWindows()
if err := initialize(); err != nil {
@ -869,11 +870,6 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
return f
}
func init() {
// Lock the main thread.
runtime.LockOSThread()
}
// createWindow creates a GLFW window.
//
// createWindow must be called from the main thread.

View File

@ -116,14 +116,6 @@ type userInterfaceImpl struct {
dropFileM sync.Mutex
}
func init() {
theUI.userInterfaceImpl = userInterfaceImpl{
runnableOnUnfocused: true,
savedCursorX: math.NaN(),
savedCursorY: math.NaN(),
}
}
var (
window = js.Global().Get("window")
document = js.Global().Get("document")
@ -133,14 +125,9 @@ var (
)
var (
documentHasFocus js.Value
documentHidden js.Value
)
func init() {
documentHasFocus = document.Get("hasFocus").Call("bind", document)
documentHidden = js.Global().Get("Object").Call("getOwnPropertyDescriptor", js.Global().Get("Document").Get("prototype"), "hidden").Get("get").Call("bind", document)
}
documentHidden = js.Global().Get("Object").Call("getOwnPropertyDescriptor", js.Global().Get("Document").Get("prototype"), "hidden").Get("get").Call("bind", document)
)
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
return window.Get("innerWidth").Int(), window.Get("innerHeight").Int()
@ -485,6 +472,12 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error {
}
func init() {
theUI.userInterfaceImpl = userInterfaceImpl{
runnableOnUnfocused: true,
savedCursorX: math.NaN(),
savedCursorY: math.NaN(),
}
// docuemnt is undefined on node.js
if !document.Truthy() {
return