Provide controller polling
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
44f0e44aed
commit
6e900581ea
@ -5,6 +5,8 @@ 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.ControllerEvent;
|
||||||
|
import net.java.games.input.ControllerListener;
|
||||||
import net.java.games.input.Event;
|
import net.java.games.input.Event;
|
||||||
import net.java.games.input.EventQueue;
|
import net.java.games.input.EventQueue;
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ public class RabiClone{
|
|||||||
public static Player player;
|
public static Player player;
|
||||||
|
|
||||||
public static Maps CURRENT_MAP = Maps.WORLD1;
|
public static Maps CURRENT_MAP = Maps.WORLD1;
|
||||||
public static List<Controller> CONTROLLERS = new ArrayList<Controller>();
|
public static Controller[] CONTROLLERS = new Controller[]{};
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
f = new JFrame(PROGRAM_NAME);
|
f = new JFrame(PROGRAM_NAME);
|
||||||
f.setResizable(false);
|
f.setResizable(false);
|
||||||
@ -68,21 +70,28 @@ public class RabiClone{
|
|||||||
p.render();
|
p.render();
|
||||||
|
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
CONTROLLERS = Arrays.asList(ControllerEnvironment.getDefaultEnvironment().getControllers());
|
|
||||||
long lastGameTime = System.nanoTime();
|
long lastGameTime = System.nanoTime();
|
||||||
while (true) {
|
while (true) {
|
||||||
long timePassed = System.nanoTime()-lastGameTime;
|
long timePassed = System.nanoTime()-lastGameTime;
|
||||||
lastGameTime=System.nanoTime();
|
lastGameTime=System.nanoTime();
|
||||||
double updateMult = Math.min(1/60d,timePassed/1000000000d);
|
double updateMult = Math.min(1/60d,timePassed/1000000000d);
|
||||||
|
|
||||||
for (int i=0;i<CONTROLLERS.size();i++) {
|
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers()
|
||||||
CONTROLLERS.get(i).poll();
|
for (int i=0;i<CONTROLLERS.length;i++) {
|
||||||
EventQueue queue = CONTROLLERS.get(i).getEventQueue();
|
if (CONTROLLERS[i].poll()) {
|
||||||
|
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("--------");
|
||||||
|
}
|
||||||
|
/*EventQueue queue = controller_list[i].getEventQueue();
|
||||||
|
|
||||||
while (queue.getNextEvent(event)) {
|
while (queue.getNextEvent(event)) {
|
||||||
Component c = event.getComponent();
|
Component c = event.getComponent();
|
||||||
System.out.println(c.getName()+","+c.getIdentifier());
|
System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.KEYS.getOrDefault(KeyEvent.VK_F1,false)) {
|
if (p.KEYS.getOrDefault(KeyEvent.VK_F1,false)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user