v0.6.0a: further improvements/fixes to threading logic

This commit is contained in:
Evan Debenham 2017-06-08 15:25:59 -04:00
parent 0697268a73
commit db97210728
2 changed files with 17 additions and 15 deletions

View File

@ -179,21 +179,24 @@ public abstract class Actor implements Bundlable {
boolean interrupted = false;
do {
now = Float.MAX_VALUE;
current = null;
for (Actor actor : all) {
current = null;
if (!interrupted) {
now = Float.MAX_VALUE;
//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;
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;
}
}
}
if (!interrupted && current != null) {
if (current != null) {
Actor acting = current;
@ -228,6 +231,7 @@ public abstract class Actor implements Bundlable {
synchronized (Thread.currentThread()) {
synchronized (GameScene.class){
//signals to the gamescene that actor processing is finished for now
GameScene.class.notify();
}
try {

View File

@ -416,11 +416,10 @@ public class GameScene extends PixelScene {
//tell the actor thread to finish, then wait for it to complete any actions it may be doing.
if (actorThread.isAlive()){
synchronized (actorThread) {
actorThread.interrupt();
}
synchronized (GameScene.class){
if (actorThread.getState() != Thread.State.WAITING) {
synchronized (actorThread) {
actorThread.interrupt();
}
try {
GameScene.class.wait(5000);
} catch (InterruptedException e) {
@ -432,7 +431,6 @@ public class GameScene extends PixelScene {
t.setStackTrace(actorThread.getStackTrace());
throw new RuntimeException("timeout waiting for actor thread! ", t);
}
}
}
}
}