mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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
|
gamepadButtonDurations map[ebiten.GamepadID][]int
|
||||||
prevGamepadButtonDurations map[ebiten.GamepadID][]int
|
prevGamepadButtonDurations map[ebiten.GamepadID][]int
|
||||||
|
|
||||||
|
touchIDs map[ebiten.TouchID]struct{}
|
||||||
touchDurations map[ebiten.TouchID]int
|
touchDurations map[ebiten.TouchID]int
|
||||||
prevTouchDurations map[ebiten.TouchID]int
|
prevTouchDurations map[ebiten.TouchID]int
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ var theInputState = &inputState{
|
|||||||
gamepadButtonDurations: map[ebiten.GamepadID][]int{},
|
gamepadButtonDurations: map[ebiten.GamepadID][]int{},
|
||||||
prevGamepadButtonDurations: map[ebiten.GamepadID][]int{},
|
prevGamepadButtonDurations: map[ebiten.GamepadID][]int{},
|
||||||
|
|
||||||
|
touchIDs: map[ebiten.TouchID]struct{}{},
|
||||||
touchDurations: map[ebiten.TouchID]int{},
|
touchDurations: map[ebiten.TouchID]int{},
|
||||||
prevTouchDurations: map[ebiten.TouchID]int{},
|
prevTouchDurations: map[ebiten.TouchID]int{},
|
||||||
}
|
}
|
||||||
@ -136,27 +138,27 @@ func (i *inputState) update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Touches
|
// Touches
|
||||||
ids := map[ebiten.TouchID]struct{}{}
|
|
||||||
|
|
||||||
// Copy the touch durations.
|
// Copy the touch durations.
|
||||||
i.prevTouchDurations = map[ebiten.TouchID]int{}
|
for id := range i.prevTouchDurations {
|
||||||
|
delete(i.prevTouchDurations, id)
|
||||||
|
}
|
||||||
for id := range i.touchDurations {
|
for id := range i.touchDurations {
|
||||||
i.prevTouchDurations[id] = i.touchDurations[id]
|
i.prevTouchDurations[id] = i.touchDurations[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for id := range i.touchIDs {
|
||||||
|
delete(i.touchIDs, id)
|
||||||
|
}
|
||||||
for _, id := range ebiten.TouchIDs() {
|
for _, id := range ebiten.TouchIDs() {
|
||||||
ids[id] = struct{}{}
|
i.touchIDs[id] = struct{}{}
|
||||||
i.touchDurations[id]++
|
i.touchDurations[id]++
|
||||||
}
|
}
|
||||||
touchIDsToDelete := []ebiten.TouchID{}
|
|
||||||
for id := range i.touchDurations {
|
for id := range i.touchDurations {
|
||||||
if _, ok := ids[id]; !ok {
|
if _, ok := i.touchIDs[id]; !ok {
|
||||||
touchIDsToDelete = append(touchIDsToDelete, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, id := range touchIDsToDelete {
|
|
||||||
delete(i.touchDurations, id)
|
delete(i.touchDurations, id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsKeyJustPressed returns a boolean value indicating
|
// IsKeyJustPressed returns a boolean value indicating
|
||||||
|
Loading…
Reference in New Issue
Block a user