v0.6.0: improved interrupt logic for actor processing
This commit is contained in:
parent
0225143d01
commit
3baf1dc5e7
|
@ -174,26 +174,24 @@ 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.
|
||||||
|
if (actor.time < now ||
|
||||||
|
actor.time == now && (current == null || actor.actPriority < current.actPriority)) {
|
||||||
|
now = actor.time;
|
||||||
|
current = actor;
|
||||||
|
}
|
||||||
|
|
||||||
//some actors will always go before others if time is equal.
|
|
||||||
if (actor.time < now ||
|
|
||||||
actor.time == now && (current == null || actor.actPriority < current.actPriority)) {
|
|
||||||
now = actor.time;
|
|
||||||
current = actor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user