Skip to content

Commit 27dc298

Browse files
authored
Merge pull request #35 from HypGamesOrlando/polling_alloc_fix
Fix to remove a per-frame allocation causing garbage collects
2 parents f6e46ef + f8de5da commit 27dc298

File tree

1 file changed

+7
-4
lines changed
  • plug-ins/Apple.GameController/Apple.GameController_Unity/Assets/Apple.GameController/Source/Controller

1 file changed

+7
-4
lines changed

plug-ins/Apple.GameController/Apple.GameController_Unity/Assets/Apple.GameController/Source/Controller/GCController.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ public GCBatteryState GetBatteryState()
175175

176176
public void Poll()
177177
{
178-
_previousButtonPressStates = new Dictionary<GCControllerInputName, bool>(_buttonPressStates);
179-
foreach (var key in _buttonPressStates.Keys.ToList())
178+
_previousButtonPressStates.Clear();
179+
foreach (var kv in _buttonPressStates)
180180
{
181-
_buttonPressStates[key] = false;
181+
_previousButtonPressStates.Add(kv.Key, kv.Value);
182+
_buttonPressStates[kv.Key] = false;
183+
182184
}
183185

184186
InputState = IsConnected ? GCControllerService.PollController(Handle) : GCControllerInputState.None;
@@ -191,4 +193,5 @@ public void SetLightColor(float red, float green, float blue)
191193
GCControllerService.SetControllerLightColor(Handle, red, green, blue);
192194
}
193195
}
194-
}
196+
}
197+

0 commit comments

Comments
 (0)