Thread aangemaakt voor het updaten van features en pollen van events. Misschien moet het hele Device een Thread worden?
This commit is contained in:
@@ -50,7 +50,7 @@ public class Main extends Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
addDevice(new ExampleDevice());
|
//addDevice(new ExampleDevice());
|
||||||
addDevice(new RumblepadDevice());
|
addDevice(new RumblepadDevice());
|
||||||
|
|
||||||
Application application = new VoorbeeldApplication();
|
Application application = new VoorbeeldApplication();
|
||||||
@@ -67,6 +67,7 @@ public class Main extends Target {
|
|||||||
public void run() throws ActionException, EventException {
|
public void run() throws ActionException, EventException {
|
||||||
run = true;
|
run = true;
|
||||||
while (run) {
|
while (run) {
|
||||||
|
//System.out.println("Print!");
|
||||||
if (actionQueue.isEmpty()) {
|
if (actionQueue.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(SLEEP);
|
Thread.sleep(SLEEP);
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ package pm.application.voorbeeld;
|
|||||||
import pm.application.Application;
|
import pm.application.Application;
|
||||||
|
|
||||||
public class VoorbeeldApplication extends Application {
|
public class VoorbeeldApplication extends Application {
|
||||||
public void start() throws Exception {
|
public void start() {
|
||||||
System.out.println("jeheee!");
|
System.out.println("start");
|
||||||
//throw new Exception("GEK");
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
System.out.println("stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
System.out.println("neheee!");
|
System.out.println("test");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|||||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||||
|
|
||||||
|
import pm.action.Action;
|
||||||
|
import pm.event.Target;
|
||||||
import pm.exception.ServiceJavaInputDeviceNotFoundException;
|
import pm.exception.ServiceJavaInputDeviceNotFoundException;
|
||||||
import pm.exception.ServiceJavaInputException;
|
import pm.exception.ServiceJavaInputException;
|
||||||
|
|
||||||
@@ -56,38 +58,50 @@ public abstract class JavaInputDevice extends Device {
|
|||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
startListeners();
|
startListeners();
|
||||||
while (run) {
|
startUpdateThread();
|
||||||
boolean sleep = true;
|
}
|
||||||
if (!axisEventQueue.isEmpty()) {
|
|
||||||
processEvent(axisEventQueue.poll());
|
protected void startUpdateThread() {
|
||||||
sleep = false;
|
new Thread() {
|
||||||
|
public void run() {
|
||||||
|
while (run) {
|
||||||
|
JXInputManager.updateFeatures();
|
||||||
|
boolean sleep = true;
|
||||||
|
if (!axisEventQueue.isEmpty()) {
|
||||||
|
processEvent(axisEventQueue.poll());
|
||||||
|
sleep = false;
|
||||||
|
}
|
||||||
|
if (!buttonEventQueue.isEmpty()) {
|
||||||
|
processEvent(buttonEventQueue.poll());
|
||||||
|
sleep = false;
|
||||||
|
}
|
||||||
|
if (!directionalEventQueue.isEmpty()) {
|
||||||
|
processEvent(directionalEventQueue.poll());
|
||||||
|
sleep = false;
|
||||||
|
}
|
||||||
|
if (sleep) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(SLEEP);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!buttonEventQueue.isEmpty()) {
|
}.start();
|
||||||
processEvent(buttonEventQueue.poll());
|
|
||||||
sleep = false;
|
|
||||||
}
|
|
||||||
if (!directionalEventQueue.isEmpty()) {
|
|
||||||
processEvent(directionalEventQueue.poll());
|
|
||||||
sleep = false;
|
|
||||||
}
|
|
||||||
if (sleep) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(SLEEP);
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processEvent(JXInputAxisEvent event) {
|
protected void processEvent(JXInputAxisEvent event) {
|
||||||
|
addAction(Action.START, Target.APPLICATION);
|
||||||
|
//System.out.println(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processEvent(JXInputButtonEvent event) {
|
protected void processEvent(JXInputButtonEvent event) {
|
||||||
System.out.println(event);
|
addAction(Action.TEST, Target.APPLICATION);
|
||||||
|
//System.out.println(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processEvent(JXInputDirectionalEvent event) {
|
protected void processEvent(JXInputDirectionalEvent event) {
|
||||||
|
addAction(Action.EXIT, Target.APPLICATION);
|
||||||
|
//System.out.println(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startListeners() {
|
protected void startListeners() {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import pm.event.Target;
|
|||||||
|
|
||||||
public class ExampleDevice extends Device {
|
public class ExampleDevice extends Device {
|
||||||
public void start() {
|
public void start() {
|
||||||
System.out.println("Ik hoef niets te starten");
|
//System.out.println("Ik hoef niets te starten");
|
||||||
addAction(Action.START, Target.APPLICATION);
|
//addAction(Action.START, Target.APPLICATION);
|
||||||
addAction(Action.TEST, Target.APPLICATION);
|
//addAction(Action.TEST, Target.APPLICATION);
|
||||||
addAction(Action.EXIT, Target.MAIN);
|
//addAction(Action.EXIT, Target.MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user