Support for team-only lighting

This commit is contained in:
Anuken
2020-06-15 13:54:02 -04:00
parent b5660a50ca
commit 7001ad09cb
24 changed files with 90 additions and 75 deletions

View File

@@ -27,11 +27,12 @@ public class BlockRenderer implements Disposable{
public final FloorRenderer floor = new FloorRenderer();
private Seq<Tile> tileview = new Seq<>(false, initialRequests, Tile.class);
private Seq<Tile> lightview = new Seq<>(false, initialRequests, Tile.class);
private int lastCamX, lastCamY, lastRangeX, lastRangeY;
private float brokenFade = 0f;
private FrameBuffer shadows = new FrameBuffer();
private FrameBuffer fog = new FrameBuffer();
private FrameBuffer dark = new FrameBuffer();
private Seq<Tilec> outArray2 = new Seq<>();
private Seq<Tile> shadowEvents = new Seq<>();
private IntSet processedEntities = new IntSet();
@@ -61,11 +62,11 @@ public class BlockRenderer implements Disposable{
Draw.color();
shadows.end();
fog.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
fog.resize(world.width(), world.height());
fog.begin();
dark.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
dark.resize(world.width(), world.height());
dark.begin();
Core.graphics.clear(Color.white);
Draw.proj().setOrtho(0, 0, fog.getWidth(), fog.getHeight());
Draw.proj().setOrtho(0, 0, dark.getWidth(), dark.getHeight());
for(Tile tile : world.tiles){
float darkness = world.getDarkness(tile.x, tile.y);
@@ -78,7 +79,7 @@ public class BlockRenderer implements Disposable{
Draw.flush();
Draw.color();
fog.end();
dark.end();
});
Events.on(TileChangeEvent.class, event -> {
@@ -96,18 +97,8 @@ public class BlockRenderer implements Disposable{
}
public void drawDarkness(){
float ww = world.width() * tilesize, wh = world.height() * tilesize;
float x = camera.position.x + tilesize / 2f, y = camera.position.y + tilesize / 2f;
float u = (x - camera.width / 2f) / ww,
v = (y - camera.height / 2f) / wh,
u2 = (x + camera.width / 2f) / ww,
v2 = (y + camera.height / 2f) / wh;
Tmp.tr1.set(fog.getTexture());
Tmp.tr1.set(u, v2, u2, v);
Draw.shader(Shaders.fog);
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
Draw.shader(Shaders.darkness);
Draw.fbo(dark, world.width(), world.height(), tilesize);
Draw.shader();
}
@@ -167,7 +158,7 @@ public class BlockRenderer implements Disposable{
Tmp.tr1.set(shadows.getTexture());
Tmp.tr1.set(u, v2, u2, v);
Draw.shader(Shaders.fog);
Draw.shader(Shaders.darkness);
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
Draw.shader();
}
@@ -187,6 +178,7 @@ public class BlockRenderer implements Disposable{
}
tileview.clear();
lightview.clear();
processedEntities.clear();
int minx = Math.max(avgx - rangex - expandr, 0);
@@ -208,6 +200,11 @@ public class BlockRenderer implements Disposable{
if(tile.entity != null) processedEntities.add(tile.entity.id());
}
//lights are drawn even in the expanded range
if(tile.entity != null){
lightview.add(tile);
}
if(tile.entity != null && tile.entity.power() != null && tile.entity.power().links.size > 0){
for(Tilec other : tile.entity.getPowerConnections(outArray2)){
if(other.block() instanceof PowerNode){ //TODO need a generic way to render connections!
@@ -228,6 +225,7 @@ public class BlockRenderer implements Disposable{
public void drawBlocks(){
drawDestroyed();
//draw most tile stuff
for(int i = 0; i < tileview.size; i++){
Tile tile = tileview.items[i];
Block block = tile.block();
@@ -250,8 +248,6 @@ public class BlockRenderer implements Disposable{
Draw.z(Layer.block);
}
entity.drawLight();
if(displayStatus && block.consumes.any()){
entity.drawStatus();
}
@@ -259,13 +255,23 @@ public class BlockRenderer implements Disposable{
Draw.reset();
}
}
//draw lights
for(int i = 0; i < lightview.size; i++){
Tile tile = lightview.items[i];
Tilec entity = tile.entity;
if(entity != null){
entity.drawLight();
}
}
}
@Override
public void dispose(){
shadows.dispose();
fog.dispose();
shadows = fog = null;
dark.dispose();
shadows = dark = null;
floor.dispose();
}
}

View File

@@ -8,6 +8,7 @@ import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -48,24 +49,28 @@ public class Drawf{
return z;
}
public static void light(float x, float y, float radius, Color color, float opacity){
renderer.lights.add(x, y, radius, color, opacity);
public static void light(Team team, float x, float y, float radius, Color color, float opacity){
if(allowLight(team)) renderer.lights.add(x, y, radius, color, opacity);
}
public static void light(Position pos, float radius, Color color, float opacity){
light(pos.getX(), pos.getY(), radius, color, opacity);
public static void light(Team team, Position pos, float radius, Color color, float opacity){
light(team, pos.getX(), pos.getY(), radius, color, opacity);
}
public static void light(float x, float y, TextureRegion region, Color color, float opacity){
renderer.lights.add(x, y, region, color, opacity);
public static void light(Team team, float x, float y, TextureRegion region, Color color, float opacity){
if(allowLight(team)) renderer.lights.add(x, y, region, color, opacity);
}
public static void light(float x, float y, float x2, float y2){
renderer.lights.line(x, y, x2, y2, 30, Color.orange, 0.3f);
public static void light(Team team, float x, float y, float x2, float y2){
if(allowLight(team)) renderer.lights.line(x, y, x2, y2, 30, Color.orange, 0.3f);
}
public static void light(float x, float y, float x2, float y2, float stroke, Color tint, float alpha){
renderer.lights.line(x, y, x2, y2, stroke, tint, alpha);
public static void light(Team team, float x, float y, float x2, float y2, float stroke, Color tint, float alpha){
if(allowLight(team)) renderer.lights.line(x, y, x2, y2, stroke, tint, alpha);
}
private static boolean allowLight(Team team){
return team == Team.derelict || team == Vars.player.team() || state.rules.enemyLights;
}
public static void selected(Tilec tile, Color color){
@@ -155,15 +160,15 @@ public class Drawf{
Draw.color();
}
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(Team team, TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float scale){
laser(team, line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), scale);
}
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(Team team, TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2){
laser(team, line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), 1f);
}
public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float rotation, float scale){
public static void laser(Team team, 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(edge, x, y, edge.getWidth() * scale * Draw.scl, edge.getHeight() * scale * Draw.scl, rotation + 180);
@@ -175,7 +180,7 @@ public class Drawf{
Lines.precise(false);
Lines.stroke(1f);
Drawf.light(x, y, x2, y2);
light(team, x, y, x2, y2);
}
public static void tri(float x, float y, float width, float length, float rotation){

View File

@@ -18,7 +18,7 @@ public class Shaders{
public static BlockBuild blockbuild;
public static @Nullable ShieldShader shield;
public static UnitBuild build;
public static FogShader fog;
public static DarknessShader darkness;
public static LightShader light;
public static SurfaceShader water, tar, slag;
public static PlanetShader planet;
@@ -38,7 +38,7 @@ public class Shaders{
t.printStackTrace();
}
build = new UnitBuild();
fog = new FogShader();
darkness = new DarknessShader();
light = new LightShader();
water = new SurfaceShader("water");
tar = new SurfaceShader("tar");
@@ -131,9 +131,9 @@ public class Shaders{
}
public static class FogShader extends LoadShader{
public FogShader(){
super("fog", "default");
public static class DarknessShader extends LoadShader{
public DarknessShader(){
super("darkness", "default");
}
}