Laser optimization

This commit is contained in:
Anuken
2019-07-03 10:41:16 -04:00
parent 310e8afc25
commit 5799e6f567
6 changed files with 35 additions and 22 deletions

View File

@@ -190,7 +190,7 @@ public class Renderer implements ApplicationListener{
drawAllTeams(false);
blocks.skipLayer(Layer.turret);
blocks.drawBlocks(Layer.laser);
blocks.drawBlocks(Layer.power);
drawFlyerShadows();

View File

@@ -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);

View File

@@ -10,7 +10,5 @@ public enum Layer{
/** "High" blocks, like turrets. */
turret,
/** Power lasers. */
power,
/** Extra lasers, like healing turrets. */
laser
power
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}