From d9692004ccff824386e1a39d2727b8237e247a84 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Apr 2019 17:08:22 -0400 Subject: [PATCH] Shield optimization --- core/assets/bundles/bundle.properties | 1 + .../src/io/anuke/mindustry/core/Renderer.java | 31 +++++++------ .../mindustry/graphics/BlockRenderer.java | 1 + .../anuke/mindustry/graphics/Pixelator.java | 15 +++++-- .../ui/dialogs/SettingsMenuDialog.java | 1 + .../world/blocks/defense/ForceProjector.java | 43 ++++++++++++++----- .../world/blocks/production/Separator.java | 2 +- 7 files changed, 67 insertions(+), 27 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 4e265ad422..8cf5a34f41 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -420,6 +420,7 @@ category.optional = Optional Enhancements setting.landscape.name = Lock Landscape setting.shadows.name = Shadows setting.animatedwater.name = Animated Water +setting.animatedshields.name = Animated Shields setting.antialias.name = Antialias[LIGHT_GRAY] (requires restart)[] setting.indicators.name = Enemy/Ally Indicators setting.autotarget.name = Auto-Target diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 5c610a2187..44a9412b39 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -163,8 +163,9 @@ public class Renderer implements ApplicationListener{ graphics.clear(clearColor); - if(graphics.getWidth() >= 2 && graphics.getHeight() >= 2 && (shieldBuffer.getWidth() != graphics.getWidth() || shieldBuffer.getHeight() != graphics.getHeight())){ + if(!graphics.isHidden() && (shieldBuffer.getWidth() != graphics.getWidth() || shieldBuffer.getHeight() != graphics.getHeight())){ shieldBuffer.resize(graphics.getWidth(), graphics.getHeight()); + pixelator.rebind(); } Draw.proj(camera.projection()); @@ -211,18 +212,22 @@ public class Renderer implements ApplicationListener{ drawAndInterpolate(playerGroup, p -> true, Player::drawBuildRequests); if(EntityDraw.countInBounds(shieldGroup) > 0){ - Draw.flush(); - shieldBuffer.begin(); - graphics.clear(Color.CLEAR); - EntityDraw.draw(shieldGroup); - EntityDraw.drawWith(shieldGroup, shield -> true, shield -> ((ShieldEntity)shield).drawOver()); - Draw.flush(); - shieldBuffer.end(); - Draw.shader(Shaders.shield); - Draw.color(Pal.accent); - Draw.rect(Draw.wrap(shieldBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height); - Draw.color(); - Draw.shader(); + if(settings.getBool("animatedshields") && !pixelator.enabled()){ + Draw.flush(); + shieldBuffer.begin(); + graphics.clear(Color.CLEAR); + EntityDraw.draw(shieldGroup); + EntityDraw.drawWith(shieldGroup, shield -> true, shield -> ((ShieldEntity)shield).drawOver()); + Draw.flush(); + shieldBuffer.end(); + Draw.shader(Shaders.shield); + Draw.color(Pal.accent); + Draw.rect(Draw.wrap(shieldBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height); + Draw.color(); + Draw.shader(); + }else{ + EntityDraw.drawWith(shieldGroup, shield -> true, shield -> ((ShieldEntity)shield).drawSimple()); + } } overlays.drawTop(); diff --git a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java index 7060288d1a..0ea6dd31ca 100644 --- a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java @@ -121,6 +121,7 @@ public class BlockRenderer{ public void drawShadows(){ if(!shadowEvents.isEmpty()){ Draw.flush(); + shadows.begin(); Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight()); diff --git a/core/src/io/anuke/mindustry/graphics/Pixelator.java b/core/src/io/anuke/mindustry/graphics/Pixelator.java index 91979a6e75..1800696011 100644 --- a/core/src/io/anuke/mindustry/graphics/Pixelator.java +++ b/core/src/io/anuke/mindustry/graphics/Pixelator.java @@ -1,32 +1,41 @@ package io.anuke.mindustry.graphics; import io.anuke.arc.Core; +import io.anuke.arc.graphics.Blending; import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.glutils.FrameBuffer; import io.anuke.arc.util.Disposable; -import static io.anuke.mindustry.Vars.*; +import static io.anuke.arc.Core.camera; +import static io.anuke.arc.Core.graphics; +import static io.anuke.mindustry.Vars.renderer; public class Pixelator implements Disposable{ private FrameBuffer buffer = new FrameBuffer(2, 2); public void drawPixelate(){ + graphics.clear(0f, 0f, 0f, 1f); + float px = Core.camera.position.x, py = Core.camera.position.y; - Core.camera.position.set((int)px, (int)py + (Core.graphics.getHeight() % 2 == 0 ? 0 : 0.5f)); + Core.camera.position.set((int)px, (int)py + ((int)(camera.height) % 2 == 0 ? 0 : 0.5f)); int w = (int)(Core.camera.width); int h = (int)(Core.camera.height); - if(buffer.getWidth() != w || buffer.getHeight() != h){ + if(!graphics.isHidden() && (buffer.getWidth() != w || buffer.getHeight() != h)){ buffer.resize(w, h); } Draw.flush(); buffer.begin(); renderer.draw(); + Draw.flush(); buffer.end(); + + Draw.blend(Blending.disabled); Draw.rect(Draw.wrap(buffer.getTexture()), Core.camera.position.x, Core.camera.position.y, Core.camera.width, -Core.camera.height); + Draw.blend(); Core.camera.position.set(px, py); } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java index b044aba5df..3d0c5fd035 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -213,6 +213,7 @@ public class SettingsMenuDialog extends SettingsDialog{ graphics.checkPref("fps", false); graphics.checkPref("indicators", true); graphics.checkPref("animatedwater", false); + graphics.checkPref("animatedshields", false); graphics.checkPref("lasers", true); graphics.checkPref("pixelate", false); } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java index 6a8b8f83dc..94e566adae 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java @@ -1,21 +1,22 @@ package io.anuke.mindustry.world.blocks.defense; import io.anuke.arc.Core; -import io.anuke.mindustry.entities.Effects; -import io.anuke.mindustry.entities.EntityGroup; -import io.anuke.mindustry.entities.EntityQuery; -import io.anuke.mindustry.entities.impl.BaseEntity; -import io.anuke.mindustry.entities.traits.DrawTrait; import io.anuke.arc.graphics.Blending; import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.Fill; +import io.anuke.arc.graphics.g2d.Lines; import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.math.Mathf; import io.anuke.arc.util.Time; import io.anuke.mindustry.content.Fx; -import io.anuke.mindustry.entities.type.TileEntity; +import io.anuke.mindustry.entities.Effects; +import io.anuke.mindustry.entities.EntityGroup; +import io.anuke.mindustry.entities.EntityQuery; +import io.anuke.mindustry.entities.impl.BaseEntity; import io.anuke.mindustry.entities.traits.AbsorbTrait; +import io.anuke.mindustry.entities.traits.DrawTrait; +import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; @@ -36,7 +37,7 @@ public class ForceProjector extends Block { protected float phaseUseTime = 350f; protected float phaseRadiusBoost = 80f; - protected float radius = 100f; + protected float radius = 101.7f; protected float breakage = 550f; protected float cooldownNormal = 1.75f; protected float cooldownLiquid = 1.5f; @@ -46,7 +47,6 @@ public class ForceProjector extends Block { protected final ConsumeForceProjectorPower consumePower; protected TextureRegion topRegion; - public ForceProjector(String name) { super(name); update = true; @@ -76,6 +76,16 @@ public class ForceProjector extends Block { stats.add(BlockStat.boostEffect, phaseRadiusBoost/tilesize, StatUnit.blocks); } + @Override + public void drawPlace(int x, int y, int rotation, boolean valid){ + super.drawPlace(x, y, rotation, valid); + + Draw.color(Pal.accent); + Lines.stroke(1f); + Lines.poly(x * tilesize, y * tilesize, 6, radius); + Draw.color(); + } + @Override public void update(Tile tile){ ForceEntity entity = tile.entity(); @@ -112,13 +122,13 @@ public class ForceProjector extends Block { if(entity.power.satisfaction < relativePowerDraw){ entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.15f); - entity.power.satisfaction = .0f; + entity.power.satisfaction = 0f; if(entity.warmup <= 0.09f){ entity.broken = true; } }else{ entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.1f); - entity.power.satisfaction -= Math.min(entity.power.satisfaction, relativePowerDraw); + entity.power.satisfaction -= Math.min(entity.power.satisfaction, relativePowerDraw*Time.delta()); } if(entity.buildup > 0){ @@ -261,6 +271,19 @@ public class ForceProjector extends Block { Draw.color(); } + public void drawSimple(){ + if(realRadius(entity) < 0.5f) return;; + + float rad = realRadius(entity); + + Draw.color(Pal.accent); + Draw.alpha(0.09f + 0.08f * entity.hit); + Fill.poly(x, y, 6, rad); + Draw.alpha(1f); + Lines.poly(x, y, 6, rad); + Draw.color(); + } + @Override public EntityGroup targetGroup(){ return shieldGroup; diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Separator.java b/core/src/io/anuke/mindustry/world/blocks/production/Separator.java index 4600ad7e2f..65a3f90045 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Separator.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Separator.java @@ -39,7 +39,7 @@ public class Separator extends Block{ hasItems = true; hasLiquids = true; - liquidRegion = reg("liquid"); + liquidRegion = reg("-liquid"); } @Override