Fog building hiding

This commit is contained in:
Anuken
2022-02-19 20:34:55 -05:00
parent 66a806c304
commit 99b01f3a3c
11 changed files with 90 additions and 17 deletions

View File

@@ -9,8 +9,10 @@ import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*;
import mindustry.world.*;
@@ -81,7 +83,11 @@ public class BlockRenderer{
updateFloors.add(new UpdateRenderState(tile, tile.floor()));
}
if(tile.block().hasShadow){
if(tile.build != null && (tile.team() == player.team() || !state.rules.fog)){
tile.build.wasVisible = true;
}
if(tile.block().hasShadow && (tile.build == null || tile.build.wasVisible)){
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
}
@@ -99,7 +105,14 @@ public class BlockRenderer{
});
Events.on(TileChangeEvent.class, event -> {
shadowEvents.add(event.tile);
boolean visible = event.tile.build == null || event.tile.build.inFogTo(Vars.player.team());
if(event.tile.build != null){
event.tile.build.wasVisible = visible;
}
if(visible){
shadowEvents.add(event.tile);
}
int avgx = (int)(camera.position.x / tilesize);
int avgy = (int)(camera.position.y / tilesize);
@@ -265,7 +278,7 @@ public class BlockRenderer{
for(Tile tile : shadowEvents){
//draw white/shadow color depending on blend
Draw.color(!tile.block().hasShadow ? Color.white : blendShadowColor);
Draw.color((!tile.block().hasShadow || (state.rules.fog && tile.build != null && !tile.build.wasVisible)) ? Color.white : blendShadowColor);
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
@@ -371,6 +384,7 @@ public class BlockRenderer{
}
public void drawBlocks(){
Team pteam = player.team();
drawDestroyed();
@@ -382,7 +396,9 @@ public class BlockRenderer{
Draw.z(Layer.block);
if(block != Blocks.air){
boolean visible = (build == null || !build.inFogTo(pteam)/* || build.wasVisible*/);
if(block != Blocks.air && visible){
block.drawBase(tile);
Draw.reset();
Draw.z(Layer.block);
@@ -394,6 +410,8 @@ public class BlockRenderer{
}
if(build != null){
if(!build.wasVisible) updateShadow(build);
build.wasVisible = true;
if(build.damaged()){
Draw.z(Layer.blockCracks);
@@ -411,6 +429,11 @@ public class BlockRenderer{
}
}
Draw.reset();
}else if(!visible){
//TODO here is the question: should buildings you lost sight of remain rendered? if so, how should this information be stored?
//comment lines below for buggy persistence
if(build.wasVisible) updateShadow(build);
build.wasVisible = false;
}
}
@@ -443,6 +466,16 @@ public class BlockRenderer{
}
}
void updateShadow(Building build){
int size = build.block.size, of = build.block.sizeOffset, tx = build.tile.x, ty = build.tile.y;
for(int x = 0; x < size; x++){
for(int y = 0; y < size; y++){
shadowEvents.add(world.tile(x + tx + of, y + ty + of));
}
}
}
static class BlockQuadtree extends QuadTree<Tile>{
public BlockQuadtree(Rect bounds){

View File

@@ -97,7 +97,8 @@ public class EnvRenderers{
tex.setWrap(TextureWrap.repeat);
}
Draw.z(Layer.weather - 1);
//TODO layer looks better? should not be conditional
Draw.z(state.rules.fog ? Layer.fogOfWar + 1 : Layer.weather - 1);
Weather.drawNoiseLayers(tex, Color.scarlet, 1000f, 0.23f, 0.4f, 1f, 1f, 0f,
4, -1.3f, 0.7f, 0.8f, 0.9f);
Draw.reset();

View File

@@ -18,9 +18,6 @@ import static mindustry.Vars.*;
/** Highly experimental fog-of-war renderer. */
public class FogRenderer{
public static final Color
staticColor = new Color(0f, 0f, 0f, 1f),
dynamicColor = new Color(0f, 0f, 0f, 0.5f);
private FrameBuffer staticFog = new FrameBuffer(), dynamicFog = new FrameBuffer();
private LongSeq events = new LongSeq();
private Rect rect = new Rect();
@@ -114,17 +111,18 @@ public class FogRenderer{
dynamicFog.getTexture().setFilter(TextureFilter.linear);
Draw.shader(Shaders.fog);
Draw.color(dynamicColor);
Draw.color(state.rules.dynamicColor);
Draw.fbo(dynamicFog.getTexture(), world.width(), world.height(), tilesize);
Draw.color(staticColor);
Draw.color(state.rules.staticColor);
Draw.fbo(staticFog.getTexture(), world.width(), world.height(), tilesize);
Draw.shader();
}
void poly(Rect check, float x, float y, float rad){
if(check.overlaps(x - rad, y - rad, rad * 2f, rad * 2f)){
Fill.poly(x, y, 20, rad);
}
//todo clipping messes up the minimap
//if(check.overlaps(x - rad, y - rad, rad * 2f, rad * 2f)){
Fill.poly(x, y, 20, rad);
//}
}
void renderEvent(long e){

View File

@@ -155,11 +155,12 @@ public class MinimapRenderer{
Tmp.tr1.set(dynamicTex);
Tmp.tr1.set(region.u, 1f - region.v, region.u2, 1f - region.v2);
Draw.color(FogRenderer.dynamicColor);
Draw.color(state.rules.dynamicColor);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Tmp.tr1.texture = staticTex;
Draw.color(FogRenderer.staticColor);
//must be black to fit with borders
Draw.color(0f, 0f, 0f, state.rules.staticColor.a);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Draw.color();