Increased fog view range, added tile fog discovery

This commit is contained in:
Anuken
2018-06-24 16:20:42 -04:00
parent 41e611d7db
commit ca10ab0274
8 changed files with 53 additions and 10 deletions

View File

@ -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;
}

View File

@ -298,7 +298,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
public float getViewDistance(){
return 60f;
return 130f;
}
public abstract TextureRegion getIconRegion();

View File

@ -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<Tile> 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();

View File

@ -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.*/

View File

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

View File

@ -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;

View File

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

View File

@ -57,6 +57,7 @@ public class CoreBlock extends StorageBlock {
size = 3;
hasItems = true;
itemCapacity = 1000;
viewRange = 200f;
flags = EnumSet.of(BlockFlag.resupplyPoint, BlockFlag.target);
}