From ca10ab02745530bda7c3386ff18d850e91ed248e Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 24 Jun 2018 16:20:42 -0400 Subject: [PATCH] Increased fog view range, added tile fog discovery --- core/assets/shaders/fog.fragment | 3 ++ .../src/io/anuke/mindustry/entities/Unit.java | 2 +- .../anuke/mindustry/graphics/FogRenderer.java | 39 ++++++++++++++++++- .../io/anuke/mindustry/io/MapTileData.java | 6 +-- core/src/io/anuke/mindustry/ui/Minimap.java | 2 - core/src/io/anuke/mindustry/world/Block.java | 3 +- .../world/blocks/defense/turrets/Turret.java | 7 +++- .../world/blocks/storage/CoreBlock.java | 1 + 8 files changed, 53 insertions(+), 10 deletions(-) diff --git a/core/assets/shaders/fog.fragment b/core/assets/shaders/fog.fragment index 8e0b8942bc..8955cc9665 100644 --- a/core/assets/shaders/fog.fragment +++ b/core/assets/shaders/fog.fragment @@ -15,5 +15,8 @@ void main() { color.a = 1.0 - color.r; color.rgb = vec3(0.0); color.a = float(int(color.a / round)) * round; + if(color.a >= 1.0 - round){ + color.a = 1.0; + } gl_FragColor = color * v_color; } diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index ddf69ba6c0..f570b160f9 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -298,7 +298,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } public float getViewDistance(){ - return 60f; + return 130f; } public abstract TextureRegion getIconRegion(); diff --git a/core/src/io/anuke/mindustry/graphics/FogRenderer.java b/core/src/io/anuke/mindustry/graphics/FogRenderer.java index 147377080b..824402d710 100644 --- a/core/src/io/anuke/mindustry/graphics/FogRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/FogRenderer.java @@ -5,15 +5,21 @@ import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.FrameBuffer; +import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Disposable; import io.anuke.mindustry.entities.Unit; +import io.anuke.mindustry.game.EventType.TileChangeEvent; import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent; +import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Graphics; import io.anuke.ucore.entities.EntityDraw; import io.anuke.ucore.graphics.ClipSpriteBatch; import io.anuke.ucore.graphics.Draw; +import io.anuke.ucore.graphics.Fill; + +import java.nio.ByteBuffer; import static io.anuke.mindustry.Vars.*; @@ -21,6 +27,8 @@ import static io.anuke.mindustry.Vars.*; public class FogRenderer implements Disposable{ private TextureRegion region = new TextureRegion(); private FrameBuffer buffer; + private ByteBuffer pixelBuffer = ByteBuffer.allocateDirect(4); + private Array changeQueue = new Array<>(); public FogRenderer(){ Events.on(WorldLoadGraphicsEvent.class, () -> { @@ -29,9 +37,25 @@ public class FogRenderer implements Disposable{ //clear buffer to black buffer.begin(); - Graphics.clear(Color.BLACK); + Graphics.clear(0, 0, 0, 1f); buffer.end(); + + for (int x = 0; x < world.width(); x++) { + for (int y = 0; y < world.height(); y++) { + Tile tile = world.tile(x, y); + + if(tile.getTeam() == players[0].getTeam() && tile.block().viewRange > 0){ + changeQueue.add(tile); + } + } + } }); + + Events.on(TileChangeEvent.class, tile -> threads.runGraphics(() -> { + if(tile.getTeam() == players[0].getTeam() && tile.block().viewRange > 0){ + changeQueue.add(tile); + } + })); } public void draw(){ @@ -58,12 +82,25 @@ public class FogRenderer implements Disposable{ Draw.color(Color.WHITE); buffer.begin(); + + //TODO use this for per-tile visibility to show/hide units + //pixelBuffer.position(0); + //Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1); + //Gdx.gl.glReadPixels(world.width()/2, world.height()/2 + 20, 1, 1, GL20.GL_RGB, GL20.GL_UNSIGNED_BYTE, pixelBuffer); + //Log.info(pixelBuffer.get(0)); + Graphics.begin(); EntityDraw.setClip(false); renderer.drawAndInterpolate(playerGroup, player -> player.getTeam() == players[0].getTeam(), Unit::drawView); renderer.drawAndInterpolate(unitGroups[players[0].getTeam().ordinal()], unit -> true, Unit::drawView); + for(Tile tile : changeQueue){ + float viewRange = tile.block().viewRange; + if(viewRange < 0) continue; + Fill.circle(tile.drawx(), tile.drawy(), tile.block().viewRange); + } + EntityDraw.setClip(true); Graphics.end(); buffer.end(); diff --git a/core/src/io/anuke/mindustry/io/MapTileData.java b/core/src/io/anuke/mindustry/io/MapTileData.java index 84579c40f7..b3fb92e4ab 100644 --- a/core/src/io/anuke/mindustry/io/MapTileData.java +++ b/core/src/io/anuke/mindustry/io/MapTileData.java @@ -61,14 +61,12 @@ public class MapTileData { /**Write a byte to a specific position.*/ public void write(int x, int y, DataPosition position, byte data){ - buffer.position((x + width * y) * TILE_SIZE + position.ordinal()); - buffer.put(data); + buffer.put((x + width * y) * TILE_SIZE + position.ordinal(), data); } /**Gets a byte at a specific position.*/ public byte read(int x, int y, DataPosition position){ - buffer.position((x + width * y) * TILE_SIZE + position.ordinal()); - return buffer.get(); + return buffer.get((x + width * y) * TILE_SIZE + position.ordinal()); } /**Reads and returns the next tile data.*/ diff --git a/core/src/io/anuke/mindustry/ui/Minimap.java b/core/src/io/anuke/mindustry/ui/Minimap.java index ec1e0b194b..5a269ffc85 100644 --- a/core/src/io/anuke/mindustry/ui/Minimap.java +++ b/core/src/io/anuke/mindustry/ui/Minimap.java @@ -33,8 +33,6 @@ public class Minimap extends Table { renderer.minimap().drawEntities(x, y, width, height); } - - renderer.fog().getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest); //draw.getRegion().setV(draw.getRegion().getV2()); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 9baa3b3811..5f1c9e3113 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -11,7 +11,6 @@ import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.Unit; import io.anuke.mindustry.entities.bullet.Bullet; -import io.anuke.mindustry.entities.effect.Decal; import io.anuke.mindustry.entities.effect.Puddle; import io.anuke.mindustry.entities.effect.RubbleDecal; import io.anuke.mindustry.game.Content; @@ -121,6 +120,8 @@ public class Block extends BaseBlock implements UnlockableContent{ public boolean consumesTap; /**The color of this block when displayed on the minimap or map preview.*/ public Color minimapColor = Color.CLEAR; + /**View range of this block type. Use a value < 0 to disable.*/ + public float viewRange = -1; public Block(String name) { this.name = name; diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java index 56fa978f6c..f6d17b3aaf 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java @@ -74,7 +74,12 @@ public abstract class Turret extends Block{ layer = Layer.turret; group = BlockGroup.turrets; } - + + @Override + public void init() { + viewRange = range; + } + @Override public void setStats(){ super.setStats(); diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index 1da2754a89..889af24eff 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -57,6 +57,7 @@ public class CoreBlock extends StorageBlock { size = 3; hasItems = true; itemCapacity = 1000; + viewRange = 200f; flags = EnumSet.of(BlockFlag.resupplyPoint, BlockFlag.target); }