diff --git a/core/src/mindustry/game/FogControl.java b/core/src/mindustry/game/FogControl.java index 9a53f82565..48183ae36a 100644 --- a/core/src/mindustry/game/FogControl.java +++ b/core/src/mindustry/game/FogControl.java @@ -178,7 +178,13 @@ public class FogControl implements CustomChunk{ //add building updates for(var build : indexer.getFlagged(team.team, BlockFlag.hasFogRadius)){ - dynamicEventQueue.add(FogEvent.get(build.tileX(), build.tileY(), build.block.fogRadius, 0)); + unitEventQueue.add(FogEvent.get(build.tileX(), build.tileY(), build.block.fogRadius, 0)); + } + + //on the client, let the renderer know of all the fog sources + //TODO this runs at a lower FPS and hence may look bad...? + if(!headless && team.team == Vars.player.team()){ + renderer.fog.flushDynamic(unitEventQueue); } //add unit updates diff --git a/core/src/mindustry/graphics/FogRenderer.java b/core/src/mindustry/graphics/FogRenderer.java index 9de4b25b44..969cdd0b4b 100644 --- a/core/src/mindustry/graphics/FogRenderer.java +++ b/core/src/mindustry/graphics/FogRenderer.java @@ -17,8 +17,10 @@ import static mindustry.Vars.*; /** Highly experimental fog-of-war renderer. */ public class FogRenderer{ - private FrameBuffer staticFog = new FrameBuffer(); + private FrameBuffer staticFog = new FrameBuffer(), dynamicFog = new FrameBuffer(); private LongSeq events = new LongSeq(); + private LongSeq dynamics = new LongSeq(); + private boolean dynamicUpdate = false; private Rect rect = new Rect(); private @Nullable Team lastTeam; @@ -33,30 +35,56 @@ public class FogRenderer{ events.add(event); } + public void flushDynamic(LongSeq seq){ + dynamics.clear(); + dynamics.addAll(seq); + dynamicUpdate = true; + } + public Texture getStaticTexture(){ return staticFog.getTexture(); } + public Texture getDynamicTexture(){ + return dynamicFog.getTexture(); + } + public void drawFog(){ //there is no fog. if(fogControl.getDiscovered(player.team()) == null) return; //resize if world size changes - boolean clear = staticFog.resizeCheck(world.width(), world.height()); + boolean + clearStatic = staticFog.resizeCheck(world.width(), world.height()), + clearDynamic = dynamicFog.resizeCheck(world.width(), world.height()); if(player.team() != lastTeam){ copyFromCpu(); lastTeam = player.team(); - clear = false; + clearStatic = false; + dynamicUpdate = true; } - //grab events - if(clear || events.size > 0){ + if(clearDynamic || dynamicUpdate){ + dynamicUpdate = false; + + Draw.proj(0, 0, staticFog.getWidth(), staticFog.getHeight()); + dynamicFog.begin(Color.black); + ScissorStack.push(rect.set(1, 1, staticFog.getWidth() - 2, staticFog.getHeight() - 2)); + + //TODO render all (clipped) view circles + + ScissorStack.pop(); + Draw.proj(Core.camera); + } + + //grab static events + if(clearStatic || events.size > 0){ //set projection to whole map Draw.proj(0, 0, staticFog.getWidth(), staticFog.getHeight()); - //if the buffer resized, it contains garbage now, clear it. - if(clear){ + //if the buffer resized, it contains garbage now, clearStatic it. + if(clearStatic){ staticFog.begin(Color.black); }else{ staticFog.begin(); diff --git a/tools/build.gradle b/tools/build.gradle index 03125ddd07..057b4a2c47 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -14,7 +14,7 @@ import arc.struct.Seq import arc.util.Http import arc.util.Log import arc.util.OS -import arc.util.async.Threads +import arc.util.Threads import arc.util.io.PropertiesUtils import arc.util.io.Streams