First client/server snapshot implementation
This commit is contained in:
@@ -7,9 +7,12 @@ public abstract class NetConnection {
|
||||
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 int lastSnapshotID = -1;
|
||||
/**Byte array of last sent snapshot data that is confirmed to be recieved.*/
|
||||
public byte[] lastSnapshot;
|
||||
|
||||
/**ID of last sent snapshot.*/
|
||||
public int lastSentSnapshotID = -1;
|
||||
/**Byte array of last sent snapshot.*/
|
||||
public byte[] lastSentSnapshot;
|
||||
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,11 +100,13 @@ public class Packets {
|
||||
|
||||
public static class ClientSnapshotPacket implements Packet{
|
||||
public Player player;
|
||||
public int lastSnapshot;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
ByteBufferOutput out = new ByteBufferOutput(buffer);
|
||||
|
||||
buffer.putInt(lastSnapshot);
|
||||
buffer.putInt(player.id);
|
||||
buffer.putLong(TimeUtils.millis());
|
||||
player.write(out);
|
||||
@@ -114,6 +116,7 @@ public class Packets {
|
||||
public void read(ByteBuffer buffer) {
|
||||
ByteBufferInput in = new ByteBufferInput(buffer);
|
||||
|
||||
lastSnapshot = buffer.getInt();
|
||||
int id = buffer.getInt();
|
||||
long time = buffer.getLong();
|
||||
player = Vars.playerGroup.getByID(id);
|
||||
|
||||
Reference in New Issue
Block a user