Lighting improvements
This commit is contained in:
@@ -9,10 +9,9 @@ import io.anuke.arc.graphics.glutils.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Teams.*;
|
||||
import io.anuke.mindustry.ui.Cicon;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import static io.anuke.arc.Core.camera;
|
||||
@@ -219,6 +218,9 @@ public class BlockRenderer implements Disposable{
|
||||
addRequest(tile, Layer.block);
|
||||
}
|
||||
|
||||
//TODO don't add at daytime / disabled lights
|
||||
addRequest(tile, Layer.lights);
|
||||
|
||||
if(block.expanded || !expanded){
|
||||
|
||||
if(block.layer != null){
|
||||
@@ -274,6 +276,9 @@ public class BlockRenderer implements Disposable{
|
||||
if(block.synthetic() && request.tile.getTeam() != player.getTeam()){
|
||||
block.drawTeam(request.tile);
|
||||
}
|
||||
|
||||
}else if(request.layer == Layer.lights){
|
||||
block.drawLight(request.tile);
|
||||
}else if(request.layer == block.layer){
|
||||
block.drawLayer(request.tile);
|
||||
}else if(request.layer == block.layer2){
|
||||
@@ -282,39 +287,6 @@ public class BlockRenderer implements Disposable{
|
||||
}
|
||||
}
|
||||
|
||||
public void drawTeamBlocks(Layer layer, Team team){
|
||||
int index = this.iterateidx;
|
||||
|
||||
for(; index < requestidx; index++){
|
||||
|
||||
if(index < requests.size && requests.get(index).layer.ordinal() > layer.ordinal()){
|
||||
break;
|
||||
}
|
||||
|
||||
BlockRequest req = requests.get(index);
|
||||
if(req.tile.getTeam() != team) continue;
|
||||
|
||||
Block block = req.tile.block();
|
||||
|
||||
if(req.layer == Layer.block){
|
||||
block.draw(req.tile);
|
||||
}else if(req.layer == block.layer){
|
||||
block.drawLayer(req.tile);
|
||||
}else if(req.layer == block.layer2){
|
||||
block.drawLayer2(req.tile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void skipLayer(Layer stopAt){
|
||||
for(; iterateidx < requestidx; iterateidx++){
|
||||
if(iterateidx < requests.size && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addRequest(Tile tile, Layer layer){
|
||||
if(requestidx >= requests.size){
|
||||
requests.add(new BlockRequest());
|
||||
|
||||
@@ -6,6 +6,8 @@ import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.util.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
public class Drawf{
|
||||
|
||||
public static void dashCircle(float x, float y, float rad, Color color){
|
||||
@@ -40,15 +42,6 @@ public class Drawf{
|
||||
square(x, y, radius, Pal.accent);
|
||||
}
|
||||
|
||||
/*
|
||||
public static void square(float x, float y, float radius){
|
||||
Lines.stroke(1f, Pal.gray);
|
||||
Lines.square(x, y - 1f, radius + 1f, 45);
|
||||
Lines.stroke(1f, Pal.accent);
|
||||
Lines.square(x, y, radius + 1f, 45);
|
||||
Draw.reset();
|
||||
}*/
|
||||
|
||||
public static void arrow(float x, float y, float x2, float y2, float length, float radius){
|
||||
float angle = Angles.angle(x, y, x2, y2);
|
||||
float space = 2f;
|
||||
@@ -81,6 +74,8 @@ public class Drawf{
|
||||
Lines.line(line, x + Tmp.v1.x, y + Tmp.v1.y, x2 - Tmp.v1.x, y2 - Tmp.v1.y, CapStyle.none, 0f);
|
||||
Lines.precise(false);
|
||||
Lines.stroke(1f);
|
||||
|
||||
renderer.lights.line(x, y, x2, y2);
|
||||
}
|
||||
|
||||
public static void tri(float x, float y, float width, float length, float rotation){
|
||||
|
||||
@@ -10,5 +10,7 @@ public enum Layer{
|
||||
/** "High" blocks, like turrets. */
|
||||
turret,
|
||||
/** Power lasers. */
|
||||
power
|
||||
power,
|
||||
/** Extra layer that's always on top.*/
|
||||
lights
|
||||
}
|
||||
|
||||
@@ -5,9 +5,13 @@ import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.graphics.glutils.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.*;
|
||||
|
||||
public class LightRenderer{
|
||||
private static final int scaling = 4;
|
||||
private float[] vertices = new float[24];
|
||||
private FrameBuffer buffer = new FrameBuffer(2, 2);
|
||||
private Array<Runnable> lights = new Array<>();
|
||||
|
||||
@@ -22,6 +26,134 @@ public class LightRenderer{
|
||||
});
|
||||
}
|
||||
|
||||
public void add(float x, float y, TextureRegion region, Color color, float opacity){
|
||||
add(() -> {
|
||||
Draw.color(color, opacity);
|
||||
Draw.rect(region, x, y);
|
||||
});
|
||||
}
|
||||
|
||||
public void line(float x, float y, float x2, float y2){
|
||||
add(() -> {
|
||||
Draw.color(Color.orange, 0.5f);
|
||||
|
||||
float stroke = 10f;
|
||||
float rot = Mathf.angleExact(x2 - x, y2 - y);
|
||||
TextureRegion ledge = Core.atlas.find("circle-end"), lmid = Core.atlas.find("circle-mid");
|
||||
|
||||
float color = Draw.getColor().toFloatBits();
|
||||
float u = lmid.getU();
|
||||
float v = lmid.getV2();
|
||||
float u2 = lmid.getU2();
|
||||
float v2 = lmid.getV();
|
||||
|
||||
|
||||
Vector2 v1 = Tmp.v1.trnsExact(rot + 90f, stroke);
|
||||
float lx1 = x - v1.x, ly1 = y - v1.y,
|
||||
lx2 = x + v1.x, ly2 = y + v1.y,
|
||||
lx3 = x2 + v1.x, ly3 = y2 + v1.y,
|
||||
lx4 = x2 - v1.x, ly4 = y2 - v1.y;
|
||||
|
||||
vertices[0] = lx1;
|
||||
vertices[1] = ly1;
|
||||
vertices[2] = color;
|
||||
vertices[3] = u;
|
||||
vertices[4] = v;
|
||||
vertices[5] = 0;
|
||||
|
||||
vertices[6] = lx2;
|
||||
vertices[7] = ly2;
|
||||
vertices[8] = color;
|
||||
vertices[9] = u;
|
||||
vertices[10] = v2;
|
||||
vertices[11] = 0;
|
||||
|
||||
vertices[12] = lx3;
|
||||
vertices[13] = ly3;
|
||||
vertices[14] = color;
|
||||
vertices[15] = u2;
|
||||
vertices[16] = v2;
|
||||
vertices[17] = 0;
|
||||
|
||||
vertices[18] = lx4;
|
||||
vertices[19] = ly4;
|
||||
vertices[20] = color;
|
||||
vertices[21] = u2;
|
||||
vertices[22] = v;
|
||||
vertices[23] = 0;
|
||||
|
||||
Draw.vert(ledge.getTexture(), vertices, 0, vertices.length);
|
||||
|
||||
|
||||
Vector2 v3 = Tmp.v2.trnsExact(rot, stroke);
|
||||
|
||||
u = ledge.getU();
|
||||
v = ledge.getV2();
|
||||
u2 = ledge.getU2();
|
||||
v2 = ledge.getV();
|
||||
|
||||
vertices[0] = lx4;
|
||||
vertices[1] = ly4;
|
||||
vertices[2] = color;
|
||||
vertices[3] = u;
|
||||
vertices[4] = v;
|
||||
vertices[5] = 0;
|
||||
|
||||
vertices[6] = lx3;
|
||||
vertices[7] = ly3;
|
||||
vertices[8] = color;
|
||||
vertices[9] = u;
|
||||
vertices[10] = v2;
|
||||
vertices[11] = 0;
|
||||
|
||||
vertices[12] = lx3 + v3.x;
|
||||
vertices[13] = ly3 + v3.y;
|
||||
vertices[14] = color;
|
||||
vertices[15] = u2;
|
||||
vertices[16] = v2;
|
||||
vertices[17] = 0;
|
||||
|
||||
vertices[18] = lx4 + v3.x;
|
||||
vertices[19] = ly4 + v3.y;
|
||||
vertices[20] = color;
|
||||
vertices[21] = u2;
|
||||
vertices[22] = v;
|
||||
vertices[23] = 0;
|
||||
|
||||
Draw.vert(ledge.getTexture(), vertices, 0, vertices.length);
|
||||
|
||||
vertices[0] = lx2;
|
||||
vertices[1] = ly2;
|
||||
vertices[2] = color;
|
||||
vertices[3] = u;
|
||||
vertices[4] = v;
|
||||
vertices[5] = 0;
|
||||
|
||||
vertices[6] = lx1;
|
||||
vertices[7] = ly1;
|
||||
vertices[8] = color;
|
||||
vertices[9] = u;
|
||||
vertices[10] = v2;
|
||||
vertices[11] = 0;
|
||||
|
||||
vertices[12] = lx1 - v3.x;
|
||||
vertices[13] = ly1 - v3.y;
|
||||
vertices[14] = color;
|
||||
vertices[15] = u2;
|
||||
vertices[16] = v2;
|
||||
vertices[17] = 0;
|
||||
|
||||
vertices[18] = lx2 - v3.x;
|
||||
vertices[19] = ly2 - v3.y;
|
||||
vertices[20] = color;
|
||||
vertices[21] = u2;
|
||||
vertices[22] = v;
|
||||
vertices[23] = 0;
|
||||
|
||||
Draw.vert(ledge.getTexture(), vertices, 0, vertices.length);
|
||||
});
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
if(buffer.getWidth() != Core.graphics.getWidth()/scaling || buffer.getHeight() != Core.graphics.getHeight()/scaling){
|
||||
buffer.resize(Core.graphics.getWidth()/scaling, Core.graphics.getHeight()/scaling);
|
||||
@@ -29,7 +161,7 @@ public class LightRenderer{
|
||||
|
||||
Draw.color();
|
||||
buffer.beginDraw(Color.clear);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.blend(Blending.normal);
|
||||
for(Runnable run : lights){
|
||||
run.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user