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
+51 -5
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();