mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
inpututil: Remove map/slice allocations in update
This commit is contained in:
parent
da71840106
commit
b859db02e5
@ -36,6 +36,7 @@ type inputState struct {
|
||||
gamepadButtonDurations map[ebiten.GamepadID][]int
|
||||
prevGamepadButtonDurations map[ebiten.GamepadID][]int
|
||||
|
||||
touchIDs map[ebiten.TouchID]struct{}
|
||||
touchDurations map[ebiten.TouchID]int
|
||||
prevTouchDurations map[ebiten.TouchID]int
|
||||
|
||||
@ -55,6 +56,7 @@ var theInputState = &inputState{
|
||||
gamepadButtonDurations: map[ebiten.GamepadID][]int{},
|
||||
prevGamepadButtonDurations: map[ebiten.GamepadID][]int{},
|
||||
|
||||
touchIDs: map[ebiten.TouchID]struct{}{},
|
||||
touchDurations: map[ebiten.TouchID]int{},
|
||||
prevTouchDurations: map[ebiten.TouchID]int{},
|
||||
}
|
||||
@ -136,28 +138,28 @@ func (i *inputState) update() {
|
||||
}
|
||||
|
||||
// Touches
|
||||
ids := map[ebiten.TouchID]struct{}{}
|
||||
|
||||
// Copy the touch durations.
|
||||
i.prevTouchDurations = map[ebiten.TouchID]int{}
|
||||
for id := range i.prevTouchDurations {
|
||||
delete(i.prevTouchDurations, id)
|
||||
}
|
||||
for id := range i.touchDurations {
|
||||
i.prevTouchDurations[id] = i.touchDurations[id]
|
||||
}
|
||||
|
||||
for id := range i.touchIDs {
|
||||
delete(i.touchIDs, id)
|
||||
}
|
||||
for _, id := range ebiten.TouchIDs() {
|
||||
ids[id] = struct{}{}
|
||||
i.touchIDs[id] = struct{}{}
|
||||
i.touchDurations[id]++
|
||||
}
|
||||
touchIDsToDelete := []ebiten.TouchID{}
|
||||
for id := range i.touchDurations {
|
||||
if _, ok := ids[id]; !ok {
|
||||
touchIDsToDelete = append(touchIDsToDelete, id)
|
||||
}
|
||||
}
|
||||
for _, id := range touchIDsToDelete {
|
||||
if _, ok := i.touchIDs[id]; !ok {
|
||||
delete(i.touchDurations, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsKeyJustPressed returns a boolean value indicating
|
||||
// whether the given key is pressed just in the current frame.
|
||||
|
Loading…
Reference in New Issue
Block a user