v0.4.2: Game logic now occurs in a separate thread

This is going to cause a LOT of bugs, next several commits will likely be fixing them.
This commit is contained in:
Evan Debenham 2016-08-24 19:11:28 -04:00 committed by Evan Debenham
parent a54bb5fdc8
commit 36aa02de2b
2 changed files with 19 additions and 2 deletions

View File

@ -164,6 +164,10 @@ public abstract class Actor implements Bundlable {
current = null;
}
}
public static boolean processing(){
return current != null;
}
public static void process() {
@ -191,7 +195,8 @@ public abstract class Actor implements Bundlable {
if (current != null) {
if (current instanceof Char && ((Char)current).sprite.isMoving) {
if (current instanceof Char &&
((Char) current).sprite != null && ((Char)current).sprite.isMoving) {
// If it's character's turn to act, but its sprite
// is moving, wait till the movement is over
current = null;

View File

@ -400,6 +400,8 @@ public class GameScene extends PixelScene {
}
}
private Thread t;
@Override
public synchronized void update() {
if (Dungeon.hero == null || scene == null) {
@ -410,7 +412,17 @@ public class GameScene extends PixelScene {
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
Actor.process();
if (!Actor.processing() && (t == null || !t.isAlive())) {
t = new Thread() {
@Override
public void run() {
Actor.process();
}
};
//if cpu time is limited, game should prefer drawing the current frame
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
if (Dungeon.hero.ready && Dungeon.hero.paralysed == 0) {
log.newLine();