COntinued modifications to controller monitoring

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent f8cbb5abfa
commit a43f1f7189
  1. 44
      src/sig/RabiClone.java
  2. 5
      src/sig/engine/Action.java
  3. 52
      src/sig/engine/KeyBind.java
  4. 3
      src/sig/objects/ConfigureControls.java

@ -5,6 +5,7 @@ import javax.swing.JFrame;
import net.java.games.input.Component; import net.java.games.input.Component;
import net.java.games.input.Controller; import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment; import net.java.games.input.ControllerEnvironment;
import net.java.games.input.ControllerListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -85,28 +86,35 @@ public class RabiClone{
lastGameTime=System.nanoTime(); lastGameTime=System.nanoTime();
double updateMult = Math.min(1/60d,timePassed/1000000000d); double updateMult = Math.min(1/60d,timePassed/1000000000d);
if (System.currentTimeMillis()-lastControllerScan>=5000) {
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
lastControllerScan=System.currentTimeMillis();
}
//System.out.println(CONTROLLERS.length); //System.out.println(CONTROLLERS.length);
for (int i=0;i<CONTROLLERS.length;i++) { if (System.currentTimeMillis()-lastControllerScan>=5000) {
if (CONTROLLERS[i].poll()) { if (CONTROLLERS.length==0) {
//System.out.println(CONTROLLERS[i].getPortType()+" // "+CONTROLLERS[i].getType()); CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
Component[] components = CONTROLLERS[i].getComponents(); lastControllerScan=System.currentTimeMillis();
for (int j=0;j<components.length;j++) { } else {
//Component c = components[j]; for (int i=0;i<CONTROLLERS.length;i++) {
//System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData()); if (CONTROLLERS[i].poll()) {
//System.out.println(CONTROLLERS[i].getPortType()+" // "+CONTROLLERS[i].getType());
Component[] components = CONTROLLERS[i].getComponents();
for (int j=0;j<components.length;j++) {
//Component c = components[j];
//System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
}
//System.out.println("--------");
} else {
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
lastControllerScan=System.currentTimeMillis();
break;
}
/*EventQueue queue = controller_list[i].getEventQueue();
while (queue.getNextEvent(event)) {
Component c = event.getComponent();
System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
}*/
} }
//System.out.println("--------");
} }
/*EventQueue queue = controller_list[i].getEventQueue();
while (queue.getNextEvent(event)) {
Component c = event.getComponent();
System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
}*/
} }
KeyBind.poll(); KeyBind.poll();

