From 5799e6f5679c9278345cf0108363428742cd9fef Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 3 Jul 2019 10:41:16 -0400 Subject: [PATCH] Laser optimization --- .../src/io/anuke/mindustry/core/Renderer.java | 2 +- .../mindustry/entities/traits/MinerTrait.java | 5 ++++- .../io/anuke/mindustry/graphics/Layer.java | 4 +--- .../io/anuke/mindustry/graphics/Shapes.java | 16 +++++++--------- .../world/blocks/power/PowerNode.java | 19 +++++++++++++++---- .../world/blocks/units/RepairPoint.java | 11 +++++++---- 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 870a36e623..f618068a2c 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -190,7 +190,7 @@ public class Renderer implements ApplicationListener{ drawAllTeams(false); blocks.skipLayer(Layer.turret); - blocks.drawBlocks(Layer.laser); + blocks.drawBlocks(Layer.power); drawFlyerShadows(); diff --git a/core/src/io/anuke/mindustry/entities/traits/MinerTrait.java b/core/src/io/anuke/mindustry/entities/traits/MinerTrait.java index c8275f6463..8cb8919c05 100644 --- a/core/src/io/anuke/mindustry/entities/traits/MinerTrait.java +++ b/core/src/io/anuke/mindustry/entities/traits/MinerTrait.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.entities.traits; +import io.anuke.arc.Core; import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.*; @@ -15,6 +16,8 @@ import io.anuke.mindustry.world.Tile; import static io.anuke.mindustry.Vars.*; public interface MinerTrait extends Entity{ + TextureRegion mineLaserRegion = Core.atlas.find("minelaser"); + TextureRegion mineLaserEndRegion = Core.atlas.find("minelaser-end"); /** Returns the range at which this miner can mine blocks.*/ default float getMiningRange(){ @@ -89,7 +92,7 @@ public interface MinerTrait extends Entity{ Draw.color(Color.LIGHT_GRAY, Color.WHITE, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl)); - Shapes.laser("minelaser", "minelaser-end", px, py, ex, ey, 0.75f); + Shapes.laser(mineLaserRegion, mineLaserEndRegion, px, py, ex, ey, 0.75f); if(unit instanceof Player && ((Player)unit).isLocal){ Lines.stroke(1f, Pal.accent); diff --git a/core/src/io/anuke/mindustry/graphics/Layer.java b/core/src/io/anuke/mindustry/graphics/Layer.java index f84f6aa3c2..206da3d6e0 100644 --- a/core/src/io/anuke/mindustry/graphics/Layer.java +++ b/core/src/io/anuke/mindustry/graphics/Layer.java @@ -10,7 +10,5 @@ public enum Layer{ /** "High" blocks, like turrets. */ turret, /** Power lasers. */ - power, - /** Extra lasers, like healing turrets. */ - laser + power } diff --git a/core/src/io/anuke/mindustry/graphics/Shapes.java b/core/src/io/anuke/mindustry/graphics/Shapes.java index 7e629d347b..dc638b476f 100644 --- a/core/src/io/anuke/mindustry/graphics/Shapes.java +++ b/core/src/io/anuke/mindustry/graphics/Shapes.java @@ -7,24 +7,22 @@ import io.anuke.arc.util.Tmp; public class Shapes{ - public static void laser(String line, String edge, float x, float y, float x2, float y2, float scale){ + public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float scale){ laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), scale); } - public static void laser(String line, String edge, float x, float y, float x2, float y2){ + public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2){ laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), 1f); } - public static void laser(String line, String edge, float x, float y, float x2, float y2, float rotation, float scale){ - TextureRegion region = Core.atlas.find(edge); - + public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float rotation, float scale){ Tmp.v1.trns(rotation, 8f * scale * Draw.scl); - Draw.rect(Core.atlas.find(edge), x, y, region.getWidth() * scale * Draw.scl, region.getHeight() * scale * Draw.scl, rotation + 180); - Draw.rect(Core.atlas.find(edge), x2, y2, region.getWidth() * scale * Draw.scl, region.getHeight() * scale * Draw.scl, rotation); + Draw.rect(edge, x, y, edge.getWidth() * scale * Draw.scl, edge.getHeight() * scale * Draw.scl, rotation + 180); + Draw.rect(edge, x2, y2, edge.getWidth() * scale * Draw.scl, edge.getHeight() * scale * Draw.scl, rotation); - Lines.stroke(12f * scale); - Lines.line(Core.atlas.find(line), x + Tmp.v1.x, y + Tmp.v1.y, x2 - Tmp.v1.x, y2 - Tmp.v1.y, CapStyle.none, 0f); + Lines.stroke(10f * scale); + Lines.line(line, x + Tmp.v1.x, y + Tmp.v1.y, x2 - Tmp.v1.x, y2 - Tmp.v1.y, CapStyle.none, 0f); Lines.stroke(1f); } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index af73a01302..0e7044d983 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -4,8 +4,7 @@ import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; import io.anuke.arc.Core; import io.anuke.arc.graphics.Color; -import io.anuke.arc.graphics.g2d.Draw; -import io.anuke.arc.graphics.g2d.Lines; +import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.Angles; import io.anuke.arc.math.Mathf; import io.anuke.arc.math.geom.Intersector; @@ -30,6 +29,7 @@ public class PowerNode extends PowerBlock{ protected Vector2 t1 = new Vector2(); protected Vector2 t2 = new Vector2(); + protected TextureRegion laser, laserEnd; protected float laserRange = 6; protected int maxNodes = 3; @@ -86,6 +86,14 @@ public class PowerNode extends PowerBlock{ } } + @Override + public void load(){ + super.load(); + + laser = Core.atlas.find("laser"); + laserEnd = Core.atlas.find("laser-end"); + } + @Override public void setBars(){ super.setBars(); @@ -204,7 +212,7 @@ public class PowerNode extends PowerBlock{ for(int i = 0; i < entity.power.links.size; i++){ Tile link = world.tile(entity.power.links.get(i)); - if(linkValid(tile, link)){ + if(link != null){ drawLaser(tile, link); } } @@ -255,8 +263,11 @@ public class PowerNode extends PowerBlock{ Draw.color(Pal.powerLight, Color.WHITE, Mathf.absin(Time.time(), 8f, 0.3f) + 0.2f); //Lines.stroke(2f); //Lines.line(x1, y1, x2, y2); + Lines.stroke(3f); + Lines.line(x1, y1, x2, y2); + Draw.reset(); - Shapes.laser("laser", "laser-end", x1, y1, x2, y2, 0.6f); + //Shapes.laser(laser, laserEnd, x1, y1, x2, y2, 0.6f); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java b/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java index 7eb2b6b40f..a1fae03e22 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java @@ -25,6 +25,7 @@ public class RepairPoint extends Block{ protected float repairSpeed = 0.3f; protected float powerUse; protected TextureRegion baseRegion; + protected TextureRegion laser, laserEnd; public RepairPoint(String name){ super(name); @@ -32,7 +33,7 @@ public class RepairPoint extends Block{ solid = true; flags = EnumSet.of(BlockFlag.repair); layer = Layer.turret; - layer2 = Layer.laser; + layer2 = Layer.power; hasPower = true; outlineIcon = true; } @@ -42,6 +43,8 @@ public class RepairPoint extends Block{ super.load(); baseRegion = Core.atlas.find(name + "-base"); + laser = Core.atlas.find("laser"); + laserEnd = Core.atlas.find("laser-end"); } @Override @@ -79,9 +82,9 @@ public class RepairPoint extends Block{ float len = 5f; Draw.color(Color.valueOf("e8ffd7")); - Shapes.laser("laser", "laser-end", - tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len), - entity.target.x, entity.target.y, entity.strength); + Shapes.laser(laser, laserEnd, + tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len), + entity.target.x, entity.target.y, entity.strength); Draw.color(); } }