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
|
||||
// is moving, wait till the movement is over
|
||||
try {
|
||||
synchronized (((Char)acting).sprite) {
|
||||
((Char) acting).sprite.wait();
|
||||
//yes, we're busy-waiting. This is insignificantly slower than using
|
||||
//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) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
|
|
|
@ -453,14 +453,11 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
|
|||
|
||||
} else if (tweener == motion) {
|
||||
|
||||
isMoving = false;
|
||||
synchronized (this){
|
||||
notify();
|
||||
}
|
||||
|
||||
motion.killAndErase();
|
||||
motion = null;
|
||||
ch.onMotionComplete();
|
||||
|
||||
isMoving = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,11 +102,8 @@ public class TenguSprite extends MobSprite {
|
|||
@Override
|
||||
public void onComplete( Animation anim ) {
|
||||
if (anim == run) {
|
||||
isMoving = false;
|
||||
synchronized (this){
|
||||
notify();
|
||||
}
|
||||
idle();
|
||||
isMoving = false;
|
||||
} else {
|
||||
super.onComplete( anim );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user