Removed sector camera clamp / Added map edge padding / Turret sprite fix
This commit is contained in:
@@ -4,13 +4,15 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||
import io.anuke.mindustry.maps.Sector;
|
||||
import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@@ -18,11 +20,13 @@ import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.CacheBatch;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.mapPadding;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
@@ -30,6 +34,8 @@ public class FloorRenderer{
|
||||
private final static int chunksize = 64;
|
||||
|
||||
private int gutter;
|
||||
private Tile gutterTile;
|
||||
private Tile gutterNearTile = new Tile(0, 0);
|
||||
private Chunk[][] cache;
|
||||
private CacheBatch cbatch;
|
||||
private IntSet drawnLayerSet = new IntSet();
|
||||
@@ -37,35 +43,26 @@ public class FloorRenderer{
|
||||
|
||||
public FloorRenderer(){
|
||||
Events.on(WorldLoadGraphicsEvent.class, this::clearTiles);
|
||||
}
|
||||
|
||||
static ShaderProgram createDefaultShader(){
|
||||
String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
|
||||
+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
|
||||
+ "uniform mat4 u_projTrans;\n" //
|
||||
+ "varying vec2 v_texCoords;\n" //
|
||||
+ "\n" //
|
||||
+ "void main()\n" //
|
||||
+ "{\n" //
|
||||
+ " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
|
||||
+ " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
|
||||
+ "}\n";
|
||||
String fragmentShader = "#ifdef GL_ES\n" //
|
||||
+ "#define LOWP lowp\n" //
|
||||
+ "precision mediump float;\n" //
|
||||
+ "#else\n" //
|
||||
+ "#define LOWP \n" //
|
||||
+ "#endif\n" //
|
||||
+ "varying vec2 v_texCoords;\n" //
|
||||
+ "uniform sampler2D u_texture;\n" //
|
||||
+ "void main()\n"//
|
||||
+ "{\n" //
|
||||
+ " gl_FragColor = texture2D(u_texture, v_texCoords);\n" //
|
||||
+ "}";
|
||||
gutterTile = new Tile(0, 0){
|
||||
@Override
|
||||
public Tile getNearby(int dx, int dy){
|
||||
Sector sec = world.getSector();
|
||||
GenResult result = world.generator().generateTile(sec.x, sec.y, x + dx, y + dy);
|
||||
gutterNearTile.x = (short)(x + dx);
|
||||
gutterNearTile.y = (short)(y + dy);
|
||||
gutterNearTile.setElevation(result.elevation);
|
||||
gutterNearTile.setFloor((Floor)result.floor);
|
||||
return gutterNearTile;
|
||||
}
|
||||
|
||||
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
|
||||
if(!shader.isCompiled()) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
|
||||
return shader;
|
||||
@Override
|
||||
public Tile getNearby(int rotation){
|
||||
int dx = Geometry.d4[rotation].x;
|
||||
int dy = Geometry.d4[rotation].y;
|
||||
return getNearby(dx, dy);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void drawFloor(){
|
||||
@@ -198,11 +195,22 @@ public class FloorRenderer{
|
||||
|
||||
ObjectSet<CacheLayer> used = new ObjectSet<>();
|
||||
|
||||
Sector sector = world.getSector();
|
||||
|
||||
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
|
||||
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
|
||||
Tile tile = world.tile(tilex - gutter, tiley - gutter);
|
||||
if(tile != null){
|
||||
used.add(tile.floor().cacheLayer);
|
||||
Floor floor = null;
|
||||
|
||||
if(tile == null && sector != null){
|
||||
GenResult result = world.generator().generateTile(sector.x, sector.y, tilex - gutter, tiley - gutter);
|
||||
floor = (Floor) result.floor;
|
||||
}else if(tile != null){
|
||||
floor = tile.floor();
|
||||
}
|
||||
|
||||
if(floor != null){
|
||||
used.add(floor.cacheLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,18 +225,34 @@ public class FloorRenderer{
|
||||
Graphics.useBatch(cbatch);
|
||||
cbatch.begin();
|
||||
|
||||
Sector sector = world.getSector();
|
||||
|
||||
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
|
||||
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
|
||||
Tile tile = world.tile(tilex - gutter, tiley - gutter);
|
||||
Floor floor;
|
||||
|
||||
if(tile == null){
|
||||
Fill.rect((tilex - gutter) * tilesize, (tiley - gutter) * tilesize, tilesize, tilesize);
|
||||
continue;
|
||||
if(sector != null){
|
||||
GenResult result = world.generator().generateTile(sector.x, sector.y, tilex - gutter, tiley - gutter);
|
||||
floor = (Floor)result.floor;
|
||||
gutterTile.setFloor(floor);
|
||||
gutterTile.x = (short)(tilex - gutter);
|
||||
gutterTile.y = (short)(tiley - gutter);
|
||||
gutterTile.setElevation(result.elevation);
|
||||
gutterTile.updateOcclusion();
|
||||
tile = gutterTile;
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}else{
|
||||
floor = tile.floor();
|
||||
}
|
||||
|
||||
if(tile.floor().cacheLayer == layer){
|
||||
tile.floor().draw(tile);
|
||||
}else if(tile.floor().cacheLayer.ordinal() < layer.ordinal()){
|
||||
tile.floor().drawNonLayer(tile);
|
||||
if(floor.cacheLayer == layer){
|
||||
floor.draw(tile);
|
||||
}else if(floor.cacheLayer.ordinal() < layer.ordinal()){
|
||||
floor.drawNonLayer(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,7 +268,7 @@ public class FloorRenderer{
|
||||
Timers.mark();
|
||||
|
||||
if(world.getSector() != null){
|
||||
gutter = 32;
|
||||
gutter = mapPadding;
|
||||
}else{
|
||||
gutter = 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
@@ -16,9 +17,9 @@ 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 io.anuke.ucore.scene.utils.ScissorStack;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -28,15 +29,23 @@ import static io.anuke.mindustry.Vars.*;
|
||||
* Used for rendering fog of war. A framebuffer is used for this.
|
||||
*/
|
||||
public class FogRenderer implements Disposable{
|
||||
private static final int extraPadding = 3;
|
||||
private static final int shadowPadding = 1;
|
||||
|
||||
private TextureRegion region = new TextureRegion();
|
||||
private FrameBuffer buffer;
|
||||
private ByteBuffer pixelBuffer = ByteBuffer.allocateDirect(4);
|
||||
private Array<Tile> changeQueue = new Array<>();
|
||||
private int padding;
|
||||
private Rectangle rect = new Rectangle();
|
||||
|
||||
public FogRenderer(){
|
||||
Events.on(WorldLoadGraphicsEvent.class, () -> {
|
||||
dispose();
|
||||
buffer = new FrameBuffer(Format.RGBA8888, world.width(), world.height(), false);
|
||||
|
||||
padding = world.getSector() != null ? mapPadding + extraPadding : 0;
|
||||
|
||||
buffer = new FrameBuffer(Format.RGBA8888, world.width() + padding*2, world.height() + padding*2, false);
|
||||
changeQueue.clear();
|
||||
|
||||
//clear buffer to black
|
||||
@@ -62,26 +71,26 @@ public class FogRenderer implements Disposable{
|
||||
}));
|
||||
}
|
||||
|
||||
public int getPadding(){
|
||||
return padding;
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
if(buffer == null) return;
|
||||
|
||||
float vw = Core.camera.viewportWidth * Core.camera.zoom;
|
||||
float vh = Core.camera.viewportHeight * Core.camera.zoom;
|
||||
|
||||
float px = Core.camera.position.x -= vw / 2f;
|
||||
float py = Core.camera.position.y -= vh / 2f;
|
||||
float px = Core.camera.position.x - vw / 2f;
|
||||
float py = Core.camera.position.y - vh / 2f;
|
||||
|
||||
float u = px / tilesize / world.width();
|
||||
float v = py / tilesize / world.height();
|
||||
float u = (px / tilesize + padding) / buffer.getWidth();
|
||||
float v = (py / tilesize + padding) / buffer.getHeight();
|
||||
|
||||
float u2 = (px + vw) / tilesize / world.width();
|
||||
float v2 = (py + vh) / tilesize / world.height();
|
||||
float u2 = ((px + vw) / tilesize + padding) / buffer.getWidth();
|
||||
float v2 = ((py + vh) / tilesize + padding) / buffer.getHeight();
|
||||
|
||||
if(Core.batch instanceof ClipSpriteBatch){
|
||||
((ClipSpriteBatch) Core.batch).enableClip(false);
|
||||
}
|
||||
|
||||
Core.batch.getProjectionMatrix().setToOrtho2D(0, 0, world.width() * tilesize, world.height() * tilesize);
|
||||
Core.batch.getProjectionMatrix().setToOrtho2D(-padding * tilesize, -padding * tilesize, buffer.getWidth() * tilesize, buffer.getHeight() * tilesize);
|
||||
|
||||
Draw.color(Color.WHITE);
|
||||
|
||||
@@ -93,6 +102,10 @@ public class FogRenderer implements Disposable{
|
||||
//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));
|
||||
|
||||
boolean pop = ScissorStack.pushScissors(rect.set((padding-shadowPadding), (padding-shadowPadding),
|
||||
(world.width() + shadowPadding*2) ,
|
||||
(world.height() + shadowPadding*2)));
|
||||
|
||||
Graphics.begin();
|
||||
EntityDraw.setClip(false);
|
||||
|
||||
@@ -111,6 +124,8 @@ public class FogRenderer implements Disposable{
|
||||
Graphics.end();
|
||||
buffer.end();
|
||||
|
||||
if(pop) ScissorStack.popScissors();
|
||||
|
||||
region.setTexture(buffer.getColorBufferTexture());
|
||||
region.setRegion(u, v2, u2, v);
|
||||
|
||||
@@ -128,10 +143,6 @@ public class FogRenderer implements Disposable{
|
||||
Graphics.setScreen();
|
||||
Core.batch.draw(renderer.pixelSurface.texture(), 0, Gdx.graphics.getHeight(), Gdx.graphics.getWidth(), -Gdx.graphics.getHeight());
|
||||
Graphics.end();
|
||||
|
||||
if(Core.batch instanceof ClipSpriteBatch){
|
||||
((ClipSpriteBatch) Core.batch).enableClip(true);
|
||||
}
|
||||
}
|
||||
|
||||
public Texture getTexture(){
|
||||
|
||||
@@ -57,6 +57,10 @@ public class MinimapRenderer implements Disposable{
|
||||
zoom = Mathf.clamp(zoom, 1, Math.min(world.width(), world.height()) / baseSize / 2);
|
||||
}
|
||||
|
||||
public float getZoom(){
|
||||
return zoom;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
if(pixmap != null){
|
||||
pixmap.dispose();
|
||||
|
||||
Reference in New Issue
Block a user