Merge branch 'crux-floor' of https://github.com/Anuken/MindustryPrivate
This commit is contained in:
@@ -141,6 +141,23 @@ public class MapIO{
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadTileData(){
|
||||
//colored floor/wall tile data will affect the map preview
|
||||
|
||||
if(!tile.block().synthetic() && tile.block() != Blocks.air){
|
||||
int color = tile.block().minimapColor(tile);
|
||||
if(color != 0){
|
||||
walls.set(tile.x, walls.height - 1 - tile.y, color);
|
||||
}
|
||||
}else if(tile.overlay() == Blocks.air && tile.block() == Blocks.air){
|
||||
int color = tile.floor().minimapColor(tile);
|
||||
if(color != 0){
|
||||
floors.set(tile.x, floors.height - 1 - tile.y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
floors.draw(walls, true);
|
||||
@@ -156,7 +173,14 @@ public class MapIO{
|
||||
for(int x = 0; x < pixmap.width; x++){
|
||||
for(int y = 0; y < pixmap.height; y++){
|
||||
Tile tile = tiles.getn(x, y);
|
||||
pixmap.set(x, pixmap.height - 1 - y, colorFor(tile.block(), tile.floor(), tile.overlay(), tile.team()));
|
||||
int color = 0;
|
||||
if(!tile.block().synthetic() && tile.block() != Blocks.air){
|
||||
color = tile.block().minimapColor(tile);
|
||||
}else if(tile.overlay() == Blocks.air && tile.block() == Blocks.air){
|
||||
color = tile.floor().minimapColor(tile);
|
||||
}
|
||||
if(color == 0) color = colorFor(tile.block(), tile.floor(), tile.overlay(), tile.team());
|
||||
pixmap.set(x, pixmap.height - 1 - y, color);
|
||||
}
|
||||
}
|
||||
return pixmap;
|
||||
@@ -202,7 +226,7 @@ public class MapIO{
|
||||
for(Tile tile : tiles){
|
||||
//default to stone floor
|
||||
if(tile.floor() == Blocks.air){
|
||||
tile.setFloorUnder((Floor)Blocks.stone);
|
||||
tile.setFloor((Floor)Blocks.stone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SaveIO{
|
||||
/** Save format header. */
|
||||
public static final byte[] header = {'M', 'S', 'A', 'V'};
|
||||
public static final IntMap<SaveVersion> versions = new IntMap<>();
|
||||
public static final Seq<SaveVersion> versionArray = Seq.with(new Save1(), new Save2(), new Save3(), new Save4(), new Save5(), new Save6(), new Save7(), new Save8());
|
||||
public static final Seq<SaveVersion> versionArray = Seq.with(new Save1(), new Save2(), new Save3(), new Save4(), new Save5(), new Save6(), new Save7(), new Save8(), new Save9());
|
||||
|
||||
static{
|
||||
for(SaveVersion version : versionArray){
|
||||
|
||||
@@ -209,7 +209,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
|
||||
//floor + overlay
|
||||
for(int i = 0; i < world.width() * world.height(); i++){
|
||||
Tile tile = world.rawTile(i % world.width(), i / world.width());
|
||||
Tile tile = world.tiles.geti(i);
|
||||
stream.writeShort(tile.floorID());
|
||||
stream.writeShort(tile.overlayID());
|
||||
int consecutives = 0;
|
||||
@@ -230,16 +230,26 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
|
||||
//blocks
|
||||
for(int i = 0; i < world.width() * world.height(); i++){
|
||||
Tile tile = world.rawTile(i % world.width(), i / world.width());
|
||||
Tile tile = world.tiles.geti(i);
|
||||
stream.writeShort(tile.blockID());
|
||||
|
||||
boolean savedata = tile.floor().saveData || tile.overlay().saveData || tile.block().saveData;
|
||||
boolean savedata = tile.shouldSaveData();
|
||||
|
||||
byte packed = (byte)((tile.build != null ? 1 : 0) | (savedata ? 2 : 0));
|
||||
//in the old version, the second bit was set to indicate presence of data, but that approach was flawed - it didn't allow buildings + data on the same tile
|
||||
//so now the third bit is used instead
|
||||
byte packed = (byte)((tile.build != null ? 1 : 0) | (savedata ? 4 : 0));
|
||||
|
||||
//make note of whether there was an entity/rotation here
|
||||
//make note of whether there was an entity or custom tile data here
|
||||
stream.writeByte(packed);
|
||||
|
||||
if(savedata){
|
||||
//the new 'extra data' format writes 7 bytes of data instead of 1
|
||||
stream.writeByte(tile.data);
|
||||
stream.writeByte(tile.floorData);
|
||||
stream.writeByte(tile.overlayData);
|
||||
stream.writeInt(tile.extraData);
|
||||
}
|
||||
|
||||
//only write the entity for multiblocks once - in the center
|
||||
if(tile.build != null){
|
||||
if(tile.isCenter()){
|
||||
@@ -251,16 +261,14 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
}else{
|
||||
stream.writeBoolean(false);
|
||||
}
|
||||
}else if(savedata){
|
||||
stream.writeByte(tile.data);
|
||||
}else{
|
||||
}else if(!savedata){ //don't write consecutive blocks when there is custom data
|
||||
//write consecutive non-entity blocks
|
||||
int consecutives = 0;
|
||||
|
||||
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
|
||||
Tile nextTile = world.rawTile(j % world.width(), j / world.width());
|
||||
|
||||
if(nextTile.blockID() != tile.blockID()){
|
||||
if(nextTile.blockID() != tile.blockID() || savedata != nextTile.shouldSaveData()){
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -310,7 +318,19 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
boolean isCenter = true;
|
||||
byte packedCheck = stream.readByte();
|
||||
boolean hadEntity = (packedCheck & 1) != 0;
|
||||
boolean hadData = (packedCheck & 2) != 0;
|
||||
//old data format (bit 2): 1 byte only if no building is present
|
||||
//new data format (bit 3): 7 bytes (3x block-specific bytes + 1x 4-byte extra data int)
|
||||
boolean hadDataOld = (packedCheck & 2) != 0, hadDataNew = (packedCheck & 4) != 0;
|
||||
|
||||
byte data = 0, floorData = 0, overlayData = 0;
|
||||
int extraData = 0;
|
||||
|
||||
if(hadDataNew){
|
||||
data = stream.readByte();
|
||||
floorData = stream.readByte();
|
||||
overlayData = stream.readByte();
|
||||
extraData = stream.readInt();
|
||||
}
|
||||
|
||||
if(hadEntity){
|
||||
isCenter = stream.readBoolean();
|
||||
@@ -321,6 +341,15 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
tile.setBlock(block);
|
||||
}
|
||||
|
||||
//must be assigned after setBlock, because that can reset data
|
||||
if(hadDataNew){
|
||||
tile.data = data;
|
||||
tile.floorData = floorData;
|
||||
tile.overlayData = overlayData;
|
||||
tile.extraData = extraData;
|
||||
context.onReadTileData();
|
||||
}
|
||||
|
||||
if(hadEntity){
|
||||
if(isCenter){ //only read entity for center blocks
|
||||
if(block.hasBuilding()){
|
||||
@@ -339,9 +368,12 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
|
||||
context.onReadBuilding();
|
||||
}
|
||||
}else if(hadData){
|
||||
tile.setBlock(block);
|
||||
tile.data = stream.readByte();
|
||||
}else if(hadDataOld || hadDataNew){ //never read consecutive blocks if there's any kind of data
|
||||
if(hadDataOld){
|
||||
tile.setBlock(block);
|
||||
//the old data format was only read in the case where there is no building, and only contained a single byte
|
||||
tile.data = stream.readByte();
|
||||
}
|
||||
}else{
|
||||
int consecutives = stream.readUnsignedByte();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.io.versions;
|
||||
|
||||
import mindustry.io.*;
|
||||
|
||||
/** Adds support for the marker binary data region. The code is unchanged here, because it was easier to add a >= 8 check in the SaveVersion class itself. */
|
||||
public class Save8 extends SaveVersion{
|
||||
|
||||
public Save8(){
|
||||
|
||||
11
core/src/mindustry/io/versions/Save9.java
Normal file
11
core/src/mindustry/io/versions/Save9.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package mindustry.io.versions;
|
||||
|
||||
import mindustry.io.*;
|
||||
|
||||
/** Adds support for the new 7-byte custom tile data. This can read Save8 data, but Save8 doesn't know how to handle this version's output, thus the version change. */
|
||||
public class Save9 extends SaveVersion{
|
||||
|
||||
public Save9(){
|
||||
super(9);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user