v0.6.0: fixed the game making a new thread with each new gamescene
This commit is contained in:
parent
34b2f9dc1f
commit
af5e55db41
|
@ -22,8 +22,8 @@
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.actors;
|
package com.shatteredpixel.shatteredpixeldungeon.actors;
|
||||||
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
|
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
||||||
|
@ -210,11 +210,14 @@ public abstract class Actor implements Bundlable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
ShatteredPixelDungeon.reportException(e);
|
acting = null; //continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doNext = acting.act();
|
doNext = !Thread.interrupted()
|
||||||
|
&& acting != null
|
||||||
|
&& acting.act();
|
||||||
|
|
||||||
if (doNext && !Dungeon.hero.isAlive()) {
|
if (doNext && !Dungeon.hero.isAlive()) {
|
||||||
doNext = false;
|
doNext = false;
|
||||||
current = null;
|
current = null;
|
||||||
|
@ -228,7 +231,7 @@ public abstract class Actor implements Bundlable {
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().wait();
|
Thread.currentThread().wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
ShatteredPixelDungeon.reportException(e);
|
//continue, should just hit wait again
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,6 +419,12 @@ public class GameScene extends PixelScene {
|
||||||
scene = null;
|
scene = null;
|
||||||
Badges.saveGlobal();
|
Badges.saveGlobal();
|
||||||
|
|
||||||
|
if (actorThread.isAlive()){
|
||||||
|
synchronized (actorThread) {
|
||||||
|
actorThread.interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.destroy();
|
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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Actor.process();
|
Actor.process();
|
||||||
|
@ -450,13 +456,13 @@ public class GameScene extends PixelScene {
|
||||||
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
|
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
|
||||||
|
|
||||||
if (!Actor.processing() && Dungeon.hero.isAlive()) {
|
if (!Actor.processing() && Dungeon.hero.isAlive()) {
|
||||||
if (!t.isAlive()) {
|
if (!actorThread.isAlive()) {
|
||||||
//if cpu time is limited, game should prefer drawing the current frame
|
//if cpu time is limited, game should prefer drawing the current frame
|
||||||
t.setPriority(Thread.NORM_PRIORITY - 1);
|
actorThread.setPriority(Thread.NORM_PRIORITY - 1);
|
||||||
t.start();
|
actorThread.start();
|
||||||
} else {
|
} else {
|
||||||
synchronized (t) {
|
synchronized (actorThread) {
|
||||||
t.notify();
|
actorThread.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user