aboutsummaryrefslogtreecommitdiffstats
path: root/coreAPI
diff options
context:
space:
mode:
authorelias <[email protected]>2007-04-19 11:59:23 +0000
committerelias <[email protected]>2007-04-19 11:59:23 +0000
commit3fc1b6b3987a91b6b374910402b3b21461c15450 (patch)
treee2a19e4ffe3bacd9cf81f65648365f69ef59e01c /coreAPI
parent0f999cd154be3fdc9a80035e4d9ba335d09554d0 (diff)
Made polling of absolute Components lazy to avoid performance problems with keyboards on mac os x
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@179 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'coreAPI')
-rw-r--r--coreAPI/src/java/net/java/games/input/AbstractComponent.java13
-rw-r--r--coreAPI/src/java/net/java/games/input/AbstractController.java4
2 files changed, 15 insertions, 2 deletions
diff --git a/coreAPI/src/java/net/java/games/input/AbstractComponent.java b/coreAPI/src/java/net/java/games/input/AbstractComponent.java
index 40a1750..c521276 100644
--- a/coreAPI/src/java/net/java/games/input/AbstractComponent.java
+++ b/coreAPI/src/java/net/java/games/input/AbstractComponent.java
@@ -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;
}
diff --git a/coreAPI/src/java/net/java/games/input/AbstractController.java b/coreAPI/src/java/net/java/games/input/AbstractController.java
index 266a303..02233df 100644
--- a/coreAPI/src/java/net/java/games/input/AbstractController.java
+++ b/coreAPI/src/java/net/java/games/input/AbstractController.java
@@ -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)) {