COntinued modifications to controller monitoring
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
f8cbb5abfa
commit
a43f1f7189
@ -5,6 +5,7 @@ import javax.swing.JFrame;
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.input.ControllerListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -85,12 +86,13 @@ public class RabiClone{
|
||||
lastGameTime=System.nanoTime();
|
||||
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);
|
||||
if (System.currentTimeMillis()-lastControllerScan>=5000) {
|
||||
if (CONTROLLERS.length==0) {
|
||||
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
|
||||
lastControllerScan=System.currentTimeMillis();
|
||||
} else {
|
||||
for (int i=0;i<CONTROLLERS.length;i++) {
|
||||
if (CONTROLLERS[i].poll()) {
|
||||
//System.out.println(CONTROLLERS[i].getPortType()+" // "+CONTROLLERS[i].getType());
|
||||
@ -100,6 +102,10 @@ public class RabiClone{
|
||||
//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();
|
||||
|
||||
@ -108,6 +114,8 @@ public class RabiClone{
|
||||
System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeyBind.poll();
|
||||
|
||||
|
@ -4,7 +4,6 @@ import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.Component.Identifier;
|
||||
|
||||
public enum Action {
|
||||
@ -25,9 +24,9 @@ public enum Action {
|
||||
Action(KeyBind...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>();
|
||||
comps.add(new KeyBind(c,axis,val));
|
||||
comps.add(new KeyBind(port,axis,val));
|
||||
KeyBind.KEYBINDS.put(this,comps);
|
||||
}
|
||||
}
|
||||
|
@ -12,21 +12,21 @@ public class KeyBind {
|
||||
public static HashMap<Action,List<KeyBind>> KEYBINDS = new HashMap<>();
|
||||
static HashMap<Action,Boolean> KEYS = new HashMap<>();
|
||||
|
||||
public Controller c;
|
||||
public byte port;
|
||||
public Identifier id;
|
||||
float val;
|
||||
|
||||
public KeyBind(Controller c, Identifier id) {
|
||||
this.c=c;
|
||||
public KeyBind(byte port, Identifier id) {
|
||||
this.port=port;
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
public KeyBind(int keycode) {
|
||||
this(null,new Key(keycode));
|
||||
this((byte)-1,new Key(keycode));
|
||||
}
|
||||
|
||||
public KeyBind(Controller c, Identifier id, float val) {
|
||||
this.c=c;
|
||||
public KeyBind(byte port, Identifier id, float val) {
|
||||
this.port=port;
|
||||
this.id=id;
|
||||
this.val=val;
|
||||
}
|
||||
@ -34,39 +34,39 @@ public class KeyBind {
|
||||
public boolean isKeyHeld() {
|
||||
if (id instanceof Key) {
|
||||
return ((Key)id).isKeyHeld();
|
||||
} else if (id instanceof Identifier.Button) {
|
||||
return c.getComponent(id).getPollData()>0.0f;
|
||||
} else if (RabiClone.CONTROLLERS.length>port && id instanceof Identifier.Button) {
|
||||
return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()>0.0f;
|
||||
} 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) {
|
||||
return c.getComponent(id).getPollData()==POV.DOWN||
|
||||
c.getComponent(id).getPollData()==POV.DOWN_LEFT||
|
||||
c.getComponent(id).getPollData()==POV.DOWN_RIGHT;
|
||||
return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_LEFT||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_RIGHT;
|
||||
} else
|
||||
if (val==POV.UP) {
|
||||
return c.getComponent(id).getPollData()==POV.UP||
|
||||
c.getComponent(id).getPollData()==POV.UP_LEFT||
|
||||
c.getComponent(id).getPollData()==POV.UP_RIGHT;
|
||||
return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_LEFT||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_RIGHT;
|
||||
} else
|
||||
if (val==POV.RIGHT) {
|
||||
return c.getComponent(id).getPollData()==POV.RIGHT||
|
||||
c.getComponent(id).getPollData()==POV.UP_RIGHT||
|
||||
c.getComponent(id).getPollData()==POV.DOWN_RIGHT;
|
||||
return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.RIGHT||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_RIGHT||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_RIGHT;
|
||||
} else
|
||||
if (val==POV.LEFT) {
|
||||
return c.getComponent(id).getPollData()==POV.LEFT||
|
||||
c.getComponent(id).getPollData()==POV.DOWN_LEFT||
|
||||
c.getComponent(id).getPollData()==POV.UP_LEFT;
|
||||
return RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.LEFT||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.DOWN_LEFT||
|
||||
RabiClone.CONTROLLERS[port].getComponent(id).getPollData()==POV.UP_LEFT;
|
||||
} else {
|
||||
System.err.println("Unexpected value for POV! Must be a cardinal direction! Given value: "+val);
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
if (id instanceof Identifier.Axis) {
|
||||
return Math.abs(c.getComponent(id).getPollData())>=c.getComponent(id).getDeadZone()&&Math.signum(c.getComponent(id).getPollData())==Math.signum(val);
|
||||
if (RabiClone.CONTROLLERS.length>port && id instanceof Identifier.Axis) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -125,8 +125,8 @@ public class KeyBind {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (c!=null) {
|
||||
return c.getComponent(id).getName();
|
||||
if (RabiClone.CONTROLLERS.length>port&&port!=-1) {
|
||||
return RabiClone.CONTROLLERS[port].getComponent(id).getName();
|
||||
} else
|
||||
if (id instanceof Key) {
|
||||
return ((Key)id).getName();
|
||||
|
@ -4,6 +4,7 @@ import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.Event;
|
||||
import net.java.games.input.Component.Identifier;
|
||||
import net.java.games.input.Component.POV;
|
||||
@ -49,7 +50,7 @@ public class ConfigureControls extends Object{
|
||||
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);
|
||||
assigningKey=false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user