Is your source available online somewhere?
I'm particularly interested in the following 2 lines and surrounding calls
1 2
| at com.astruyk.freetar.input.Gamepad.updateButtonStates(Gamepad.java:123) at com.astruyk.freetar.input.GamepadPoller.startPolling(GamepadPoller.java:91) |
The full source isn't available at the moment anywhere, but here's the code you are interested in:
1 2 3 4 5 6 7 8 9
| public synchronized void startPolling() { gamepad.poll(); pressedLastUpdate.clear(); for(Button currentButton : gamepad.getButtons()){ pressedLastUpdate.put(currentButton, currentButton.isPressed()); } pollTimer.start(); } |
Last night I refactored the gamepad.updateButtonStates() to gamepad.poll() to more closely match its intended functionality - so here's the source for the gamepad.poll()
1 2 3
| public void poll(){ controller.poll(); } |
Gamepad contains its own Controller Class - and also an array of Button objects associated with the gamepad.
Button is basically a wrapper for Component, with a couple subclasses so that I can handle analog and HAT-switch input as button presses rather than true-analog inputs. I had to create these classes so I could handle analog stick movements as button presses simply by calling .isPressed() rather than doing a bunch of checks each time for the type of Component I'm working with....
I'm not sure if you need it, but here's the code that the Timer calls when it is activated. It is in the GamepadPoller class (the class in charge of repeatedly polling the controller and generating events after button updates). This code is called by the Timer each time it runs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public synchronized void pollController() { gamepad.poll(); for (Button currentButton : pressedLastUpdate.keySet()) { if (pressedLastUpdate.get(currentButton) != currentButton.isPressed()) { ButtonEvent.EventType eventType = null; if (currentButton.isPressed()){ eventType = ButtonEvent.EventType.BUTTON_PRESSED; }else{ eventType = ButtonEvent.EventType.BUTTON_RELEASED; } ButtonEvent evt = new ButtonEvent( gamepad, currentButton, eventType); for(GamepadButtonListener observer : observers){ observer.buttonActionTriggered(evt); } pressedLastUpdate.put(currentButton, currentButton.isPressed()); } } } |
As you can see, the ControllerPoller contains a Map<Button, Boolean> (pressedLastUpdate) that stores the state of the button at the last call to pollController() - so that it can tell when the button state has changed.
If this isn't enough code for you to figure out whats going on, I can send you a copy of the relevant code from my input package...