Skip to content

Commit

Permalink
add comment to explain why these constants were introduced
Browse files Browse the repository at this point in the history
also use the constants instead of ControllerButton.values() consistently throughout the file
  • Loading branch information
klianc09 committed Dec 13, 2023
1 parent 114d6a5 commit 8072235
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ public class JamepadController implements Controller {
private static final IntMap<ControllerButton> CODE_TO_BUTTON = new IntMap<>(ControllerButton.values().length);
private static final IntMap<ControllerAxis> CODE_TO_AXIS = new IntMap<>(ControllerAxis.values().length);
private static final Logger logger = new Logger(JamepadController.class.getSimpleName());
// ControllerButton.values() and ControllerAxis.values() is cached once, to avoid producing garbage every frame
private static final ControllerButton[] CONTROLLER_BUTTON_VALUES = ControllerButton.values();
private static final ControllerAxis[] CONTROLLER_AXIS_VALUES = ControllerAxis.values();

static {
for (ControllerButton button : ControllerButton.values()) {
for (ControllerButton button : CONTROLLER_BUTTON_VALUES) {
CODE_TO_BUTTON.put(button.ordinal(), button);
}

for (ControllerAxis axis : ControllerAxis.values()) {
for (ControllerAxis axis : CONTROLLER_AXIS_VALUES) {
CODE_TO_AXIS.put(axis.ordinal(), axis);
}
}
Expand Down Expand Up @@ -166,11 +167,11 @@ private void updateButtonsState() {
}

private void initializeState() {
for (ControllerAxis axis : ControllerAxis.values()) {
for (ControllerAxis axis : CONTROLLER_AXIS_VALUES) {
axisState.put(axis.ordinal(), 0);
}

for (ControllerButton button : ControllerButton.values()) {
for (ControllerButton button : CONTROLLER_BUTTON_VALUES) {
buttonState.put(button.ordinal(), false);
}
}
Expand Down

0 comments on commit 8072235

Please sign in to comment.