v0.4.2: switch wait/notify to busy wait
This solves a race condition, yes using lock/semaphore would do this too, but that is a considerable amount of complexity for what amounts to an extremely simple bit of blocking logic. busy-wait works just as well and is insignificantly more expensive with the use of thread.sleep.
This commit is contained in:
parent
22585dd223
commit
8d7eac940b
|
@ -204,8 +204,11 @@ public abstract class Actor implements Bundlable {
|
||||||
// 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
|
||||||
try {
|
try {
|
||||||
synchronized (((Char)acting).sprite) {
|
//yes, we're busy-waiting. This is insignificantly slower than using
|
||||||
((Char) acting).sprite.wait();
|
//a lock/semaphore but results in more readable code.
|
||||||
|
while (((Char)acting).sprite.isMoving) {
|
||||||
|
//tries every ~0.1 milliseconds
|
||||||
|
Thread.sleep(0, 100000);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
ShatteredPixelDungeon.reportException(e);
|
ShatteredPixelDungeon.reportException(e);
|
||||||
|
|
|
@ -453,14 +453,11 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
||||||
|
|
||||||
} else if (tweener == motion) {
|
} else if (tweener == motion) {
|
||||||
|
|
||||||
isMoving = false;
|
|
||||||
synchronized (this){
|
|
||||||
notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
motion.killAndErase();
|
motion.killAndErase();
|
||||||
motion = null;
|
motion = null;
|
||||||
ch.onMotionComplete();
|
ch.onMotionComplete();
|
||||||
|
|
||||||
|
isMoving = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,11 +102,8 @@ public class TenguSprite extends MobSprite {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete( Animation anim ) {
|
public void onComplete( Animation anim ) {
|
||||||
if (anim == run) {
|
if (anim == run) {
|
||||||
isMoving = false;
|
|
||||||
synchronized (this){
|
|
||||||
notify();
|
|
||||||
}
|
|
||||||
idle();
|
idle();
|
||||||
|
isMoving = false;
|
||||||
} else {
|
} else {
|
||||||
super.onComplete( anim );
|
super.onComplete( anim );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user