v0.6.0a: further improvements/fixes to threading logic
This commit is contained in:
parent
0697268a73
commit
db97210728
|
@ -179,21 +179,24 @@ public abstract class Actor implements Bundlable {
|
||||||
boolean interrupted = false;
|
boolean interrupted = false;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
now = Float.MAX_VALUE;
|
|
||||||
current = null;
|
current = null;
|
||||||
|
if (!interrupted) {
|
||||||
|
now = Float.MAX_VALUE;
|
||||||
|
|
||||||
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 (!interrupted && current != null) {
|
if (current != null) {
|
||||||
|
|
||||||
Actor acting = current;
|
Actor acting = current;
|
||||||
|
|
||||||
|
@ -228,6 +231,7 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
synchronized (Thread.currentThread()) {
|
synchronized (Thread.currentThread()) {
|
||||||
synchronized (GameScene.class){
|
synchronized (GameScene.class){
|
||||||
|
//signals to the gamescene that actor processing is finished for now
|
||||||
GameScene.class.notify();
|
GameScene.class.notify();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -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.
|
//tell the actor thread to finish, then wait for it to complete any actions it may be doing.
|
||||||
if (actorThread.isAlive()){
|
if (actorThread.isAlive()){
|
||||||
synchronized (actorThread) {
|
|
||||||
actorThread.interrupt();
|
|
||||||
}
|
|
||||||
synchronized (GameScene.class){
|
synchronized (GameScene.class){
|
||||||
if (actorThread.getState() != Thread.State.WAITING) {
|
synchronized (actorThread) {
|
||||||
|
actorThread.interrupt();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
GameScene.class.wait(5000);
|
GameScene.class.wait(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -432,7 +431,6 @@ public class GameScene extends PixelScene {
|
||||||
t.setStackTrace(actorThread.getStackTrace());
|
t.setStackTrace(actorThread.getStackTrace());
|
||||||
throw new RuntimeException("timeout waiting for actor thread! ", t);
|
throw new RuntimeException("timeout waiting for actor thread! ", t);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user