diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index 899a2b87c6..dedc5993ba 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -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()){ diff --git a/core/src/mindustry/entities/Effect.java b/core/src/mindustry/entities/Effect.java index 5ff06d44e0..9104b870ec 100644 --- a/core/src/mindustry/entities/Effect.java +++ b/core/src/mindustry/entities/Effect.java @@ -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); }