mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-09-26 20:11:28 +08:00
ebiten: keep TouchID int by using a generics function
This commit is contained in:
4
input.go
4
input.go
@@ -348,7 +348,7 @@ func UpdateStandardGamepadLayoutMappings(mappings string) (bool, error) {
|
||||
}
|
||||
|
||||
// TouchID represents a touch's identifier.
|
||||
type TouchID = ui.TouchID
|
||||
type TouchID int
|
||||
|
||||
// AppendTouchIDs appends the current touch states to touches, and returns the extended buffer.
|
||||
// Giving a slice that already has enough capacity works efficiently.
|
||||
@@ -361,7 +361,7 @@ type TouchID = ui.TouchID
|
||||
//
|
||||
// AppendTouchIDs is concurrent-safe.
|
||||
func AppendTouchIDs(touches []TouchID) []TouchID {
|
||||
return inputstate.Get().AppendTouchIDs(touches)
|
||||
return inputstate.AppendTouchIDs(touches)
|
||||
}
|
||||
|
||||
// TouchIDs returns the current touch states.
|
||||
|
@@ -88,12 +88,12 @@ func (i *inputState) IsMouseButtonPressed(mouseButton ui.MouseButton) bool {
|
||||
return i.state.MouseButtonPressed[mouseButton]
|
||||
}
|
||||
|
||||
func (i *inputState) AppendTouchIDs(touches []ui.TouchID) []ui.TouchID {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
func AppendTouchIDs[T ~int](touches []T) []T {
|
||||
theInputState.m.Lock()
|
||||
defer theInputState.m.Unlock()
|
||||
|
||||
for _, t := range i.state.Touches {
|
||||
touches = append(touches, ui.TouchID(t.ID))
|
||||
for _, t := range theInputState.state.Touches {
|
||||
touches = append(touches, T(t.ID))
|
||||
}
|
||||
return touches
|
||||
}
|
||||
|
Reference in New Issue
Block a user