v0.4.3b: game logic thread now uses wait/notify
This commit is contained in:
parent
851060251e
commit
44e91ee771
|
@ -222,7 +222,17 @@ public abstract class Actor implements Bundlable {
|
||||||
doNext = false;
|
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 ) {
|
public static void add( Actor actor ) {
|
||||||
|
|
|
@ -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
|
@Override
|
||||||
public synchronized void update() {
|
public synchronized void update() {
|
||||||
|
@ -414,16 +419,16 @@ public class GameScene extends PixelScene {
|
||||||
|
|
||||||
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
|
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
|
||||||
|
|
||||||
if (!Actor.processing() && (t == null || !t.isAlive()) && Dungeon.hero.isAlive()) {
|
if (!Actor.processing() && Dungeon.hero.isAlive()) {
|
||||||
t = new Thread() {
|
if (!t.isAlive()) {
|
||||||
@Override
|
//if cpu time is limited, game should prefer drawing the current frame
|
||||||
public void run() {
|
t.setPriority(Thread.NORM_PRIORITY - 1);
|
||||||
Actor.process();
|
t.start();
|
||||||
|
} else {
|
||||||
|
synchronized (t) {
|
||||||
|
t.notify();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
//if cpu time is limited, game should prefer drawing the current frame
|
|
||||||
t.setPriority(Thread.NORM_PRIORITY-1);
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Dungeon.hero.ready && Dungeon.hero.paralysed == 0) {
|
if (Dungeon.hero.ready && Dungeon.hero.paralysed == 0) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user