mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 18:57:39 +07:00
Removed shadow/world padding
This commit is contained in:
parent
7cd842df19
commit
ffa1aae27c
@ -38,7 +38,7 @@ void main() {
|
||||
else if(m > 0.35) gl_FragColor.rgb = p4;
|
||||
else gl_FragColor.rgb = vec3(0.0);
|
||||
|
||||
gl_FragColor.rgb *= 0.8;
|
||||
gl_FragColor.rgb *= 0.75;
|
||||
|
||||
gl_FragColor.a = mod(abs(float(coords.x)) + abs(float(coords.y)), 110.0) < 35.0 ? 1.0 : 0.0;
|
||||
}
|
@ -10,7 +10,6 @@ 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;
|
||||
@ -20,23 +19,18 @@ 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.Structs;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Structs;
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
@ -44,26 +38,6 @@ public class FloorRenderer{
|
||||
|
||||
public FloorRenderer(){
|
||||
Events.on(WorldLoadGraphicsEvent.class, event -> clearTiles());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@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(){
|
||||
@ -188,18 +162,10 @@ public class FloorRenderer{
|
||||
|
||||
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 = null;
|
||||
Tile tile = world.tile(tilex, tiley);
|
||||
|
||||
if(tile == null && sector != null && tilex < world.width() + gutter*2 && tiley < world.height() + gutter*2){
|
||||
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);
|
||||
if(tile != null){
|
||||
used.add(tile.floor().cacheLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,22 +184,11 @@ public class FloorRenderer{
|
||||
|
||||
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);
|
||||
Tile tile = world.tile(tilex , tiley);
|
||||
Floor floor;
|
||||
|
||||
if(tile == null){
|
||||
if(sector != null && tilex < world.width() + gutter*2 && tiley < world.height() + gutter*2){
|
||||
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;
|
||||
}
|
||||
continue;
|
||||
}else{
|
||||
floor = tile.floor();
|
||||
}
|
||||
@ -254,14 +209,8 @@ public class FloorRenderer{
|
||||
public void clearTiles(){
|
||||
if(cbatch != null) cbatch.dispose();
|
||||
|
||||
if(world.getSector() != null){
|
||||
gutter = mapPadding;
|
||||
}else{
|
||||
gutter = 0;
|
||||
}
|
||||
|
||||
int chunksx = Mathf.ceil((float) (world.width() + gutter) / chunksize),
|
||||
chunksy = Mathf.ceil((float) (world.height() + gutter) / chunksize) ;
|
||||
int chunksx = Mathf.ceil((float) (world.width()) / chunksize),
|
||||
chunksy = Mathf.ceil((float) (world.height()) / chunksize) ;
|
||||
cache = new Chunk[chunksx][chunksy];
|
||||
cbatch = new CacheBatch(world.width() * world.height() * 4 * 4);
|
||||
|
||||
|
@ -7,7 +7,6 @@ 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;
|
||||
@ -27,52 +26,27 @@ 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 fshadowPadding = 1;
|
||||
|
||||
private TextureRegion region = new TextureRegion();
|
||||
private FrameBuffer buffer;
|
||||
private ByteBuffer pixelBuffer;
|
||||
private Array<Tile> changeQueue = new Array<>();
|
||||
private int padding;
|
||||
private int shadowPadding;
|
||||
private Rectangle rect = new Rectangle();
|
||||
private boolean dirty;
|
||||
|
||||
private boolean isOffseted;
|
||||
private int offsettedX, offsettedY;
|
||||
|
||||
public FogRenderer(){
|
||||
Events.on(WorldLoadGraphicsEvent.class, event -> {
|
||||
if(!isOffseted){
|
||||
dispose();
|
||||
}
|
||||
dispose();
|
||||
|
||||
padding = world.getSector() != null ? mapPadding + extraPadding : 0;
|
||||
shadowPadding = world.getSector() != null ? fshadowPadding : -1;
|
||||
shadowPadding = -1;
|
||||
|
||||
FrameBuffer lastBuffer = buffer;
|
||||
|
||||
buffer = new FrameBuffer(Format.RGBA8888, world.width() + padding*2, world.height() + padding*2, false);
|
||||
buffer = new FrameBuffer(Format.RGBA8888, world.width(), world.height(), false);
|
||||
changeQueue.clear();
|
||||
|
||||
//clear buffer to black
|
||||
buffer.begin();
|
||||
Graphics.clear(0, 0, 0, 1f);
|
||||
|
||||
if(isOffseted){
|
||||
Core.batch.getProjectionMatrix().setToOrtho2D(-padding, -padding, buffer.getWidth(), buffer.getHeight());
|
||||
Core.batch.begin();
|
||||
Core.batch.draw(lastBuffer.getColorBufferTexture(), offsettedX, offsettedY + lastBuffer.getColorBufferTexture().getHeight(),
|
||||
lastBuffer.getColorBufferTexture().getWidth(), -lastBuffer.getColorBufferTexture().getHeight());
|
||||
Core.batch.end();
|
||||
}
|
||||
buffer.end();
|
||||
|
||||
if(isOffseted){
|
||||
lastBuffer.dispose();
|
||||
}
|
||||
|
||||
for(int x = 0; x < world.width(); x++){
|
||||
for(int y = 0; y < world.height(); y++){
|
||||
Tile tile = world.tile(x, y);
|
||||
@ -84,8 +58,6 @@ public class FogRenderer implements Disposable{
|
||||
|
||||
pixelBuffer = ByteBuffer.allocateDirect(world.width() * world.height() * 4);
|
||||
dirty = true;
|
||||
|
||||
isOffseted = false;
|
||||
});
|
||||
|
||||
Events.on(TileChangeEvent.class, event -> threads.runGraphics(() -> {
|
||||
@ -101,7 +73,7 @@ public class FogRenderer implements Disposable{
|
||||
buffer.begin();
|
||||
pixelBuffer.position(0);
|
||||
Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);
|
||||
Gdx.gl.glReadPixels(padding, padding, world.width(), world.height(), GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
|
||||
Gdx.gl.glReadPixels(0, 0, world.width(), world.height(), GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
|
||||
|
||||
pixelBuffer.position(0);
|
||||
for(int i = 0; i < world.width() * world.height(); i++){
|
||||
@ -115,7 +87,7 @@ public class FogRenderer implements Disposable{
|
||||
}
|
||||
|
||||
public int getPadding(){
|
||||
return padding;
|
||||
return -shadowPadding;
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
@ -127,19 +99,19 @@ public class FogRenderer implements Disposable{
|
||||
float px = Core.camera.position.x - vw / 2f;
|
||||
float py = Core.camera.position.y - vh / 2f;
|
||||
|
||||
float u = (px / tilesize + padding) / buffer.getWidth();
|
||||
float v = (py / tilesize + padding) / buffer.getHeight();
|
||||
float u = (px / tilesize) / buffer.getWidth();
|
||||
float v = (py / tilesize) / buffer.getHeight();
|
||||
|
||||
float u2 = ((px + vw) / tilesize + padding) / buffer.getWidth();
|
||||
float v2 = ((py + vh) / tilesize + padding) / buffer.getHeight();
|
||||
float u2 = ((px + vw) / tilesize) / buffer.getWidth();
|
||||
float v2 = ((py + vh) / tilesize) / buffer.getHeight();
|
||||
|
||||
Core.batch.getProjectionMatrix().setToOrtho2D(-padding * tilesize, -padding * tilesize, buffer.getWidth() * tilesize, buffer.getHeight() * tilesize);
|
||||
Core.batch.getProjectionMatrix().setToOrtho2D(0, 0, buffer.getWidth() * tilesize, buffer.getHeight() * tilesize);
|
||||
|
||||
Draw.color(Color.WHITE);
|
||||
|
||||
buffer.begin();
|
||||
|
||||
Graphics.beginClip((padding-shadowPadding), (padding-shadowPadding), (world.width() + shadowPadding*2), (world.height() + shadowPadding*2));
|
||||
Graphics.beginClip((-shadowPadding), (-shadowPadding), (world.width() + shadowPadding*2), (world.height() + shadowPadding*2));
|
||||
|
||||
Graphics.begin();
|
||||
EntityDraw.setClip(false);
|
||||
|
@ -230,6 +230,8 @@ public class Sectors{
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO check for core on impassable block.
|
||||
|
||||
//50% chance to get a wave mission
|
||||
if(Mathf.randomSeed(sector.getSeed() + 6) < 0.5){
|
||||
//recipe mission (maybe)
|
||||
|
Loading…
Reference in New Issue
Block a user