Effect cleanup

This commit is contained in:
Anuken 2022-02-10 19:56:42 -05:00
parent e405a3880e
commit e0c677a313
2 changed files with 43 additions and 42 deletions

View File

@ -46,7 +46,7 @@ public class Renderer implements ApplicationListener{
public @Nullable Bloom bloom;
public @Nullable FrameBuffer backgroundBuffer;
public FrameBuffer effectBuffer = new FrameBuffer();
public boolean animateShields, drawWeather = true, drawStatus;
public boolean animateShields, drawWeather = true, drawStatus, enableEffects;
public float weatherAlpha;
/** minZoom = zooming out, maxZoom = zooming in */
public float minZoom = 1.5f, maxZoom = 6f;
@ -164,6 +164,7 @@ public class Renderer implements ApplicationListener{
bridgeOpacity = settings.getInt("bridgeopacity") / 100f;
animateShields = settings.getBool("animatedshields");
drawStatus = Core.settings.getBool("blockstatus");
enableEffects = settings.getBool("effects");
if(landTime > 0){
if(!state.isPaused()){

View File

@ -103,39 +103,71 @@ public class Effect{
}
public void at(Position pos){
create(this, pos.getX(), pos.getY(), 0, Color.white, null);
create(pos.getX(), pos.getY(), 0, Color.white, null);
}
public void at(Position pos, boolean parentize){
create(this, pos.getX(), pos.getY(), 0, Color.white, parentize ? pos : null);
create(pos.getX(), pos.getY(), 0, Color.white, parentize ? pos : null);
}
public void at(Position pos, float rotation){
create(this, pos.getX(), pos.getY(), rotation, Color.white, null);
create(pos.getX(), pos.getY(), rotation, Color.white, null);
}
public void at(float x, float y){
create(this, x, y, 0, Color.white, null);
create(x, y, 0, Color.white, null);
}
public void at(float x, float y, float rotation){
create(this, x, y, rotation, Color.white, null);
create(x, y, rotation, Color.white, null);
}
public void at(float x, float y, float rotation, Color color){
create(this, x, y, rotation, color, null);
create(x, y, rotation, color, null);
}
public void at(float x, float y, Color color){
create(this, x, y, 0, color, null);
create(x, y, 0, color, null);
}
public void at(float x, float y, float rotation, Color color, Object data){
create(this, x, y, rotation, color, data);
create(x, y, rotation, color, data);
}
public void at(float x, float y, float rotation, Object data){
create(this, x, y, rotation, Color.white, data);
create(x, y, rotation, Color.white, data);
}
protected void create(float x, float y, float rotation, Color color, Object data){
if(headless || this == Fx.none || !Vars.renderer.enableEffects) return;
if(Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(x, y, clip))){
if(!initialized){
initialized = true;
init();
}
if(startDelay <= 0f){
add(x, y, rotation, color, data);
}else{
Time.runTask(startDelay, () -> add(x, y, rotation, color, data));
}
}
}
protected void add(float x, float y, float rotation, Color color, Object data){
var entity = EffectState.create();
entity.effect = this;
entity.rotation = baseRotation + rotation;
entity.data = data;
entity.lifetime = lifetime;
entity.set(x, y);
entity.color.set(color);
if(followParent && data instanceof Posc p){
entity.parent = p;
entity.rotWithParent = rotWithParent;
}
entity.add();
}
public float render(int id, Color color, float life, float lifetime, float rotation, float x, float y, Object data){
@ -191,38 +223,6 @@ public class Effect{
}
}
public static void create(Effect effect, float x, float y, float rotation, Color color, Object data){
if(headless || effect == Fx.none || !Core.settings.getBool("effects")) return;
if(Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(x, y, effect.clip))){
if(!effect.initialized){
effect.initialized = true;
effect.init();
}
if(effect.startDelay <= 0f){
inst(effect, x, y, rotation, color, data);
}else{
Time.runTask(effect.startDelay, () -> inst(effect, x, y, rotation, color, data));
}
}
}
private static void inst(Effect effect, float x, float y, float rotation, Color color, Object data){
EffectState entity = EffectState.create();
entity.effect = effect;
entity.rotation = effect.baseRotation + rotation;
entity.data = data;
entity.lifetime = effect.lifetime;
entity.set(x, y);
entity.color.set(color);
if(effect.followParent && data instanceof Posc p){
entity.parent = p;
entity.rotWithParent = effect.rotWithParent;
}
entity.add();
}
public static void decal(TextureRegion region, float x, float y, float rotation){
decal(region, x, y, rotation, 3600f, Pal.rubble);
}