mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-10-01 18:50:27 +03:00
Building afterReadAll fix + Send entities over network (possibly unstable)
This commit is contained in:
@@ -385,7 +385,7 @@ public class NetClient implements ApplicationListener{
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(called = Loc.client, variants = Variant.one)
|
||||
@Remote(called = Loc.client, variants = Variant.one, priority = PacketPriority.high)
|
||||
public static void connect(String ip, int port){
|
||||
if(!steam && (ip.startsWith("steam:") || ip.startsWith("steamserver:"))) return;
|
||||
netClient.disconnectQuietly();
|
||||
|
||||
@@ -109,7 +109,7 @@ public class MapIO{
|
||||
if(ver.version >= 12) ver.skipChunk(stream);
|
||||
ver.readRegion("content", stream, counter, MapIO::readPreviewContentHeader);
|
||||
if(ver.version == 11) ver.skipChunk(stream);
|
||||
ver.readRegion("preview_map", stream, counter, in -> ver.readMap(in, new WorldContext(){
|
||||
ver.readRegion("preview_map", stream, counter, in -> ver.readMap(in, new SaveReadState(new WorldContext(){
|
||||
@Override public void resize(int width, int height){}
|
||||
@Override public boolean isGenerating(){return false;}
|
||||
@Override public void begin(){
|
||||
@@ -179,7 +179,9 @@ public class MapIO{
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}){{
|
||||
preview = true;
|
||||
}}));
|
||||
|
||||
floors.draw(walls, true);
|
||||
walls.dispose();
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package mindustry.io;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class SaveReadState{
|
||||
public final WorldContext context;
|
||||
/** true when generating a map preview */
|
||||
public boolean preview;
|
||||
public @Nullable String ruleString;
|
||||
public Seq<Building> allBuildings = new Seq<>();
|
||||
|
||||
public SaveReadState(WorldContext context){
|
||||
this.context = context;
|
||||
|
||||
@@ -66,8 +66,8 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
|
||||
try{
|
||||
readRegion("content", stream, counter, this::readContentHeader);
|
||||
readRegion("map", stream, counter, in -> readMap(in, saveState.context));
|
||||
readRegion("entities", stream, counter, this::readEntities);
|
||||
readRegion("map", stream, counter, in -> readMap(in, saveState));
|
||||
readRegion("entities", stream, counter, stream1 -> readEntities(stream1, saveState));
|
||||
if(version >= 8) readRegion("markers", stream, counter, this::readMarkers);
|
||||
readRegion("custom", stream, counter, this::readCustomChunks);
|
||||
}finally{
|
||||
@@ -288,7 +288,8 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
}
|
||||
}
|
||||
|
||||
public void readMap(DataInput stream, WorldContext context) throws IOException{
|
||||
public void readMap(DataInput stream, SaveReadState state) throws IOException{
|
||||
var context = state.context;
|
||||
int width = stream.readUnsignedShort();
|
||||
int height = stream.readUnsignedShort();
|
||||
|
||||
@@ -345,7 +346,10 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
//set block only if this is the center; otherwise, it's handled elsewhere
|
||||
if(isCenter){
|
||||
tile.setBlock(block);
|
||||
if(tile.build != null) tile.build.enabled = true;
|
||||
if(tile.build != null){
|
||||
if(!state.preview) state.allBuildings.add(tile.build);
|
||||
tile.build.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
//must be assigned after setBlock, because that can reset data
|
||||
@@ -481,7 +485,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
}
|
||||
}
|
||||
|
||||
public void readWorldEntities(DataInput stream, Prov[] mapping) throws IOException{
|
||||
public void readWorldEntities(DataInput stream, Prov[] mapping, SaveReadState state) throws IOException{
|
||||
IntSet used = new IntSet();
|
||||
Seq<Entityc> reassign = new Seq<>();
|
||||
|
||||
@@ -516,7 +520,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
|
||||
Groups.all.each(Entityc::afterReadAll);
|
||||
Groups.unit.each(Entityc::afterReadAll);
|
||||
Groups.build.each(Entityc::afterReadAll);
|
||||
state.allBuildings.each(Buildingc::afterReadAll);
|
||||
}
|
||||
|
||||
public Prov[] readEntityMapping(DataInput stream) throws IOException{
|
||||
@@ -535,10 +539,10 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
return entityMapping;
|
||||
}
|
||||
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
public void readEntities(DataInput stream, SaveReadState state) throws IOException{
|
||||
var mapping = readEntityMapping(stream);
|
||||
readTeamBlocks(stream);
|
||||
readWorldEntities(stream, mapping);
|
||||
readWorldEntities(stream, mapping, state);
|
||||
}
|
||||
|
||||
public void readDataPatches(DataInput stream, SaveReadState saveState) throws IOException{
|
||||
|
||||
@@ -20,8 +20,8 @@ public class LegacyRegionSaveVersion extends ShortChunkSaveVersion{
|
||||
readRegion("content", stream, counter, this::readContentHeader);
|
||||
|
||||
try{
|
||||
readRegion("map", stream, counter, in -> readMap(in, saveState.context));
|
||||
readRegion("entities", stream, counter, this::readEntities);
|
||||
readRegion("map", stream, counter, in -> readMap(in, saveState));
|
||||
readRegion("entities", stream, counter, in -> readEntities(in, saveState));
|
||||
}finally{
|
||||
content.setTemporaryMapper(null);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package mindustry.io.versions;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
@@ -16,7 +17,8 @@ public abstract class LegacySaveVersion extends LegacyRegionSaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMap(DataInput stream, WorldContext context) throws IOException{
|
||||
public void readMap(DataInput stream, SaveReadState state) throws IOException{
|
||||
var context = state.context;
|
||||
int width = stream.readUnsignedShort();
|
||||
int height = stream.readUnsignedShort();
|
||||
|
||||
@@ -56,7 +58,10 @@ public abstract class LegacySaveVersion extends LegacyRegionSaveVersion{
|
||||
//do not override occupied cells
|
||||
if(!occupied){
|
||||
tile.setBlock(block);
|
||||
if(tile.build != null) tile.build.enabled = true;
|
||||
if(tile.build != null){
|
||||
if(!state.preview) state.allBuildings.add(tile.build);
|
||||
tile.build.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(block.hasBuilding()){
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.io.versions;
|
||||
|
||||
import arc.func.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -13,7 +14,7 @@ public class LegacySaveVersion2 extends LegacyRegionSaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readWorldEntities(DataInput stream, Prov[] mapping) throws IOException{
|
||||
public void readWorldEntities(DataInput stream, Prov[] mapping, SaveReadState state) throws IOException{
|
||||
|
||||
int amount = stream.readInt();
|
||||
for(int j = 0; j < amount; j++){
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mindustry.io.versions;
|
||||
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class Save1 extends LegacySaveVersion{
|
||||
@@ -9,7 +11,7 @@ public class Save1 extends LegacySaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
public void readEntities(DataInput stream, SaveReadState state) throws IOException{
|
||||
readLegacyEntities(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class Save11 extends SaveVersion{
|
||||
|
||||
try{
|
||||
readRegion("patches", stream, counter, in -> readDataPatches(in, saveState));
|
||||
readRegion("map", stream, counter, in -> readMap(in, saveState.context));
|
||||
readRegion("entities", stream, counter, this::readEntities);
|
||||
readRegion("map", stream, counter, in -> readMap(in, saveState));
|
||||
readRegion("entities", stream, counter, in -> readEntities(in, saveState));
|
||||
readRegion("markers", stream, counter, this::readMarkers);
|
||||
readRegion("custom", stream, counter, this::readCustomChunks);
|
||||
}finally{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mindustry.io.versions;
|
||||
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class Save2 extends LegacySaveVersion{
|
||||
@@ -9,7 +11,7 @@ public class Save2 extends LegacySaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
public void readEntities(DataInput stream, SaveReadState state) throws IOException{
|
||||
readLegacyEntities(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.io.versions;
|
||||
|
||||
import mindustry.game.*;
|
||||
import mindustry.game.Teams.*;
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -14,7 +15,7 @@ public class Save3 extends LegacySaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
public void readEntities(DataInput stream, SaveReadState state) throws IOException{
|
||||
int teamc = stream.readInt();
|
||||
for(int i = 0; i < teamc; i++){
|
||||
Team team = Team.get(stream.readInt());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.io.versions;
|
||||
|
||||
import mindustry.gen.*;
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -12,9 +13,9 @@ public class Save4 extends LegacySaveVersion2{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
public void readEntities(DataInput stream, SaveReadState state) throws IOException{
|
||||
readTeamBlocks(stream);
|
||||
readWorldEntities(stream, EntityMapping.idMap);
|
||||
readWorldEntities(stream, EntityMapping.idMap, state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ShortChunkSaveVersion extends SaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readWorldEntities(DataInput stream, Prov[] mapping) throws IOException{
|
||||
public void readWorldEntities(DataInput stream, Prov[] mapping, SaveReadState state) throws IOException{
|
||||
|
||||
int amount = stream.readInt();
|
||||
for(int j = 0; j < amount; j++){
|
||||
@@ -45,7 +45,8 @@ public class ShortChunkSaveVersion extends SaveVersion{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMap(DataInput stream, WorldContext context) throws IOException{
|
||||
public void readMap(DataInput stream, SaveReadState state) throws IOException{
|
||||
var context = state.context;
|
||||
int width = stream.readUnsignedShort();
|
||||
int height = stream.readUnsignedShort();
|
||||
|
||||
@@ -103,7 +104,10 @@ public class ShortChunkSaveVersion extends SaveVersion{
|
||||
//set block only if this is the center; otherwise, it's handled elsewhere
|
||||
if(isCenter){
|
||||
tile.setBlock(block);
|
||||
if(tile.build != null) tile.build.enabled = true;
|
||||
if(tile.build != null){
|
||||
if(!state.preview) state.allBuildings.add(tile.build);
|
||||
tile.build.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
//must be assigned after setBlock, because that can reset data
|
||||
|
||||
@@ -60,6 +60,7 @@ public class NetworkIO{
|
||||
|
||||
SaveIO.getSaveWriter().writeContentHeader(stream);
|
||||
SaveIO.getSaveWriter().writeMap(stream);
|
||||
SaveIO.getSaveWriter().writeEntities(stream);
|
||||
SaveIO.getSaveWriter().writeTeamBlocks(stream);
|
||||
SaveIO.getSaveWriter().writeMarkers(stream);
|
||||
SaveIO.getSaveWriter().writeCustomChunks(stream, true);
|
||||
@@ -93,8 +94,11 @@ public class NetworkIO{
|
||||
player.id = id;
|
||||
player.add();
|
||||
|
||||
var state = new SaveReadState(world.context);
|
||||
|
||||
SaveIO.getSaveWriter().readContentHeader(stream);
|
||||
SaveIO.getSaveWriter().readMap(stream, world.context);
|
||||
SaveIO.getSaveWriter().readMap(stream, state);
|
||||
SaveIO.getSaveWriter().readEntities(stream, state);
|
||||
SaveIO.getSaveWriter().readTeamBlocks(stream);
|
||||
SaveIO.getSaveWriter().readMarkers(stream);
|
||||
SaveIO.getSaveWriter().readCustomChunks(stream);
|
||||
|
||||
Reference in New Issue
Block a user