From e3f9619c6b80cff6efe1825c9a2768350d7d20db Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 21 Oct 2024 16:13:57 -0400 Subject: [PATCH] v3.0.0: added some sync safety checks to CharSprite --- .../sprites/CharSprite.java | 310 +++++++++--------- 1 file changed, 158 insertions(+), 152 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 6335c4a31..c86602bae 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -357,135 +357,139 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip } public void add( State state ) { - switch (state) { - case BURNING: - burning = emitter(); - burning.pour( FlameParticle.FACTORY, 0.06f ); - if (visible) { - Sample.INSTANCE.play( Assets.Sounds.BURNING ); - } - break; - case LEVITATING: - levitation = emitter(); - levitation.pour( Speck.factory( Speck.JET ), 0.02f ); - break; - case INVISIBLE: - if (invisible != null) { - invisible.killAndErase(); - } - invisible = new AlphaTweener( this, 0.4f, 0.4f ); - if (parent != null){ - parent.add(invisible); - } else - alpha( 0.4f ); - break; - case PARALYSED: - paused = true; - break; - case FROZEN: - iceBlock = IceBlock.freeze( this ); - break; - case ILLUMINATED: - GameScene.effect( light = new TorchHalo( this ) ); - break; - case CHILLED: - chilled = emitter(); - chilled.pour(SnowParticle.FACTORY, 0.1f); - break; - case DARKENED: - darkBlock = DarkBlock.darken( this ); - break; - case MARKED: - marked = emitter(); - marked.pour(ShadowParticle.UP, 0.1f); - break; - case HEALING: - healing = emitter(); - healing.pour(Speck.factory(Speck.HEALING), 0.5f); - break; - case SHIELDED: - if (shield != null) { - shield.killAndErase(); - } - GameScene.effect(shield = new ShieldHalo(this)); - break; - case HEARTS: - hearts = emitter(); - hearts.pour(Speck.factory(Speck.HEART), 0.5f); - break; + synchronized (State.class) { + switch (state) { + case BURNING: + burning = emitter(); + burning.pour(FlameParticle.FACTORY, 0.06f); + if (visible) { + Sample.INSTANCE.play(Assets.Sounds.BURNING); + } + break; + case LEVITATING: + levitation = emitter(); + levitation.pour(Speck.factory(Speck.JET), 0.02f); + break; + case INVISIBLE: + if (invisible != null) { + invisible.killAndErase(); + } + invisible = new AlphaTweener(this, 0.4f, 0.4f); + if (parent != null) { + parent.add(invisible); + } else + alpha(0.4f); + break; + case PARALYSED: + paused = true; + break; + case FROZEN: + iceBlock = IceBlock.freeze(this); + break; + case ILLUMINATED: + GameScene.effect(light = new TorchHalo(this)); + break; + case CHILLED: + chilled = emitter(); + chilled.pour(SnowParticle.FACTORY, 0.1f); + break; + case DARKENED: + darkBlock = DarkBlock.darken(this); + break; + case MARKED: + marked = emitter(); + marked.pour(ShadowParticle.UP, 0.1f); + break; + case HEALING: + healing = emitter(); + healing.pour(Speck.factory(Speck.HEALING), 0.5f); + break; + case SHIELDED: + if (shield != null) { + shield.killAndErase(); + } + GameScene.effect(shield = new ShieldHalo(this)); + break; + case HEARTS: + hearts = emitter(); + hearts.pour(Speck.factory(Speck.HEART), 0.5f); + break; + } } } public void remove( State state ) { - switch (state) { - case BURNING: - if (burning != null) { - burning.on = false; - burning = null; - } - break; - case LEVITATING: - if (levitation != null) { - levitation.on = false; - levitation = null; - } - break; - case INVISIBLE: - if (invisible != null) { - invisible.killAndErase(); - invisible = null; - } - alpha( 1f ); - break; - case PARALYSED: - paused = false; - break; - case FROZEN: - if (iceBlock != null) { - iceBlock.melt(); - iceBlock = null; - } - break; - case ILLUMINATED: - if (light != null) { - light.putOut(); - } - break; - case CHILLED: - if (chilled != null){ - chilled.on = false; - chilled = null; - } - break; - case DARKENED: - if (darkBlock != null) { - darkBlock.lighten(); - darkBlock = null; - } - break; - case MARKED: - if (marked != null){ - marked.on = false; - marked = null; - } - break; - case HEALING: - if (healing != null){ - healing.on = false; - healing = null; - } - break; - case SHIELDED: - if (shield != null){ - shield.putOut(); - } - break; - case HEARTS: - if (hearts != null){ - hearts.on = false; - hearts = null; - } - break; + synchronized (State.class) { + switch (state) { + case BURNING: + if (burning != null) { + burning.on = false; + burning = null; + } + break; + case LEVITATING: + if (levitation != null) { + levitation.on = false; + levitation = null; + } + break; + case INVISIBLE: + if (invisible != null) { + invisible.killAndErase(); + invisible = null; + } + alpha(1f); + break; + case PARALYSED: + paused = false; + break; + case FROZEN: + if (iceBlock != null) { + iceBlock.melt(); + iceBlock = null; + } + break; + case ILLUMINATED: + if (light != null) { + light.putOut(); + } + break; + case CHILLED: + if (chilled != null) { + chilled.on = false; + chilled = null; + } + break; + case DARKENED: + if (darkBlock != null) { + darkBlock.lighten(); + darkBlock = null; + } + break; + case MARKED: + if (marked != null) { + marked.on = false; + marked = null; + } + break; + case HEALING: + if (healing != null) { + healing.on = false; + healing = null; + } + break; + case SHIELDED: + if (shield != null) { + shield.putOut(); + } + break; + case HEARTS: + if (hearts != null) { + hearts.on = false; + hearts = null; + } + break; + } } } @@ -524,34 +528,36 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip if (flashTime > 0 && (flashTime -= Game.elapsed) <= 0) { resetColor(); } - - if (burning != null) { - burning.visible = visible; - } - if (levitation != null) { - levitation.visible = visible; - } - if (iceBlock != null) { - iceBlock.visible = visible; - } - if (chilled != null) { - chilled.visible = visible; - } - if (marked != null) { - marked.visible = visible; - } - if (healing != null){ - healing.visible = visible; - } - if (hearts != null){ - hearts.visible = visible; - } - if (aura != null){ - if (aura.parent == null){ - aura.show(this, 0); + + synchronized (State.class) { + if (burning != null) { + burning.visible = visible; + } + if (levitation != null) { + levitation.visible = visible; + } + if (iceBlock != null) { + iceBlock.visible = visible; + } + if (chilled != null) { + chilled.visible = visible; + } + if (marked != null) { + marked.visible = visible; + } + if (healing != null) { + healing.visible = visible; + } + if (hearts != null) { + hearts.visible = visible; + } + if (aura != null) { + if (aura.parent == null) { + aura.show(this, 0); + } + aura.visible = visible; + aura.point(center()); } - aura.visible = visible; - aura.point(center()); } if (sleeping) { showSleep();