mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 15:19:24 +07:00
Fixed build errors
This commit is contained in:
parent
2bcbc3294b
commit
0bd0602655
@ -27,7 +27,7 @@ allprojects {
|
||||
gdxVersion = '1.9.8'
|
||||
roboVMVersion = '2.3.0'
|
||||
aiVersion = '1.8.1'
|
||||
uCoreVersion = '32c8405'
|
||||
uCoreVersion = '382d7b2'
|
||||
|
||||
getVersionString = {
|
||||
String buildVersion = getBuildVersion()
|
||||
|
@ -7,6 +7,8 @@ import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
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.io.Version;
|
||||
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.entities.Entities;
|
||||
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.util.Log;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@ -37,6 +45,13 @@ public class NetServer extends Module{
|
||||
private boolean closing = false;
|
||||
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(){
|
||||
|
||||
Net.handleServer(Connect.class, (id, connect) -> {
|
||||
@ -170,19 +185,56 @@ public class NetServer extends Module{
|
||||
}
|
||||
|
||||
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(Player player : connections.values()){
|
||||
for (EntityGroup<?> group : Entities.getAllGroups()) {
|
||||
if (!group.isEmpty() && (group.all().get(0) instanceof SyncTrait)) totalGroups ++;
|
||||
}
|
||||
|
||||
//check for syncable groups.
|
||||
for(EntityGroup<?> group : Entities.getAllGroups()){
|
||||
if(group.isEmpty()) continue;
|
||||
//write total amount of serializable groups
|
||||
dataStream.writeByte(totalGroups);
|
||||
|
||||
//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)
|
||||
|
@ -6,6 +6,13 @@ public abstract class NetConnection {
|
||||
public final int id;
|
||||
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){
|
||||
this.id = id;
|
||||
this.address = address;
|
||||
|
@ -1,5 +1,17 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
|
||||
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.ucore.io.ByteBufferOutput;
|
||||
import io.anuke.ucore.io.IOUtils;
|
||||
import io.anuke.ucore.io.delta.ByteBufferInput;
|
||||
import io.anuke.ucore.io.ByteBufferInput;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user