v0.4.2: changed sprite movement to use a wait/notify structure
This commit is contained in:
parent
ced9532a72
commit
50f6329578
|
@ -22,6 +22,7 @@ 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;
|
||||
|
@ -96,7 +97,8 @@ public abstract class Actor implements Bundlable {
|
|||
|
||||
private static HashSet<Actor> all = new HashSet<>();
|
||||
private static HashSet<Char> chars = new HashSet<>();
|
||||
private static Actor current;
|
||||
private static volatile Actor current;
|
||||
private static volatile boolean processing;
|
||||
|
||||
private static SparseArray<Actor> ids = new SparseArray<>();
|
||||
|
||||
|
@ -195,15 +197,22 @@ public abstract class Actor implements Bundlable {
|
|||
|
||||
if (current != null) {
|
||||
|
||||
if (current instanceof Char &&
|
||||
((Char) current).sprite != null && ((Char)current).sprite.isMoving) {
|
||||
Actor acting = current;
|
||||
|
||||
if (acting instanceof Char &&
|
||||
((Char) acting).sprite != null && ((Char)acting).sprite.isMoving) {
|
||||
// If it's character's turn to act, but its sprite
|
||||
// is moving, wait till the movement is over
|
||||
current = null;
|
||||
break;
|
||||
try {
|
||||
synchronized (((Char)acting).sprite) {
|
||||
((Char) acting).sprite.wait();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
doNext = current.act();
|
||||
doNext = acting.act();
|
||||
if (doNext && !Dungeon.hero.isAlive()) {
|
||||
doNext = false;
|
||||
current = null;
|
||||
|
|
|
@ -98,7 +98,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||
|
||||
public Char ch;
|
||||
|
||||
public boolean isMoving = false;
|
||||
//used to prevent the actor associated with this sprite from acting until movement completes
|
||||
public volatile boolean isMoving = false;
|
||||
|
||||
public CharSprite() {
|
||||
super();
|
||||
|
@ -453,6 +454,9 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||
} else if (tweener == motion) {
|
||||
|
||||
isMoving = false;
|
||||
synchronized (this){
|
||||
notify();
|
||||
}
|
||||
|
||||
motion.killAndErase();
|
||||
motion = null;
|
||||
|
|
|
@ -103,6 +103,9 @@ public class TenguSprite extends MobSprite {
|
|||
public void onComplete( Animation anim ) {
|
||||
if (anim == run) {
|
||||
isMoving = false;
|
||||
synchronized (this){
|
||||
notify();
|
||||
}
|
||||
idle();
|
||||
} else {
|
||||
super.onComplete( anim );
|
||||
|
|
Loading…
Reference in New Issue
Block a user