Partial 7.0 merge - API preview

This commit is contained in:
Anuken
2021-06-02 11:08:08 -04:00
parent ea75a357ca
commit 28b235ef07
531 changed files with 12356 additions and 6286 deletions

View File

@@ -192,11 +192,12 @@ public class JsonIO{
json.setSerializer(UnlockableContent.class, new Serializer<>(){
@Override
public void write(Json json, UnlockableContent object, Class knownType){
json.writeValue(object.name);
json.writeValue(object == null ? null : object.name);
}
@Override
public UnlockableContent read(Json json, JsonValue jsonData, Class type){
if(jsonData.isNull()) return null;
String str = jsonData.asString();
Item item = Vars.content.getByName(ContentType.item, str);
Liquid liquid = Vars.content.getByName(ContentType.liquid, str);

View File

@@ -2,7 +2,6 @@ package mindustry.io;
import arc.files.*;
import arc.graphics.*;
import arc.graphics.Pixmap.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.io.*;
@@ -84,8 +83,8 @@ public class MapIO{
int c = colorFor(block(), Blocks.air, Blocks.air, team());
if(c != black){
walls.draw(x, floors.getHeight() - 1 - y, c);
floors.draw(x, floors.getHeight() - 1 - y + 1, shade);
walls.setRaw(x, floors.height - 1 - y, c);
floors.set(x, floors.height - 1 - y + 1, shade);
}
}
};
@@ -112,7 +111,7 @@ public class MapIO{
for(int dx = 0; dx < size; dx++){
for(int dy = 0; dy < size; dy++){
int drawx = tile.x + dx + offsetx, drawy = tile.y + dy + offsety;
walls.draw(drawx, floors.getHeight() - 1 - drawy, c);
walls.set(drawx, floors.height - 1 - drawy, c);
}
}
@@ -132,9 +131,9 @@ public class MapIO{
@Override
public Tile create(int x, int y, int floorID, int overlayID, int wallID){
if(overlayID != 0){
floors.draw(x, floors.getHeight() - 1 - y, colorFor(Blocks.air, Blocks.air, content.block(overlayID), Team.derelict));
floors.set(x, floors.height - 1 - y, colorFor(Blocks.air, Blocks.air, content.block(overlayID), Team.derelict));
}else{
floors.draw(x, floors.getHeight() - 1 - y, colorFor(Blocks.air, content.block(floorID), Blocks.air, Team.derelict));
floors.set(x, floors.height - 1 - y, colorFor(Blocks.air, content.block(floorID), Blocks.air, Team.derelict));
}
if(content.block(overlayID) == Blocks.spawn){
map.spawns ++;
@@ -143,7 +142,7 @@ public class MapIO{
}
}));
floors.drawPixmap(walls, 0, 0);
floors.draw(walls, true);
walls.dispose();
return floors;
}finally{
@@ -152,11 +151,11 @@ public class MapIO{
}
public static Pixmap generatePreview(Tiles tiles){
Pixmap pixmap = new Pixmap(tiles.width, tiles.height, Format.rgba8888);
for(int x = 0; x < pixmap.getWidth(); x++){
for(int y = 0; y < pixmap.getHeight(); y++){
Pixmap pixmap = new Pixmap(tiles.width, tiles.height);
for(int x = 0; x < pixmap.width; x++){
for(int y = 0; y < pixmap.height; y++){
Tile tile = tiles.getn(x, y);
pixmap.draw(x, pixmap.getHeight() - 1 - y, colorFor(tile.block(), tile.floor(), tile.overlay(), tile.team()));
pixmap.set(x, pixmap.height - 1 - y, colorFor(tile.block(), tile.floor(), tile.overlay(), tile.team()));
}
}
return pixmap;
@@ -175,14 +174,14 @@ public class MapIO{
//while synthetic blocks are possible, most of their data is lost, so in order to avoid questions like
//"why is there air under my drill" and "why are all my conveyors facing right", they are disabled
int color = tile.block().hasColor && !tile.block().synthetic() ? tile.block().mapColor.rgba() : tile.floor().mapColor.rgba();
pix.draw(tile.x, tiles.height - 1 - tile.y, color);
pix.set(tile.x, tiles.height - 1 - tile.y, color);
}
return pix;
}
public static void readImage(Pixmap pixmap, Tiles tiles){
for(Tile tile : tiles){
int color = pixmap.getPixel(tile.x, pixmap.getHeight() - 1 - tile.y);
int color = pixmap.get(tile.x, pixmap.height - 1 - tile.y);
Block block = ColorMapper.get(color);
if(block.isFloor()){

View File

@@ -102,8 +102,8 @@ public abstract class SaveFileReader{
if(!isByte){
output.writeInt(length);
}else{
if(length > Short.MAX_VALUE){
throw new IOException("Byte write length exceeded: " + length + " > " + Short.MAX_VALUE);
if(length > 65535){
throw new IOException("Byte write length exceeded: " + length + " > 65535");
}
output.writeShort(length);
}

View File

@@ -18,10 +18,10 @@ import java.util.zip.*;
import static mindustry.Vars.*;
public class SaveIO{
/** Format header. This is the string 'MSAV' in ASCII. */
public static final byte[] header = {77, 83, 65, 86};
/** 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());
public static final Seq<SaveVersion> versionArray = Seq.with(new Save1(), new Save2(), new Save3(), new Save4(), new Save5());
static{
for(SaveVersion version : versionArray){

View File

@@ -1,14 +1,14 @@
package mindustry.io;
import arc.*;
import arc.assets.*;
import arc.assets.loaders.*;
import arc.assets.loaders.resolvers.*;
import arc.files.*;
public class SavePreviewLoader extends TextureLoader{
public SavePreviewLoader(){
super(new AbsoluteFileHandleResolver());
super(Core.files::absolute);
}
@Override

View File

@@ -1,6 +1,7 @@
package mindustry.io;
import arc.*;
import arc.func.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
@@ -12,10 +13,11 @@ import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*;
import mindustry.maps.*;
import mindustry.maps.Map;
import mindustry.world.*;
import java.io.*;
import java.util.*;
import static mindustry.Vars.*;
@@ -24,6 +26,9 @@ public abstract class SaveVersion extends SaveFileReader{
//HACK stores the last read build of the save file, valid after read meta call
protected int lastReadBuild;
//stores entity mappings for use after readEntityMapping
//if null, fall back to EntityMapping's values
protected @Nullable Prov[] entityMapping;
public SaveVersion(int version){
this.version = version;
@@ -284,7 +289,7 @@ public abstract class SaveVersion extends SaveFileReader{
}
}
public void writeEntities(DataOutput stream) throws IOException{
public void writeTeamBlocks(DataOutput stream) throws IOException{
//write team data with entities.
Seq<TeamData> data = state.teams.getActive().copy();
if(!data.contains(Team.sharded.data())) data.add(Team.sharded.data());
@@ -300,7 +305,9 @@ public abstract class SaveVersion extends SaveFileReader{
TypeIO.writeObject(Writes.get(stream), block.config);
}
}
}
public void writeWorldEntities(DataOutput stream) throws IOException{
stream.writeInt(Groups.all.count(Entityc::serialize));
for(Entityc entity : Groups.all){
if(!entity.serialize()) continue;
@@ -312,7 +319,21 @@ public abstract class SaveVersion extends SaveFileReader{
}
}
public void readEntities(DataInput stream) throws IOException{
public void writeEntityMapping(DataOutput stream) throws IOException{
stream.writeShort(EntityMapping.customIdMap.size);
for(var entry : EntityMapping.customIdMap.entries()){
stream.writeShort(entry.key);
stream.writeUTF(entry.value);
}
}
public void writeEntities(DataOutput stream) throws IOException{
writeEntityMapping(stream);
writeTeamBlocks(stream);
writeWorldEntities(stream);
}
public void readTeamBlocks(DataInput stream) throws IOException{
int teamc = stream.readInt();
for(int i = 0; i < teamc; i++){
@@ -333,23 +354,48 @@ public abstract class SaveVersion extends SaveFileReader{
}
}
}
}
public void readWorldEntities(DataInput stream) throws IOException{
//entityMapping is null in older save versions, so use the default
Prov[] mapping = this.entityMapping == null ? EntityMapping.idMap : this.entityMapping;
int amount = stream.readInt();
for(int j = 0; j < amount; j++){
readChunk(stream, true, in -> {
byte typeid = in.readByte();
if(EntityMapping.map(typeid) == null){
if(mapping[typeid] == null){
in.skipBytes(lastRegionLength - 1);
return;
}
Entityc entity = (Entityc)EntityMapping.map(typeid).get();
Entityc entity = (Entityc)mapping[typeid].get();
entity.read(Reads.get(in));
entity.add();
});
}
}
public void readEntityMapping(DataInput stream) throws IOException{
//copy entityMapping for further mutation; will be used in readWorldEntities
entityMapping = Arrays.copyOf(EntityMapping.idMap, EntityMapping.idMap.length);
short amount = stream.readShort();
for(int i = 0; i < amount; i++){
//everything that corresponded to this ID in this save goes by this name
//so replace the prov in the current mapping with the one found with this name
short id = stream.readShort();
String name = stream.readUTF();
entityMapping[id] = EntityMapping.map(name);
}
}
public void readEntities(DataInput stream) throws IOException{
readEntityMapping(stream);
readTeamBlocks(stream);
readWorldEntities(stream);
}
public void readContentHeader(DataInput stream) throws IOException{
byte mapped = stream.readByte();

View File

@@ -5,7 +5,6 @@ import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import arc.util.pooling.*;
import mindustry.ai.types.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
@@ -29,7 +28,7 @@ import java.nio.*;
import static mindustry.Vars.*;
/** Class for specifying read/write methods for code generation. */
/** Class for specifying read/write methods for code generation. All IO MUST be thread safe!*/
@SuppressWarnings("unused")
@TypeIOHandler
public class TypeIO{
@@ -392,13 +391,13 @@ public class TypeIO{
return new Vec2(read.f(), read.f());
}
public static void writeStatuse(Writes write, StatusEntry entry){
public static void writeStatus(Writes write, StatusEntry entry){
write.s(entry.effect.id);
write.f(entry.time);
}
public static StatusEntry readStatuse(Reads read){
return Pools.obtain(StatusEntry.class, StatusEntry::new).set(content.getByID(ContentType.status, read.s()), read.f());
public static StatusEntry readStatus(Reads read){
return new StatusEntry().set(content.getByID(ContentType.status, read.s()), read.f());
}
public static void writeItems(Writes write, ItemStack stack){

View File

@@ -2,9 +2,25 @@ package mindustry.io.versions;
import mindustry.io.*;
import java.io.*;
/** This version only writes entities, no entity ID mappings. */
public class Save4 extends SaveVersion{
public Save4(){
super(4);
}
@Override
public void writeEntities(DataOutput stream) throws IOException{
writeTeamBlocks(stream);
writeWorldEntities(stream);
}
@Override
public void readEntities(DataInput stream) throws IOException{
readTeamBlocks(stream);
readWorldEntities(stream);
}
}

View File

@@ -0,0 +1,10 @@
package mindustry.io.versions;
import mindustry.io.*;
public class Save5 extends SaveVersion{
public Save5(){
super(5);
}
}