v0.4.3b: game logic thread now uses wait/notify

This commit is contained in:
Evan Debenham 2016-11-02 18:49:04 -04:00
parent 851060251e
commit 44e91ee771
2 changed files with 28 additions and 13 deletions

View File

@ -222,7 +222,17 @@ public abstract class Actor implements Bundlable {
doNext = false;
}
} while (doNext);
if (!doNext){
synchronized (Thread.currentThread()) {
try {
Thread.currentThread().wait();
} catch (InterruptedException e) {
ShatteredPixelDungeon.reportException(e);
}
}
}
} while (true);
}
public static void add( Actor actor ) {

View File

@ -402,7 +402,12 @@ public class GameScene extends PixelScene {
}
}
private Thread t;
private final Thread t = new Thread() {
@Override
public void run() {
Actor.process();
}
};
@Override
public synchronized void update() {
@ -414,16 +419,16 @@ public class GameScene extends PixelScene {
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
if (!Actor.processing() && (t == null || !t.isAlive()) && Dungeon.hero.isAlive()) {
t = new Thread() {
@Override
public void run() {
Actor.process();
}
};
if (!Actor.processing() && Dungeon.hero.isAlive()) {
if (!t.isAlive()) {
//if cpu time is limited, game should prefer drawing the current frame
t.setPriority(Thread.NORM_PRIORITY-1);
t.setPriority(Thread.NORM_PRIORITY - 1);
t.start();
} else {
synchronized (t) {
t.notify();
}
}
}
if (Dungeon.hero.ready && Dungeon.hero.paralysed == 0) {