From ea4d45da7f82d3e92a0b57f765bfd0903ee59dff Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 30 Jun 2020 21:15:04 -0400 Subject: [PATCH] v0.8.1a: tweaked syncing on char sprites to hopefully fix rare deadlocks --- .../sprites/CharSprite.java | 122 ++++++++++-------- .../sprites/GhoulSprite.java | 5 +- .../sprites/MimicSprite.java | 2 +- .../sprites/MobSprite.java | 4 +- 4 files changed, 70 insertions(+), 63 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java index 605bdadf2..5c494df2b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -291,10 +291,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip public void die() { sleeping = false; play( die ); - - if (emo != null) { - emo.killAndErase(); - } + + hideEmo(); if (health != null){ health.killAndErase(); @@ -465,8 +463,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip } @Override - //syncronized due to EmoIcon handling - public synchronized void update() { + public void update() { super.update(); @@ -498,8 +495,10 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip } else { hideSleep(); } - if (emo != null && emo.alive) { - emo.visible = visible; + synchronized (EmoIcon.class) { + if (emo != null && emo.alive) { + emo.visible = visible; + } } } @@ -511,61 +510,76 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip } } - public synchronized void showSleep() { - if (emo instanceof EmoIcon.Sleep) { - - } else { - if (emo != null) { - emo.killAndErase(); + public void showSleep() { + synchronized (EmoIcon.class) { + if (!(emo instanceof EmoIcon.Sleep)) { + if (emo != null) { + emo.killAndErase(); + } + emo = new EmoIcon.Sleep(this); + emo.visible = visible; } - emo = new EmoIcon.Sleep( this ); - emo.visible = visible; } idle(); } - public synchronized void hideSleep() { - if (emo instanceof EmoIcon.Sleep) { - emo.killAndErase(); - emo = null; + public void hideSleep() { + synchronized (EmoIcon.class) { + if (emo instanceof EmoIcon.Sleep) { + emo.killAndErase(); + emo = null; + } } } - public synchronized void showAlert() { - if (emo instanceof EmoIcon.Alert) { - - } else { + public void showAlert() { + synchronized (EmoIcon.class) { + if (!(emo instanceof EmoIcon.Alert)) { + if (emo != null) { + emo.killAndErase(); + } + emo = new EmoIcon.Alert(this); + emo.visible = visible; + } + } + } + + public void hideAlert() { + synchronized (EmoIcon.class) { + if (emo instanceof EmoIcon.Alert) { + emo.killAndErase(); + emo = null; + } + } + } + + public void showLost() { + synchronized (EmoIcon.class) { + if (!(emo instanceof EmoIcon.Lost)) { + if (emo != null) { + emo.killAndErase(); + } + emo = new EmoIcon.Lost(this); + emo.visible = visible; + } + } + } + + public void hideLost() { + synchronized (EmoIcon.class) { + if (emo instanceof EmoIcon.Lost) { + emo.killAndErase(); + emo = null; + } + } + } + + public void hideEmo(){ + synchronized (EmoIcon.class) { if (emo != null) { emo.killAndErase(); + emo = null; } - emo = new EmoIcon.Alert( this ); - emo.visible = visible; - } - } - - public synchronized void hideAlert() { - if (emo instanceof EmoIcon.Alert) { - emo.killAndErase(); - emo = null; - } - } - - public synchronized void showLost() { - if (emo instanceof EmoIcon.Lost) { - - } else { - if (emo != null) { - emo.killAndErase(); - } - emo = new EmoIcon.Lost( this ); - emo.visible = visible; - } - } - - public synchronized void hideLost() { - if (emo instanceof EmoIcon.Lost) { - emo.killAndErase(); - emo = null; } } @@ -573,9 +587,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip public void kill() { super.kill(); - if (emo != null) { - emo.killAndErase(); - } + hideEmo(); for( State s : State.values()){ remove(s); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhoulSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhoulSprite.java index 1e3ddd109..bf6aa606b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhoulSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GhoulSprite.java @@ -54,10 +54,7 @@ public class GhoulSprite extends MobSprite { } public void crumple(){ - if (emo != null){ - emo.killAndErase(); - emo = null; - } + hideEmo(); play(crumple); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MimicSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MimicSprite.java index 0f3c992e2..cd1e7e65e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MimicSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MimicSprite.java @@ -81,7 +81,7 @@ public class MimicSprite extends MobSprite { } @Override - public synchronized void showSleep() { + public void showSleep() { if (curAnim == hiding){ return; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MobSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MobSprite.java index 0762b3b0f..421a81914 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MobSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/MobSprite.java @@ -62,9 +62,7 @@ public class MobSprite extends CharSprite { angularSpeed = Random.Int( 2 ) == 0 ? -720 : 720; am = 1; - if (emo != null){ - emo.killAndErase(); - } + hideEmo(); if (health != null){ health.killAndErase();