v0.6.0: improved interrupt logic for actor processing

This commit is contained in:
Evan Debenham 2017-06-01 02:17:18 -04:00
parent 0225143d01
commit 3baf1dc5e7

View File

@ -174,17 +174,14 @@ public abstract class Actor implements Bundlable {
public static void process() { public static void process() {
if (current != null) {
return;
}
boolean doNext; boolean doNext;
boolean interrupted = false;
do { do {
now = Float.MAX_VALUE; now = Float.MAX_VALUE;
current = null; current = null;
if (!interrupted) {
for (Actor actor : all) { for (Actor actor : all) {
//some actors will always go before others if time is equal. //some actors will always go before others if time is equal.
@ -195,6 +192,7 @@ public abstract class Actor implements Bundlable {
} }
} }
}
if (current != null) { if (current != null) {
@ -210,14 +208,13 @@ public abstract class Actor implements Bundlable {
} }
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
acting = null; //continue interrupted = true;
} }
} }
doNext = !Thread.interrupted() interrupted = interrupted || Thread.interrupted();
&& acting != null
&& Dungeon.hero != null doNext = !interrupted && acting.act();
&& acting.act();
if (doNext && !Dungeon.hero.isAlive()) { if (doNext && !Dungeon.hero.isAlive()) {
doNext = false; doNext = false;
@ -228,11 +225,12 @@ public abstract class Actor implements Bundlable {
} }
if (!doNext){ if (!doNext){
interrupted = false;
synchronized (Thread.currentThread()) { synchronized (Thread.currentThread()) {
try { try {
Thread.currentThread().wait(); Thread.currentThread().wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
//continue, should just hit wait again interrupted = true;
} }
} }
} }