Write synced entities in world data
This commit is contained in:
@@ -359,13 +359,7 @@ public class NetClient implements ApplicationListener{
|
|||||||
Groups.player.removeByID(playerid);
|
Groups.player.removeByID(playerid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
public static void readSyncEntity(DataInputStream input, Reads read) throws IOException{
|
||||||
public static void entitySnapshot(short amount, byte[] data){
|
|
||||||
try{
|
|
||||||
netClient.byteStream.setBytes(data);
|
|
||||||
DataInputStream input = netClient.dataStream;
|
|
||||||
|
|
||||||
for(int j = 0; j < amount; j++){
|
|
||||||
int id = input.readInt();
|
int id = input.readInt();
|
||||||
byte typeID = input.readByte();
|
byte typeID = input.readByte();
|
||||||
|
|
||||||
@@ -388,7 +382,7 @@ public class NetClient implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//read the entity
|
//read the entity
|
||||||
entity.readSync(Reads.get(input));
|
entity.readSync(read);
|
||||||
|
|
||||||
if(created){
|
if(created){
|
||||||
//snap initial starting position
|
//snap initial starting position
|
||||||
@@ -400,6 +394,16 @@ public class NetClient implements ApplicationListener{
|
|||||||
netClient.addRemovedEntity(entity.id());
|
netClient.addRemovedEntity(entity.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
||||||
|
public static void entitySnapshot(short amount, byte[] data){
|
||||||
|
try{
|
||||||
|
netClient.byteStream.setBytes(data);
|
||||||
|
DataInputStream input = netClient.dataStream;
|
||||||
|
|
||||||
|
for(int j = 0; j < amount; j++){
|
||||||
|
readSyncEntity(input, Reads.get(input));
|
||||||
|
}
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -667,6 +667,13 @@ public class TypeIO{
|
|||||||
public Building unbox(){
|
public Building unbox(){
|
||||||
return world.build(pos);
|
return world.build(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "BuildingBox{" +
|
||||||
|
"pos=" + pos +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Represents a unit that has not been resolved yet. TODO unimplemented / unused*/
|
/** Represents a unit that has not been resolved yet. TODO unimplemented / unused*/
|
||||||
@@ -680,5 +687,12 @@ public class TypeIO{
|
|||||||
public Unit unbox(){
|
public Unit unbox(){
|
||||||
return Groups.unit.getByID(id);
|
return Groups.unit.getByID(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "UnitBox{" +
|
||||||
|
"id=" + id +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,19 @@ public class NetworkIO{
|
|||||||
stream.writeLong(GlobalConstants.rand.seed0);
|
stream.writeLong(GlobalConstants.rand.seed0);
|
||||||
stream.writeLong(GlobalConstants.rand.seed1);
|
stream.writeLong(GlobalConstants.rand.seed1);
|
||||||
|
|
||||||
|
Writes write = new Writes(stream);
|
||||||
|
|
||||||
stream.writeInt(player.id);
|
stream.writeInt(player.id);
|
||||||
player.write(Writes.get(stream));
|
player.write(write);
|
||||||
|
|
||||||
|
stream.writeInt(Groups.sync.size());
|
||||||
|
|
||||||
|
//write all synced entities *immediately*
|
||||||
|
for(Syncc entity : Groups.sync){
|
||||||
|
stream.writeInt(entity.id());
|
||||||
|
stream.writeByte(entity.classId());
|
||||||
|
entity.writeSync(write);
|
||||||
|
}
|
||||||
|
|
||||||
SaveIO.getSaveWriter().writeContentHeader(stream);
|
SaveIO.getSaveWriter().writeContentHeader(stream);
|
||||||
SaveIO.getSaveWriter().writeMap(stream);
|
SaveIO.getSaveWriter().writeMap(stream);
|
||||||
@@ -68,13 +79,21 @@ public class NetworkIO{
|
|||||||
GlobalConstants.rand.seed0 = stream.readLong();
|
GlobalConstants.rand.seed0 = stream.readLong();
|
||||||
GlobalConstants.rand.seed1 = stream.readLong();
|
GlobalConstants.rand.seed1 = stream.readLong();
|
||||||
|
|
||||||
|
Reads read = new Reads(stream);
|
||||||
|
|
||||||
Groups.clear();
|
Groups.clear();
|
||||||
int id = stream.readInt();
|
int id = stream.readInt();
|
||||||
player.reset();
|
player.reset();
|
||||||
player.read(Reads.get(stream));
|
player.read(read);
|
||||||
player.id = id;
|
player.id = id;
|
||||||
player.add();
|
player.add();
|
||||||
|
|
||||||
|
int entities = stream.readInt();
|
||||||
|
|
||||||
|
for(int j = 0; j < entities; j++){
|
||||||
|
NetClient.readSyncEntity(stream, read);
|
||||||
|
}
|
||||||
|
|
||||||
SaveIO.getSaveWriter().readContentHeader(stream);
|
SaveIO.getSaveWriter().readContentHeader(stream);
|
||||||
SaveIO.getSaveWriter().readMap(stream, world.context);
|
SaveIO.getSaveWriter().readMap(stream, world.context);
|
||||||
SaveIO.getSaveWriter().readTeamBlocks(stream);
|
SaveIO.getSaveWriter().readTeamBlocks(stream);
|
||||||
|
|||||||
Reference in New Issue
Block a user