mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
input: Use sync.Once
This commit is contained in:
parent
f5c68d2a61
commit
d56668bfdb
@ -30,7 +30,7 @@ import (
|
||||
type Input struct {
|
||||
keyPressed map[glfw.Key]bool
|
||||
mouseButtonPressed map[glfw.MouseButton]bool
|
||||
callbacksInitialized bool
|
||||
onceCallback sync.Once
|
||||
scrollX float64
|
||||
scrollY float64
|
||||
cursorX int
|
||||
@ -120,15 +120,14 @@ func (i *Input) Update(window *glfw.Window, scale float64) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
|
||||
if !i.callbacksInitialized {
|
||||
i.onceCallback.Do(func() {
|
||||
window.SetCharModsCallback(func(w *glfw.Window, char rune, mods glfw.ModifierKey) {
|
||||
i.appendRuneBuffer(char)
|
||||
})
|
||||
window.SetScrollCallback(func(w *glfw.Window, xoff float64, yoff float64) {
|
||||
i.setWheel(xoff, yoff)
|
||||
})
|
||||
i.callbacksInitialized = true
|
||||
}
|
||||
})
|
||||
if i.keyPressed == nil {
|
||||
i.keyPressed = map[glfw.Key]bool{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user