mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
inpututil: Optimization
This commit is contained in:
parent
40e662d672
commit
2b77b57b75
@ -97,18 +97,24 @@ func (i *inputState) update() {
|
||||
// Gamepads
|
||||
|
||||
// Copy the gamepad IDs.
|
||||
i.prevGamepadIDs = map[ebiten.GamepadID]struct{}{}
|
||||
for id := range i.prevGamepadIDs {
|
||||
delete(i.prevGamepadIDs, id)
|
||||
}
|
||||
for id := range i.gamepadIDs {
|
||||
i.prevGamepadIDs[id] = struct{}{}
|
||||
}
|
||||
|
||||
// Copy the gamepad button durations.
|
||||
i.prevGamepadButtonDurations = map[ebiten.GamepadID][]int{}
|
||||
for id := range i.prevGamepadButtonDurations {
|
||||
delete(i.prevGamepadButtonDurations, id)
|
||||
}
|
||||
for id, ds := range i.gamepadButtonDurations {
|
||||
i.prevGamepadButtonDurations[id] = append([]int{}, ds...)
|
||||
}
|
||||
|
||||
i.gamepadIDs = map[ebiten.GamepadID]struct{}{}
|
||||
for id := range i.gamepadIDs {
|
||||
delete(i.gamepadIDs, id)
|
||||
}
|
||||
for _, id := range ebiten.GamepadIDs() {
|
||||
i.gamepadIDs[id] = struct{}{}
|
||||
if _, ok := i.gamepadButtonDurations[id]; !ok {
|
||||
@ -123,15 +129,11 @@ func (i *inputState) update() {
|
||||
}
|
||||
}
|
||||
}
|
||||
gamepadIDsToDelete := []ebiten.GamepadID{}
|
||||
for id := range i.gamepadButtonDurations {
|
||||
if _, ok := i.gamepadIDs[id]; !ok {
|
||||
gamepadIDsToDelete = append(gamepadIDsToDelete, id)
|
||||
}
|
||||
}
|
||||
for _, id := range gamepadIDsToDelete {
|
||||
delete(i.gamepadButtonDurations, id)
|
||||
}
|
||||
}
|
||||
|
||||
// Touches
|
||||
ids := map[ebiten.TouchID]struct{}{}
|
||||
|
Loading…
Reference in New Issue
Block a user