Persistent unit IDs

This commit is contained in:
Anuken
2021-11-29 10:02:03 -05:00
parent 117fd3769e
commit e2576f1538
16 changed files with 74 additions and 34 deletions

View File

@@ -1083,7 +1083,7 @@ public class Blocks{
}}; }};
slagCentrifuge = new GenericCrafter("slag-centrifuge"){{ slagCentrifuge = new GenericCrafter("slag-centrifuge"){{
requirements(Category.crafting, with(Items.tungsten, 60, Items.graphite, 60, Items.oxide, 40)); requirements(Category.crafting, with(Items.carbide, 70, Items.graphite, 60, Items.silicon, 40, Items.oxide, 40));
consumes.power(2f / 60f); consumes.power(2f / 60f);
@@ -2077,7 +2077,7 @@ public class Blocks{
//TODO awful name //TODO awful name
largePlasmaBore = new BeamDrill("large-plasma-bore"){{ largePlasmaBore = new BeamDrill("large-plasma-bore"){{
//TODO requirements //TODO requirements
requirements(Category.production, with(Items.graphite, 30, Items.beryllium, 20, Items.carbide, 30)); requirements(Category.production, with(Items.graphite, 30, Items.oxide, 30, Items.beryllium, 20, Items.carbide, 30));
consumes.power(0.6f); consumes.power(0.6f);
drillTime = 170f; drillTime = 170f;
tier = 5; tier = 5;

View File

@@ -59,7 +59,6 @@ public class ErekirTechTree{
}); });
}); });
//TODO where in the tech tree is the arc furnace placed? is it essential?
node(siliconArcFurnace, () -> { node(siliconArcFurnace, () -> {
node(electrolyzer, () -> { node(electrolyzer, () -> {
node(oxidationChamber, () -> { node(oxidationChamber, () -> {
@@ -81,7 +80,6 @@ public class ErekirTechTree{
node(slagIncinerator, () -> { node(slagIncinerator, () -> {
//when is this actually needed? //when is this actually needed?
node(slagHeater, () -> { node(slagHeater, () -> {
//TODO
node(slagCentrifuge, () -> { node(slagCentrifuge, () -> {
}); });
@@ -97,12 +95,10 @@ public class ErekirTechTree{
//TODO move into turbine condenser? //TODO move into turbine condenser?
node(plasmaBore, () -> { node(plasmaBore, () -> {
node(cliffCrusher, () -> { node(cliffCrusher, () -> {
//TODO req
node(largePlasmaBore, () -> { node(largePlasmaBore, () -> {
}); });
//TODO req
node(impactDrill, () -> { node(impactDrill, () -> {
}); });
@@ -154,7 +150,6 @@ public class ErekirTechTree{
nodeProduce(Liquids.ozone, () -> { nodeProduce(Liquids.ozone, () -> {
nodeProduce(Liquids.hydrogen, () -> { nodeProduce(Liquids.hydrogen, () -> {
//TODO how will nitrogen be gated behind the electrolyzer?
nodeProduce(Liquids.nitrogen, () -> { nodeProduce(Liquids.nitrogen, () -> {
nodeProduce(Liquids.cyanogen, () -> { nodeProduce(Liquids.cyanogen, () -> {
@@ -165,12 +160,9 @@ public class ErekirTechTree{
nodeProduce(Items.tungsten, () -> { nodeProduce(Items.tungsten, () -> {
nodeProduce(Items.carbide, () -> { nodeProduce(Items.carbide, () -> {
nodeProduce(Liquids.gallium, () -> {
}); });
//TODO does it require carbide?
nodeProduce(Liquids.gallium, () -> {
}); });
}); });
}); });

View File

@@ -30,6 +30,11 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
return lastId++; return lastId++;
} }
/** Makes sure the next ID counter is higher than this number, so future entities cannot possibly use this ID. */
public static void checkNextId(int id){
lastId = id + 1;
}
public EntityGroup(Class<T> type, boolean spatial, boolean mapping){ public EntityGroup(Class<T> type, boolean spatial, boolean mapping){
array = new Seq<>(false, 32, type); array = new Seq<>(false, 32, type);

View File

@@ -7,7 +7,7 @@ import arc.util.serialization.Json.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.io.legacy.*; import mindustry.io.versions.*;
import mindustry.type.*; import mindustry.type.*;
import java.util.*; import java.util.*;

View File

@@ -7,7 +7,6 @@ import arc.util.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.*; import mindustry.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.io.legacy.*;
import mindustry.io.versions.*; import mindustry.io.versions.*;
import mindustry.world.*; import mindustry.world.*;
@@ -21,7 +20,7 @@ public class SaveIO{
/** Save format header. */ /** Save format header. */
public static final byte[] header = {'M', 'S', 'A', 'V'}; public static final byte[] header = {'M', 'S', 'A', 'V'};
public static final IntMap<SaveVersion> versions = new IntMap<>(); 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()); public static final Seq<SaveVersion> versionArray = Seq.with(new Save1(), new Save2(), new Save3(), new Save4(), new Save5(), new Save6());
static{ static{
for(SaveVersion version : versionArray){ for(SaveVersion version : versionArray){

View File

@@ -10,6 +10,7 @@ import mindustry.content.*;
import mindustry.content.TechTree.*; import mindustry.content.TechTree.*;
import mindustry.core.*; import mindustry.core.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Teams.*; import mindustry.game.Teams.*;
import mindustry.gen.*; import mindustry.gen.*;
@@ -316,6 +317,7 @@ public abstract class SaveVersion extends SaveFileReader{
writeChunk(stream, true, out -> { writeChunk(stream, true, out -> {
out.writeByte(entity.classId()); out.writeByte(entity.classId());
out.writeInt(entity.id());
entity.write(Writes.get(out)); entity.write(Writes.get(out));
}); });
} }
@@ -371,7 +373,11 @@ public abstract class SaveVersion extends SaveFileReader{
return; return;
} }
int id = in.readInt();
Entityc entity = (Entityc)mapping[typeid].get(); Entityc entity = (Entityc)mapping[typeid].get();
EntityGroup.checkNextId(id);
entity.id(id);
entity.read(Reads.get(in)); entity.read(Reads.get(in));
entity.add(); entity.add();
}); });

View File

@@ -1,4 +1,4 @@
package mindustry.io.legacy; package mindustry.io.versions;
import arc.*; import arc.*;
import arc.struct.*; import arc.struct.*;

View File

@@ -1,4 +1,4 @@
package mindustry.io.legacy; package mindustry.io.versions;
import arc.util.*; import arc.util.*;
import arc.util.io.*; import arc.util.io.*;

View File

@@ -0,0 +1,37 @@
package mindustry.io.versions;
import arc.func.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.io.*;
import java.io.*;
/** This version did not read/write entity IDs to the save. */
public class LegacySaveVersion2 extends SaveVersion{
public LegacySaveVersion2(int version){
super(version);
}
@Override
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 -> {
int typeid = in.readUnsignedByte();
if(mapping[typeid] == null){
in.skipBytes(lastRegionLength - 1);
return;
}
Entityc entity = (Entityc)mapping[typeid].get();
entity.read(Reads.get(in));
entity.add();
});
}
}
}

View File

@@ -1,4 +1,4 @@
package mindustry.io.legacy; package mindustry.io.versions;
import java.io.*; import java.io.*;

View File

@@ -1,4 +1,4 @@
package mindustry.io.legacy; package mindustry.io.versions;
import java.io.*; import java.io.*;

View File

@@ -1,4 +1,4 @@
package mindustry.io.legacy; package mindustry.io.versions;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Teams.*; import mindustry.game.Teams.*;

View File

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

View File

@@ -1,8 +1,7 @@
package mindustry.io.versions; package mindustry.io.versions;
import mindustry.io.*; /** Uses the legacy readWorldEntities function without entity IDs. */
public class Save5 extends LegacySaveVersion2{
public class Save5 extends SaveVersion{
public Save5(){ public Save5(){
super(5); super(5);

View File

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

View File

@@ -16,7 +16,7 @@ import mindustry.core.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.io.legacy.*; import mindustry.io.versions.*;
import mindustry.net.*; import mindustry.net.*;
import mindustry.net.Packets.*; import mindustry.net.Packets.*;
import mindustry.ui.*; import mindustry.ui.*;