Skip to content

Commit

Permalink
use IntFloatMap provided by libgdx instead of running a custom solution
Browse files Browse the repository at this point in the history
  • Loading branch information
klianc09 committed Jun 24, 2023
1 parent 6c8eed0 commit 114d6a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.controllers.ControllerListener;
import com.badlogic.gdx.controllers.ControllerMapping;
import com.badlogic.gdx.controllers.ControllerPowerLevel;
import com.badlogic.gdx.utils.IntFloatMap;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.Logger;
import com.badlogic.gdx.utils.TimeUtils;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class JamepadController implements Controller {

private final CompositeControllerListener compositeControllerListener = new CompositeControllerListener();
private final IntMap<Boolean> buttonState = new IntMap<>();
private final IntMap<FloatWrapper> axisState = new IntMap<>();
private final IntFloatMap axisState = new IntFloatMap();
private final String uuid;
private final String name;
private ControllerIndex controllerIndex;
Expand Down Expand Up @@ -134,14 +135,13 @@ private void updateAxisState() {
int id = axis.ordinal();

float value = getAxis(id);
FloatWrapper axisValueWrapper = axisState.get(id);
if (value != axisValueWrapper.value) {
if (value != axisState.get(id, 0)) {
if (logger.getLevel() == Logger.DEBUG) {
logger.debug("Axis [" + id + " - " + toAxis(id) + "] moved [" + value + "]");
}
compositeControllerListener.axisMoved(this, id, value);
}
axisValueWrapper.value = value;
axisState.put(id, value);
}
}

Expand All @@ -167,7 +167,7 @@ private void updateButtonsState() {

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

for (ControllerButton button : ControllerButton.values()) {
Expand Down

0 comments on commit 114d6a5

Please sign in to comment.