diff options
Diffstat (limited to 'coreAPI')
-rw-r--r-- | coreAPI/build.xml | 6 | ||||
-rw-r--r-- | coreAPI/src/java/net/java/games/input/ControllerEnvironment.java | 5 | ||||
-rw-r--r-- | coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java | 65 |
3 files changed, 71 insertions, 5 deletions
diff --git a/coreAPI/build.xml b/coreAPI/build.xml index f585b00..56b531d 100644 --- a/coreAPI/build.xml +++ b/coreAPI/build.xml @@ -10,7 +10,7 @@ </target> <target name="compile" depends="init"> - <javac srcdir="src/java" destdir="classes" debug="true" deprecation="true" source="1.4" target="1.4"> + <javac srcdir="src/java" destdir="classes" debug="true" deprecation="true" source="1.5" target="1.5"> <include name="net/**"/> <exclude name="**/Version.java"/> <!-- To add something to the classpath: --> @@ -26,7 +26,7 @@ <filter token="API_VERSION" value="${api.version}"/> </filterset> </copy> - <javac srcdir="build/src/java" destdir="classes" debug="true" deprecation="true" source="1.4" target="1.4"> + <javac srcdir="build/src/java" destdir="classes" debug="true" deprecation="true" source="1.5" target="1.5"> <include name="net/**" /> </javac> <echo message="Build version class for ${api.version} build ${build.number}"/> @@ -44,7 +44,7 @@ <target name="javadoc" depends="init" description="Javadoc for my API."> <javadoc packagenames="net.java.games.input.*" destdir="apidocs" - additionalparam="-source 1.4" + additionalparam="-source 1.5" excludepackagenames="net.java.games.input.example.*,net.java.games.input.test.*"> <sourcepath> <pathelement location="src/java"/> diff --git a/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java b/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java index 17208f7..3a7c21e 100644 --- a/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java +++ b/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java @@ -100,6 +100,11 @@ public abstract class ControllerEnvironment { * or an empty array if there are no controllers in this environment. */ public abstract Controller[] getControllers(); + /** + * Rescans the devices and provides a list of new controllers. + * @return a list of all controllers available to this environment. + */ + public abstract Controller[] rescanControllers(); /** * Adds a listener for controller state change events. diff --git a/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java b/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java index 431a9ff..b193ef0 100644 --- a/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java +++ b/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java @@ -105,9 +105,10 @@ class DefaultControllerEnvironment extends ControllerEnvironment { /** * List of all controllers in this environment */ - private ArrayList controllers; + private ArrayList<Controller> controllers; private Collection loadedPlugins = new ArrayList(); + private ArrayList<ControllerEnvironment> environments = new ArrayList<ControllerEnvironment>(); /** * Public no-arg constructor. @@ -122,7 +123,7 @@ class DefaultControllerEnvironment extends ControllerEnvironment { public Controller[] getControllers() { if (controllers == null) { // Controller list has not been scanned. - controllers = new ArrayList(); + controllers = new ArrayList<Controller>(); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { scanControllers(); @@ -159,6 +160,7 @@ class DefaultControllerEnvironment extends ControllerEnvironment { Class ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance(); if(ce.isSupported()) { + environments.add(ce); addControllers(ce.getControllers()); loadedPlugins.add(ce.getClass().getName()); } else { @@ -170,6 +172,65 @@ class DefaultControllerEnvironment extends ControllerEnvironment { } } } + if(!environments.isEmpty()){ + Controller[] newScanControllers = environments.get(0).getControllers(); + Controller[] ret = new Controller[newScanControllers.length]; + for(int i = 0; i < newScanControllers.length; i++){ + ret[i] = newScanControllers[i]; + } + return ret; + } + + Controller[] ret = new Controller[controllers.size()]; + Iterator it = controllers.iterator(); + int i = 0; + while (it.hasNext()) { + ret[i] = (Controller)it.next(); + i++; + } + return ret; + } + + /** + * Returns a list of all controllers available to this environment, + * or an empty array if there are no controllers in this environment. + */ + public Controller[] rescanControllers() { + if(!environments.isEmpty()){ + Controller[] newScanControllers = environments.get(0).rescanControllers(); + // need to add controllers that were connected + for(int i = 0; i < newScanControllers.length; i++){ + boolean controllerExist = false; + for(Controller controller:controllers){ + if(newScanControllers[i] == controller){ + controllerExist = true; + break; + } + } + if(!controllerExist){ + controllers.add(newScanControllers[i]); + } + } + ArrayList<Controller> removeControllers = new ArrayList<Controller>(); + // need to remove controllers that have disconnected + for(Controller controller:controllers){ + boolean controllerExist = false; + for(int i = 0; i < newScanControllers.length; i++){ + if(controller == newScanControllers[i]){ + controllerExist = true; + break; + } + } + if(!controllerExist){ + //controllers.remove(controller); + removeControllers.add(controller); + } + } + for(Controller controller: removeControllers){ + controllers.remove(controller); + } + } + Controller[] ret = new Controller[controllers.size()]; Iterator it = controllers.iterator(); int i = 0; |