Fog persistence in sector expansion

This commit is contained in:
Anuken
2018-09-21 16:11:40 -04:00
parent bee83a3a3e
commit 90691de457
2 changed files with 33 additions and 2 deletions

View File

@@ -40,21 +40,40 @@ public class FogRenderer implements Disposable{
private Rectangle rect = new Rectangle();
private boolean dirty;
private boolean isOffseted;
private int offsettedX, offsettedY;
public FogRenderer(){
Events.on(WorldLoadGraphicsEvent.class, event -> {
dispose();
if(!isOffseted){
dispose();
}
padding = world.getSector() != null ? mapPadding + extraPadding : 0;
shadowPadding = world.getSector() != null ? fshadowPadding : -1;
FrameBuffer lastBuffer = buffer;
buffer = new FrameBuffer(Format.RGBA8888, world.width() + padding*2, world.height() + padding*2, 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);
@@ -66,6 +85,8 @@ public class FogRenderer implements Disposable{
pixelBuffer = ByteBuffer.allocateDirect(world.width() * world.height() * 4);
dirty = true;
isOffseted = false;
});
Events.on(TileChangeEvent.class, event -> threads.runGraphics(() -> {
@@ -75,6 +96,12 @@ public class FogRenderer implements Disposable{
}));
}
public void setLoadingOffset(int x, int y){
isOffseted = true;
offsettedX = x;
offsettedY = y;
}
public void writeFog(){
if(buffer == null) return;

View File

@@ -126,6 +126,10 @@ public class Sectors{
}
}
if(!headless){
renderer.fog().setLoadingOffset(shiftX, shiftY);
}
//create *new* tile array
Tile[][] newTiles = new Tile[sector.width * sectorSize][sector.height * sectorSize];
@@ -150,7 +154,7 @@ public class Sectors{
for (int x = 0; x < sectorSize; x++) {
for (int y = 0; y < sectorSize; y++) {
GenResult result = world.generator().generateTile(sx + sector.x, sy + sector.y, x, y);
newTiles[sx * sectorSize + x][sy * sectorSize + y] = new Tile(x + sx * tilesize, y + sy*tilesize, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
newTiles[sx * sectorSize + x][sy * sectorSize + y] = new Tile(x + sx * sectorSize, y + sy*sectorSize, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
}
}
}