@ -4,7 +4,6 @@ import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import net.java.games.input.Controller;
import net.java.games.input.Component.Identifier; import net.java.games.input.Component.Identifier;
public enum Action { public enum Action {
@ -25,9 +24,9 @@ public enum Action {
Action(KeyBind...keybinds) { Action(KeyBind...keybinds) {
KeyBind.KEYBINDS.put(this,new ArrayList<>(Arrays.asList(keybinds))); KeyBind.KEYBINDS.put(this,new ArrayList<>(Arrays.asList(keybinds)));
} }
Action(Controller c, Identifier.Axis axis,float val) { Action(byte port, Identifier.Axis axis,float val) {
ArrayList<KeyBind> comps = new ArrayList<KeyBind>(); ArrayList<KeyBind> comps = new ArrayList<KeyBind>();
comps.add(new KeyBind(c,axis,val)); comps.add(new KeyBind(port,axis,val));
KeyBind.KEYBINDS.put(this,comps); KeyBind.KEYBINDS.put(this,comps);
} }
} }

@ -12,21 +12,21 @@ public class KeyBind {
public static HashMap<Action,List<KeyBind>> KEYBINDS = new HashMap<>(); public static HashMap<Action,List<KeyBind>> KEYBINDS = new HashMap<>();
static HashMap<Action,Boolean> KEYS = new HashMap<>(); static HashMap<Action,Boolean> KEYS = new HashMap<>();
public Controller c; public byte port;
public Identifier id; public Identifier id;
float val; float val;
public KeyBind(Controller c, Identifier id) { public KeyBind(byte port, Identifier id) {
this.c=c; this.port=port;
this.id=id; this.id=id;
} }
public KeyBind(int keycode) { public KeyBind(int keycode) {
this(null,new Key(keycode)); this((byte)-1,new Key(keycode));
} }
public KeyBind(Controller c, Identifier id, float val) { public KeyBind(byte port, Identifier id, float val) {
this.c=c; this.port=port;
this.id=id; this.id=id;
this.val=val; this.val=val;
} }
@ -34,39 +34,39 @@ public class KeyBind {
public boolean isKeyHeld() { public boolean isKeyHeld() {
if (id instanceof Key) { if (id instanceof Key) {
return ((Key)id).isKeyHeld(); return ((Key)id).isKeyHeld();
} else if (id instanceof Identifier.Button) { } else if (RabiClone.CONTROLLERS.length>port && id instanceof Identifier.Button) {
return c.getComponent(id).getPollData()>0.0f; return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()>0.0f;
} else } else
if (c.getComponent(id).getIdentifier()==Identifier.Axis.POV) { if (RabiClone.CONTROLLERS.length>port && RabiClone.CONTROLLERS[port].getComponent(id).getIdentifier()==Identifier.Axis.POV) {
if (val==POV.DOWN) { if (val==POV.DOWN) {
return c.getComponent(id).getPollData()==POV.DOWN|| return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN||
c.getComponent(id).getPollData()==POV.DOWN_LEFT|| RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_LEFT||
c.getComponent(id).getPollData()==POV.DOWN_RIGHT; RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_RIGHT;
} else } else
if (val==POV.UP) { if (val==POV.UP) {
return c.getComponent(id).getPollData()==POV.UP|| return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP||
c.getComponent(id).getPollData()==POV.UP_LEFT|| RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_LEFT||
c.getComponent(id).getPollData()==POV.UP_RIGHT; RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_RIGHT;
} else } else
if (val==POV.RIGHT) { if (val==POV.RIGHT) {
return c.getComponent(id).getPollData()==POV.RIGHT|| return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.RIGHT||
c.getComponent(id).getPollData()==POV.UP_RIGHT|| RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_RIGHT||
c.getComponent(id).getPollData()==POV.DOWN_RIGHT; RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_RIGHT;
} else } else
if (val==POV.LEFT) { if (val==POV.LEFT) {
return c.getComponent(id).getPollData()==POV.LEFT|| return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.LEFT||
c.getComponent(id).getPollData()==POV.DOWN_LEFT|| RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_LEFT||
c.getComponent(id).getPollData()==POV.UP_LEFT; RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_LEFT;
} else { } else {
System.err.println("Unexpected value for POV! Must be a cardinal direction! Given value: "+val); System.err.println("Unexpected value for POV! Must be a cardinal direction! Given value: "+val);
return false; return false;
} }
} else } else
if (id instanceof Identifier.Axis) { if (RabiClone.CONTROLLERS.length>port && id instanceof Identifier.Axis) {
return Math.abs(c.getComponent(id).getPollData())>=c.getComponent(id).getDeadZone()&&Math.signum(c.getComponent(id).getPollData())==Math.signum(val); return Math.abs(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())>=RabiClone.CONTROLLERS[port].getComponent(id).getDeadZone()&&Math.signum(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())==Math.signum(val);
} }
else { else {
System.out.println("Could not find proper recognition for component "+id.getName()); //System.out.println("Could not find proper recognition for component "+id.getName());
return false; return false;
} }
} }
@ -125,8 +125,8 @@ public class KeyBind {
} }
public String getName() { public String getName() {
if (c!=null) { if (RabiClone.CONTROLLERS.length>port&&port!=-1) {
return c.getComponent(id).getName(); return RabiClone.CONTROLLERS[port].getComponent(id).getName();
} else } else
if (id instanceof Key) { if (id instanceof Key) {
return ((Key)id).getName(); return ((Key)id).getName();

@ -4,6 +4,7 @@ import java.awt.event.MouseEvent;
import java.util.List; import java.util.List;
import net.java.games.input.Component; import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Event; import net.java.games.input.Event;
import net.java.games.input.Component.Identifier; import net.java.games.input.Component.Identifier;
import net.java.games.input.Component.POV; import net.java.games.input.Component.POV;
@ -49,7 +50,7 @@ public class ConfigureControls extends Object{
continue; //Can't add ordinal directions, only cardinal. continue; //Can't add ordinal directions, only cardinal.
} }
} }
clist.add(new KeyBind(RabiClone.CONTROLLERS[i],id,e.getValue())); clist.add(new KeyBind((byte)i,id,e.getValue()));
KeyBind.KEYBINDS.put(selectedAction,clist); KeyBind.KEYBINDS.put(selectedAction,clist);
assigningKey=false; assigningKey=false;
} }

Loading…
Cancel
Save