From af5e55db41c958739afec45d43e8723f978f6dfc Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 30 May 2017 15:05:14 -0400 Subject: [PATCH] v0.6.0: fixed the game making a new thread with each new gamescene --- .../shatteredpixeldungeon/actors/Actor.java | 13 ++++++++----- .../scenes/GameScene.java | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index b8f2e0199..3dbe9dca1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -22,8 +22,8 @@ package com.shatteredpixel.shatteredpixeldungeon.actors; import android.util.SparseArray; + import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -210,11 +210,14 @@ public abstract class Actor implements Bundlable { } } } catch (InterruptedException e) { - ShatteredPixelDungeon.reportException(e); + acting = null; //continue } } - - doNext = acting.act(); + + doNext = !Thread.interrupted() + && acting != null + && acting.act(); + if (doNext && !Dungeon.hero.isAlive()) { doNext = false; current = null; @@ -228,7 +231,7 @@ public abstract class Actor implements Bundlable { try { Thread.currentThread().wait(); } catch (InterruptedException e) { - ShatteredPixelDungeon.reportException(e); + //continue, should just hit wait again } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 1ecde0573..9d28909d5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -419,6 +419,12 @@ public class GameScene extends PixelScene { scene = null; Badges.saveGlobal(); + if (actorThread.isAlive()){ + synchronized (actorThread) { + actorThread.interrupt(); + } + } + super.destroy(); } @@ -432,7 +438,7 @@ public class GameScene extends PixelScene { } } - private final Thread t = new Thread() { + private static final Thread actorThread = new Thread() { @Override public void run() { Actor.process(); @@ -450,13 +456,13 @@ public class GameScene extends PixelScene { if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed ); if (!Actor.processing() && Dungeon.hero.isAlive()) { - if (!t.isAlive()) { + if (!actorThread.isAlive()) { //if cpu time is limited, game should prefer drawing the current frame - t.setPriority(Thread.NORM_PRIORITY - 1); - t.start(); + actorThread.setPriority(Thread.NORM_PRIORITY - 1); + actorThread.start(); } else { - synchronized (t) { - t.notify(); + synchronized (actorThread) { + actorThread.notify(); } } }