ebiten: keep TouchID int by using a generics function

This commit is contained in:
Hajime Hoshi
2025-09-21 18:48:41 +09:00
parent 6aa208e15e
commit 244510643c
2 changed files with 7 additions and 7 deletions

View File

@@ -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.

View File

@@ -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
}