Fixed build errors
This commit is contained in:
@@ -27,7 +27,7 @@ allprojects {
|
|||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
roboVMVersion = '2.3.0'
|
roboVMVersion = '2.3.0'
|
||||||
aiVersion = '1.8.1'
|
aiVersion = '1.8.1'
|
||||||
uCoreVersion = '32c8405'
|
uCoreVersion = '382d7b2'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import io.anuke.annotations.Annotations.Remote;
|
|||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.gen.RemoteReadServer;
|
import io.anuke.mindustry.gen.RemoteReadServer;
|
||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
import io.anuke.mindustry.net.*;
|
import io.anuke.mindustry.net.*;
|
||||||
@@ -15,12 +17,18 @@ import io.anuke.mindustry.net.Packets.*;
|
|||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.entities.EntityGroup;
|
import io.anuke.ucore.entities.EntityGroup;
|
||||||
|
import io.anuke.ucore.entities.trait.Entity;
|
||||||
|
import io.anuke.ucore.io.delta.ByteDeltaEncoder;
|
||||||
|
import io.anuke.ucore.io.delta.ByteMatcherHash;
|
||||||
|
import io.anuke.ucore.io.delta.DEZEncoder;
|
||||||
import io.anuke.ucore.modules.Module;
|
import io.anuke.ucore.modules.Module;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
import io.anuke.ucore.util.Timer;
|
import io.anuke.ucore.util.Timer;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -37,6 +45,13 @@ public class NetServer extends Module{
|
|||||||
private boolean closing = false;
|
private boolean closing = false;
|
||||||
private Timer timer = new Timer(5);
|
private Timer timer = new Timer(5);
|
||||||
|
|
||||||
|
/**Stream for writing player sync data to.*/
|
||||||
|
private ByteArrayOutputStream syncStream = new ByteArrayOutputStream();
|
||||||
|
/**Data stream for writing player sync data to.*/
|
||||||
|
private DataOutputStream dataStream = new DataOutputStream(syncStream);
|
||||||
|
/**Encoder for computing snapshot deltas.*/
|
||||||
|
private DEZEncoder encoder = new DEZEncoder();
|
||||||
|
|
||||||
public NetServer(){
|
public NetServer(){
|
||||||
|
|
||||||
Net.handleServer(Connect.class, (id, connect) -> {
|
Net.handleServer(Connect.class, (id, connect) -> {
|
||||||
@@ -170,19 +185,56 @@ public class NetServer extends Module{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sync(){
|
void sync(){
|
||||||
//TODO implement snapshot packets w/ delta compression
|
try {
|
||||||
|
//TODO implement snapshot packets w/ delta compression
|
||||||
|
|
||||||
|
//iterate through each player
|
||||||
|
for (Player player : connections.values()) {
|
||||||
|
//reset stream to begin writing
|
||||||
|
syncStream.reset();
|
||||||
|
|
||||||
|
int totalGroups = 0;
|
||||||
|
|
||||||
//iterate through each player
|
for (EntityGroup<?> group : Entities.getAllGroups()) {
|
||||||
for(Player player : connections.values()){
|
if (!group.isEmpty() && (group.all().get(0) instanceof SyncTrait)) totalGroups ++;
|
||||||
|
}
|
||||||
|
|
||||||
//check for syncable groups.
|
//write total amount of serializable groups
|
||||||
for(EntityGroup<?> group : Entities.getAllGroups()){
|
dataStream.writeByte(totalGroups);
|
||||||
if(group.isEmpty()) continue;
|
|
||||||
|
//check for syncable groups
|
||||||
|
for (EntityGroup<?> group : Entities.getAllGroups()) {
|
||||||
|
//TODO range-check sync positions?
|
||||||
|
if (group.isEmpty() || !(group.all().get(0) instanceof SyncTrait)) continue;
|
||||||
|
|
||||||
|
//write group ID + group size
|
||||||
|
dataStream.writeByte(group.getID());
|
||||||
|
dataStream.writeShort(group.size());
|
||||||
|
|
||||||
|
for(Entity entity : group.all()){
|
||||||
|
//write all entities now
|
||||||
|
((SyncTrait)entity).write(dataStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NetConnection connection = Net.getConnection(player.clientid);
|
||||||
|
|
||||||
|
byte[] bytes = syncStream.toByteArray();
|
||||||
|
if(connection.lastSnapshot == null){
|
||||||
|
//no snapshot to diff, send it all
|
||||||
|
Call.onSnapshot(connection.id, bytes, -1);
|
||||||
|
}else{
|
||||||
|
//send diff otherwise
|
||||||
|
byte[] diff = ByteDeltaEncoder.toDiff(new ByteMatcherHash(connection.lastSnapshot, bytes), encoder);
|
||||||
|
Call.onSnapshot(connection.id, diff, connection.lastSnapshotID);
|
||||||
|
|
||||||
|
connection.lastSentSnapshot = bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}catch (IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(server = false)
|
@Remote(server = false)
|
||||||
|
|||||||
@@ -6,6 +6,13 @@ public abstract class NetConnection {
|
|||||||
public final int id;
|
public final int id;
|
||||||
public final String address;
|
public final String address;
|
||||||
|
|
||||||
|
/**ID of last snapshot this connection is guaranteed to have recieved.*/
|
||||||
|
public int lastSnapshotID;
|
||||||
|
/**Byte array of last sent snapshot data that is confirmed to be recieved..*/
|
||||||
|
public byte[] lastSnapshot;
|
||||||
|
/**Byte array of last sent snapshot.*/
|
||||||
|
public byte[] lastSentSnapshot;
|
||||||
|
|
||||||
public NetConnection(int id, String address){
|
public NetConnection(int id, String address){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
package io.anuke.mindustry.net;
|
package io.anuke.mindustry.net;
|
||||||
|
|
||||||
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
|
|
||||||
public class NetEvents {
|
public class NetEvents {
|
||||||
|
|
||||||
|
@Remote(one = true, all = false, unreliable = true)
|
||||||
|
public static void onSnapshot(byte[] snapshot, int snapshotID){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Remote(unreliable = true, server = false)
|
||||||
|
public static void onRecievedSnapshot(Player player, int snapshotID){
|
||||||
|
Net.getConnection(player.clientid).lastSnapshotID = snapshotID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import io.anuke.mindustry.net.Packet.ImportantPacket;
|
|||||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||||
import io.anuke.ucore.io.ByteBufferOutput;
|
import io.anuke.ucore.io.ByteBufferOutput;
|
||||||
import io.anuke.ucore.io.IOUtils;
|
import io.anuke.ucore.io.IOUtils;
|
||||||
import io.anuke.ucore.io.delta.ByteBufferInput;
|
import io.anuke.ucore.io.ByteBufferInput;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user