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 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;
|
||||||
|
@ -96,7 +97,8 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
private static HashSet<Actor> all = new HashSet<>();
|
private static HashSet<Actor> all = new HashSet<>();
|
||||||
private static HashSet<Char> chars = 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<>();
|
private static SparseArray<Actor> ids = new SparseArray<>();
|
||||||
|
|
||||||
|
@ -195,15 +197,22 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
|
|
||||||
if (current instanceof Char &&
|
Actor acting = current;
|
||||||
((Char) current).sprite != null && ((Char)current).sprite.isMoving) {
|
|
||||||
|
if (acting instanceof Char &&
|
||||||
|
((Char) acting).sprite != null && ((Char)acting).sprite.isMoving) {
|
||||||
// If it's character's turn to act, but its sprite
|
// If it's character's turn to act, but its sprite
|
||||||
// is moving, wait till the movement is over
|
// is moving, wait till the movement is over
|
||||||
current = null;
|
try {
|
||||||
break;
|
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()) {
|
if (doNext && !Dungeon.hero.isAlive()) {
|
||||||
doNext = false;
|
doNext = false;
|
||||||
current = null;
|
current = null;
|
||||||
|
|
|
@ -98,7 +98,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
|
|
||||||
public Char ch;
|
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() {
|
public CharSprite() {
|
||||||
super();
|
super();
|
||||||
|
@ -453,6 +454,9 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
} else if (tweener == motion) {
|
} else if (tweener == motion) {
|
||||||
|
|
||||||
isMoving = false;
|
isMoving = false;
|
||||||
|
synchronized (this){
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
|
||||||
motion.killAndErase();
|
motion.killAndErase();
|
||||||
motion = null;
|
motion = null;
|
||||||
|
|
|
@ -103,6 +103,9 @@ public class TenguSprite extends MobSprite {
|
||||||
public void onComplete( Animation anim ) {
|
public void onComplete( Animation anim ) {
|
||||||
if (anim == run) {
|
if (anim == run) {
|
||||||
isMoving = false;
|
isMoving = false;
|
||||||
|
synchronized (this){
|
||||||
|
notify();
|
||||||
|
}
|
||||||
idle();
|
idle();
|
||||||
} else {
|
} else {
|
||||||
super.onComplete( anim );
|
super.onComplete( anim );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user