Merge remote-tracking branch 'origin/continuous-sectors' into continuous-sectors

# Conflicts:
#	core/src/io/anuke/mindustry/maps/Sectors.java
This commit is contained in:
Anuken
2018-09-21 16:33:00 -04:00
5 changed files with 137 additions and 15 deletions

View File

@@ -195,6 +195,12 @@ public class World extends Module{
generating = true;
}
/**Call to signal the beginning of loading the map with a custom set of tiles.*/
public void beginMapLoad(Tile[][] tiles){
this.tiles = tiles;
generating = true;
}
/**
* Call to signify the end of map loading. Updates tile occlusions and sets up physics for the world.
* A WorldLoadEvent will be fire.

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

@@ -15,7 +15,11 @@ import io.anuke.mindustry.maps.missions.WaveMission;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.GridMap;
import io.anuke.ucore.util.Log;
@@ -25,6 +29,7 @@ import static io.anuke.mindustry.Vars.*;
public class Sectors{
private static final int sectorImageSize = 32;
private static final boolean checkExpansion = false;
private static final float sectorLargeChance = 0.24f;
private GridMap<Sector> grid = new GridMap<>();
@@ -80,9 +85,7 @@ public class Sectors{
throw new IllegalArgumentException("Sector is not being played in!");
}
sector.width += expandX;
sector.height += expandY;
//remove old sector data to clear things up
for(int x = sector.x; x < sector.x+sector.width; x++){
for(int y = sector.y; y < sector.y+sector.height; y++){
grid.put(x, y, null);
@@ -92,13 +95,80 @@ public class Sectors{
if(expandX < 0) sector.x += expandX;
if(expandY < 0) sector.y += expandY;
sector.width += Math.abs(expandX);
sector.height += Math.abs(expandY);
if(checkExpansion) {
for (int x = sector.x; x < sector.x + sector.width; x++) {
for (int y = sector.y; y < sector.y + sector.height; y++) {
if (grid.get(x, y) != null && grid.get(x, y).complete) {
//if a completed sector is hit, expansion failed
if (expandX < 0) sector.x -= expandX;
if (expandY < 0) sector.y -= expandY;
sector.width -= Math.abs(expandX);
sector.height -= Math.abs(expandY);
return false;
}
}
}
}
//add new sector spaces
for(int x = sector.x; x < sector.x+sector.width; x++){
for(int y = sector.y; y < sector.y+sector.height; y++){
grid.put(x, y, sector);
}
}
return false;
//sector map data should now be shifted and generated
int shiftX = expandX < 0 ? -expandX*sectorSize : 0;
int shiftY = expandY < 0 ? -expandY*sectorSize : 0;
for(EntityGroup<?> group : Entities.getAllGroups()){
for(Entity entity : group.all()){
entity.set(entity.getX() + shiftX * tilesize, entity.getY() + shiftY * tilesize);
}
}
if(!headless){
renderer.fog().setLoadingOffset(shiftX, shiftY);
}
//create *new* tile array
Tile[][] newTiles = new Tile[sector.width * sectorSize][sector.height * sectorSize];
//shift existing tiles to new array
for (int x = 0; x < (sector.width - Math.abs(expandX))*sectorSize; x++) {
for (int y = 0; y < (sector.height - Math.abs(expandY))*sectorSize; y++) {
Tile tile = world.rawTile(x, y);
tile.x = (short)(x + shiftX);
tile.y = (short)(y + shiftY);
newTiles[x + shiftX][y + shiftY] = tile;
}
}
world.beginMapLoad(newTiles);
//create new tiles
for (int sx = 0; sx < sector.width; sx++) {
for (int sy = 0; sy < sector.height; sy++) {
//if this sector is a 'new sector (not part of the current save data...)
if(sx < -expandX || sy < -expandY || sx >= sector.width - expandX || sy >= sector.height - expandY){
//gen tiles in sector
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 * sectorSize, y + sy*sectorSize, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
}
}
}
}
}
//end loading of map
world.endMapLoad();
return true;
}
/**Unlocks a sector. This shows nearby sectors.*/

View File

@@ -8,7 +8,6 @@ import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.OreBlocks;
import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.MapTileData;
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
@@ -26,7 +25,8 @@ import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.SeedRandom;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.sectorSize;
import static io.anuke.mindustry.Vars.world;
public class WorldGenerator{
@@ -73,6 +73,11 @@ public class WorldGenerator{
generateOres(tiles, seed, genOres, null);
}
/**'Prepares' a tile array by:<br>
* - setting up multiblocks<br>
* - updating cliff data<br>
* - removing ores on cliffs<br>
* Usually used before placing structures on a tile array.*/
public void prepareTiles(Tile[][] tiles){
//find multiblocks
@@ -82,14 +87,8 @@ public class WorldGenerator{
for(int y = 0; y < tiles[0].length; y++){
Tile tile = tiles[x][y];
Team team = tile.getTeam();
if(tile.block() == StorageBlocks.core){
state.teams.get(team).cores.add(tile);
}
if(tiles[x][y].block().isMultiblock()){
multiblocks.add(tiles[x][y].packedPosition());
if(tile.block().isMultiblock()){
multiblocks.add(tile.packedPosition());
}
}
}
@@ -134,6 +133,7 @@ public class WorldGenerator{
tile.setBlock(Blocks.air);
}
//remove ore veins on cliffs
if(tile.floor() instanceof OreBlock && tile.hasCliffs()){
tile.setFloor(((OreBlock)tile.floor()).base);
}
@@ -245,6 +245,17 @@ public class WorldGenerator{
return generateTile(result, sectorX, sectorY, localX, localY, detailed, null);
}
/**
* Gets the generation result from a specific sector at specific coordinates.
* @param result where to put the generation results
* @param sectorX X of the sector in terms of sector coordinates
* @param sectorY Y of the sector in terms of sector coordinates
* @param localX X in terms of local sector tile coordinates
* @param localY Y in terms of local sector tile coordinates
* @param detailed whether the tile result is 'detailed' (e.g. previews should not be detailed)
* @param spawnpoints list of player spawnpoints, can be null
* @return the GenResult passed in with its values modified
*/
public GenResult generateTile(GenResult result, int sectorX, int sectorY, int localX, int localY, boolean detailed, Array<GridPoint2> spawnpoints){
int x = sectorX * sectorSize + localX + Short.MAX_VALUE;
int y = sectorY * sectorSize + localY + Short.MAX_VALUE;

View File

@@ -79,6 +79,14 @@ public class CoreBlock extends StorageBlock{
if(entity != null) entity.solid = solid;
}
@Override
public void onProximityUpdate(Tile tile) {
//add cores
if(!state.teams.get(tile.getTeam()).cores.contains(tile, true)){
state.teams.get(tile.getTeam()).cores.add(tile);
}
}
@Override
public boolean canBreak(Tile tile){
return state.teams.get(tile.getTeam()).cores.size > 1;