v3.0.0: new sprite state logic, now only processes fx in display thread

This commit is contained in:
Evan Debenham
2025-01-06 15:13:04 -05:00
parent 5b083c2244
commit e911070017
2 changed files with 229 additions and 199 deletions
@@ -303,7 +303,6 @@ public class GameScene extends PixelScene {
hero.place( Dungeon.hero.pos ); hero.place( Dungeon.hero.pos );
hero.updateArmor(); hero.updateArmor();
mobs.add( hero ); mobs.add( hero );
Dungeon.hero.updateSpriteState();
for (Mob mob : Dungeon.level.mobs) { for (Mob mob : Dungeon.level.mobs) {
addMobSprite( mob ); addMobSprite( mob );
@@ -58,6 +58,7 @@ import com.watabou.utils.PointF;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.nio.Buffer; import java.nio.Buffer;
import java.util.HashSet;
public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip.Listener { public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip.Listener {
@@ -83,9 +84,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
protected float shadowOffset = 0.25f; protected float shadowOffset = 0.25f;
public enum State { public enum State {
BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED, HEALING, SHIELDED, HEARTS, GLOWING BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED, HEALING, SHIELDED, HEARTS, GLOWING, AURA
} }
private int stunStates = 0;
protected Animation idle; protected Animation idle;
protected Animation run; protected Animation run;
@@ -358,8 +358,23 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
flashTime = FLASH_INTERVAL; flashTime = FLASH_INTERVAL;
} }
private final HashSet<State> stateAdditions = new HashSet<>();
public void add( State state ) { public void add( State state ) {
synchronized (State.class) { synchronized (State.class) {
stateAdditions.add(state);
}
}
private int auraColor = 0;
//Aura needs color data too
public void aura( int color ){
add(State.AURA);
auraColor = color;
}
private synchronized void processStateAddition( State state ) {
switch (state) { switch (state) {
case BURNING: case BURNING:
if (burning != null) burning.on = false; if (burning != null) burning.on = false;
@@ -425,12 +440,35 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
if (glowBlock != null) glowBlock.killAndErase(); if (glowBlock != null) glowBlock.killAndErase();
glowBlock = GlowBlock.lighten(this); glowBlock = GlowBlock.lighten(this);
break; break;
case AURA:
if (aura != null) aura.killAndErase();
float size = Math.max(width(), height());
size = Math.max(size+4, 16);
aura = new Flare(5, size);
aura.angularSpeed = 90;
aura.color(auraColor, true);
aura.visible = visible;
if (parent != null) {
aura.show(this, 0);
} }
break;
} }
} }
private final HashSet<State> stateRemovals = new HashSet<>();
public void remove( State state ) { public void remove( State state ) {
synchronized (State.class) { synchronized (State.class) {
stateRemovals.add(state);
}
}
public void clearAura(){
remove(State.AURA);
}
private synchronized void processStateRemoval( State state ) {
switch (state) { switch (state) {
case BURNING: case BURNING:
if (burning != null) { if (burning != null) {
@@ -506,31 +544,14 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
glowBlock.darken(); glowBlock.darken();
glowBlock = null; glowBlock = null;
} }
} break;
} case AURA:
}
public void aura( int color ){
if (aura != null){
aura.killAndErase();
}
float size = Math.max(width(), height());
size = Math.max(size+4, 16);
aura = new Flare(5, size);
aura.angularSpeed = 90;
aura.color(color, true);
aura.visible = visible;
if (parent != null) {
aura.show(this, 0);
}
}
public void clearAura(){
if (aura != null){ if (aura != null){
aura.killAndErase(); aura.killAndErase();
aura = null; aura = null;
} }
break;
}
} }
@Override @Override
@@ -547,6 +568,16 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
} }
synchronized (State.class) { synchronized (State.class) {
for (State s : stateAdditions) {
processStateAddition(s);
}
stateAdditions.clear();
for (State s : stateRemovals) {
processStateRemoval(s);
}
stateRemovals.clear();
}
if (burning != null) { if (burning != null) {
burning.visible = visible; burning.visible = visible;
} }
@@ -585,7 +616,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
if (glowBlock != null){ if (glowBlock != null){
glowBlock.visible =visible; glowBlock.visible =visible;
} }
}
if (sleeping) { if (sleeping) {
showSleep(); showSleep();
} else { } else {