mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2025-12-06 08:01:59 +01:00
Made polling of absolute Components lazy to avoid performance problems with keyboards on mac os x
This commit is contained in:
parent
7716494aee
commit
1bfb2dc3c0
|
|
@ -52,6 +52,7 @@ public abstract class AbstractComponent implements Component {
|
|||
|
||||
private final Identifier id;
|
||||
|
||||
private boolean has_polled;
|
||||
private float value;
|
||||
private float event_value;
|
||||
|
||||
|
|
@ -98,9 +99,21 @@ public abstract class AbstractComponent implements Component {
|
|||
* @return 0.0f by default, can be overridden
|
||||
*/
|
||||
public final float getPollData() {
|
||||
if (!has_polled && !isRelative()) {
|
||||
has_polled = true;
|
||||
try {
|
||||
setPollData(poll());
|
||||
} catch (IOException e) {
|
||||
ControllerEnvironment.log("Failed to poll component: " + e);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
final void resetHasPolled() {
|
||||
has_polled = false;
|
||||
}
|
||||
|
||||
final void setPollData(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,8 +212,8 @@ public abstract class AbstractController implements Controller {
|
|||
if (component.isRelative()) {
|
||||
component.setPollData(0);
|
||||
} else {
|
||||
float value = component.poll();
|
||||
component.setPollData(value);
|
||||
// Let the component poll itself lazily
|
||||
component.resetHasPolled();
|
||||
}
|
||||
}
|
||||
while (getNextDeviceEvent(event)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue