From ea4600beb389fe2c7a24f0e08ecaecd057ef1a6a Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 13 Apr 2022 21:35:26 -0400 Subject: [PATCH] Better MultiEffect --- core/src/mindustry/entities/Effect.java | 10 +++++--- .../entities/effect/MultiEffect.java | 24 ++++--------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/core/src/mindustry/entities/Effect.java b/core/src/mindustry/entities/Effect.java index c3f6fd9ec5..2f8e85152d 100644 --- a/core/src/mindustry/entities/Effect.java +++ b/core/src/mindustry/entities/Effect.java @@ -138,8 +138,12 @@ public class Effect{ 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; + public boolean shouldCreate(){ + return !headless && this != Fx.none && Vars.renderer.enableEffects; + } + + public void create(float x, float y, float rotation, Color color, Object data){ + if(!shouldCreate()) return; if(Core.camera.bounds(Tmp.r1).overlaps(Tmp.r2.setCentered(x, y, clip))){ if(!initialized){ @@ -150,7 +154,7 @@ public class Effect{ if(startDelay <= 0f){ add(x, y, rotation, color, data); }else{ - Time.runTask(startDelay, () -> add(x, y, rotation, color, data)); + Time.run(startDelay, () -> add(x, y, rotation, color, data)); } } } diff --git a/core/src/mindustry/entities/effect/MultiEffect.java b/core/src/mindustry/entities/effect/MultiEffect.java index ba44402ab7..a38765067b 100644 --- a/core/src/mindustry/entities/effect/MultiEffect.java +++ b/core/src/mindustry/entities/effect/MultiEffect.java @@ -1,5 +1,6 @@ package mindustry.entities.effect; +import arc.graphics.*; import mindustry.entities.*; /** Renders multiple particle effects at once. */ @@ -7,33 +8,18 @@ public class MultiEffect extends Effect{ public Effect[] effects = {}; public MultiEffect(){ - clip = 100f; } public MultiEffect(Effect... effects){ - this(); this.effects = effects; } @Override - public void init(){ - for(Effect f : effects){ - f.init(); - clip = Math.max(clip, f.clip); - lifetime = Math.max(lifetime, f.lifetime); - } - } + public void create(float x, float y, float rotation, Color color, Object data){ + if(!shouldCreate()) return; - @Override - public void render(EffectContainer e){ - int index = 0; - for(Effect f : effects){ - int i = ++index; - e.scaled(f.lifetime, cont -> { - cont.id = e.id + i; - f.render(cont); - }); - clip = Math.max(clip, f.clip); + for(var effect : effects){ + effect.create(x, y, rotation, color, data); } } }