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