Update controller updating system to handle controller adding and removal correctly
This commit is contained in:
parent
83c48f9f83
commit
2210a101d0
@ -1,4 +1,4 @@
|
|||||||
#Wed, 22 Jun 2022 15:36:59 +0000
|
#Wed, 22 Jun 2022 18:18:39 +0000
|
||||||
|
|
||||||
|
|
||||||
/workspaces/jinput2.10=
|
/workspaces/jinput2.10=
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
dist/jinput-with-sources.jar
vendored
BIN
dist/jinput-with-sources.jar
vendored
Binary file not shown.
BIN
dist/jinput.jar
vendored
BIN
dist/jinput.jar
vendored
Binary file not shown.
@ -46,6 +46,32 @@ public abstract class AbstractController implements Controller {
|
|||||||
|
|
||||||
private final static Event event = new Event();
|
private final static Event event = new Event();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof AbstractController) {
|
||||||
|
AbstractController c = (AbstractController)obj;
|
||||||
|
return name.equals(c.getName())&&
|
||||||
|
components.length==c.getComponents().length&&
|
||||||
|
children.length==c.getControllers().length&&
|
||||||
|
rumblers.length==c.getRumblers().length&&
|
||||||
|
componentsMatch(this,c);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean componentsMatch(AbstractController a, AbstractController c) {
|
||||||
|
if (a.id_to_components.size()==c.id_to_components.size()) {
|
||||||
|
for (Component.Identifier id : a.id_to_components.keySet()) {
|
||||||
|
if (!c.id_to_components.containsKey(id)&&id.getName().equals(c.id_to_components.get(id).getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Human-readable name for this Controller
|
* Human-readable name for this Controller
|
||||||
*/
|
*/
|
||||||
|
@ -106,6 +106,7 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
|
|||||||
* List of all controllers in this environment
|
* List of all controllers in this environment
|
||||||
*/
|
*/
|
||||||
private ArrayList<Controller> controllers;
|
private ArrayList<Controller> controllers;
|
||||||
|
private ArrayList<Controller> newControllers;
|
||||||
|
|
||||||
private Collection loadedPlugins = new ArrayList();
|
private Collection loadedPlugins = new ArrayList();
|
||||||
private ArrayList<ControllerEnvironment> environments = new ArrayList<ControllerEnvironment>();
|
private ArrayList<ControllerEnvironment> environments = new ArrayList<ControllerEnvironment>();
|
||||||
@ -124,6 +125,7 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
|
|||||||
if (controllers == null) {
|
if (controllers == null) {
|
||||||
// Controller list has not been scanned.
|
// Controller list has not been scanned.
|
||||||
controllers = new ArrayList<Controller>();
|
controllers = new ArrayList<Controller>();
|
||||||
|
newControllers = new ArrayList<Controller>();
|
||||||
AccessController.doPrivileged(new PrivilegedAction() {
|
AccessController.doPrivileged(new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
scanControllers();
|
scanControllers();
|
||||||
@ -198,48 +200,44 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
|
|||||||
public Controller[] rescanControllers() {
|
public Controller[] rescanControllers() {
|
||||||
if(!environments.isEmpty()){
|
if(!environments.isEmpty()){
|
||||||
Controller[] newScanControllers = environments.get(0).rescanControllers();
|
Controller[] newScanControllers = environments.get(0).rescanControllers();
|
||||||
// need to add controllers that were connected
|
boolean[] controllerChecklist = new boolean[controllers.size()];
|
||||||
|
boolean[] newControllerChecklist = new boolean[newScanControllers.length];
|
||||||
|
// Create a checklist for all controllers.
|
||||||
for(int i = 0; i < newScanControllers.length; i++){
|
for(int i = 0; i < newScanControllers.length; i++){
|
||||||
boolean controllerExist = false;
|
for (int j=0;j<controllerChecklist.length;j++) {
|
||||||
for(Controller controller:controllers){
|
if (!controllerChecklist[j]&&((AbstractController)controllers.get(j)).equals(newScanControllers[i])) {
|
||||||
if(newScanControllers[i] == controller){
|
controllerChecklist[j]=true;
|
||||||
controllerExist = true;
|
newControllerChecklist[j]=true;
|
||||||
|
newControllers.add(newScanControllers[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!controllerExist){
|
}
|
||||||
controllers.add(newScanControllers[i]);
|
for (int i=0;i<controllerChecklist.length;i++) {
|
||||||
|
if (!controllerChecklist[i]) {
|
||||||
|
//Remove this controller.
|
||||||
|
fireControllerRemoved(controllers.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i=0;i<newControllerChecklist.length;i++) {
|
||||||
|
if (!newControllerChecklist[i]) {
|
||||||
|
//Add this controller.
|
||||||
fireControllerAdded(newScanControllers[i]);
|
fireControllerAdded(newScanControllers[i]);
|
||||||
|
newControllers.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);
|
|
||||||
fireControllerRemoved(controller);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Controller controller: removeControllers){
|
|
||||||
controllers.remove(controller);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller[] ret = new Controller[controllers.size()];
|
Controller[] ret = new Controller[newControllers.size()];
|
||||||
Iterator<Controller> it = controllers.iterator();
|
Iterator<Controller> it = newControllers.iterator();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
ret[i] = (Controller)it.next();
|
ret[i] = (Controller)it.next();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
controllers.clear();
|
||||||
|
controllers.addAll(newControllers);
|
||||||
|
newControllers.clear();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user