Removed delta compression / Removed client snapshot packet
This commit is contained in:
@@ -1,28 +1,12 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
|
||||
public abstract class NetConnection{
|
||||
public final int id;
|
||||
public final String address;
|
||||
|
||||
/**
|
||||
* The current base snapshot that the client is absolutely confirmed to have recieved.
|
||||
* All sent snapshots should be taking the diff from this base snapshot, if it isn't null.
|
||||
*/
|
||||
//public byte[] currentBaseSnapshot;
|
||||
/**
|
||||
* ID of the current base snapshot.
|
||||
*/
|
||||
// public int currentBaseID = -1;
|
||||
|
||||
//public int lastSentBase = -1;
|
||||
// public byte[] lastSentSnapshot;
|
||||
//public byte[] lastSentRawSnapshot;
|
||||
public int lastRecievedSnapshotID = -1;
|
||||
public int lastSentSnapshotID = -1;
|
||||
public IntMap<byte[]> sent = new IntMap<>();
|
||||
|
||||
/**ID of last recieved client snapshot.*/
|
||||
public int lastRecievedClientSnapshot = -1;
|
||||
@@ -31,6 +15,7 @@ public abstract class NetConnection{
|
||||
|
||||
public boolean hasConnected = false;
|
||||
public boolean hasBegunConnecting = false;
|
||||
public float viewWidth, viewHeight, viewX, viewY;
|
||||
|
||||
public NetConnection(int id, String address){
|
||||
this.id = id;
|
||||
|
||||
@@ -135,6 +135,10 @@ public class NetworkIO{
|
||||
}
|
||||
|
||||
//now write a snapshot.
|
||||
player.con.viewX = world.width() * tilesize/2f;
|
||||
player.con.viewY = world.height() * tilesize/2f;
|
||||
player.con.viewWidth = world.width() * tilesize;
|
||||
player.con.viewHeight = world.height() * tilesize;
|
||||
netServer.writeSnapshot(player, stream);
|
||||
|
||||
}catch(IOException e){
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||
import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.io.IOUtils;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
/**
|
||||
* Class for storing all packets.
|
||||
*/
|
||||
@@ -147,94 +136,7 @@ public class Packets{
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientSnapshotPacket implements Packet{
|
||||
//snapshot meta
|
||||
public int lastSnapshot;
|
||||
public int snapid;
|
||||
public long timeSent;
|
||||
//player snapshot data
|
||||
public float x, y, pointerX, pointerY, rotation, baseRotation, xv, yv;
|
||||
public Tile mining;
|
||||
public boolean boosting, shooting, alting;
|
||||
public Array<BuildRequest> requests = new Array<>();
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer){
|
||||
Player player = Vars.players[0];
|
||||
|
||||
buffer.putInt(lastSnapshot);
|
||||
buffer.putInt(snapid);
|
||||
buffer.putLong(TimeUtils.millis());
|
||||
|
||||
buffer.putFloat(player.x);
|
||||
buffer.putFloat(player.y);
|
||||
buffer.putFloat(player.pointerX);
|
||||
buffer.putFloat(player.pointerY);
|
||||
buffer.put(player.isBoosting ? (byte) 1 : 0);
|
||||
buffer.put(player.isShooting ? (byte) 1 : 0);
|
||||
buffer.put(player.isAlt ? (byte) 1 : 0);
|
||||
|
||||
buffer.put((byte) (Mathf.clamp(player.getVelocity().x, -Unit.maxAbsVelocity, Unit.maxAbsVelocity) * Unit.velocityPercision));
|
||||
buffer.put((byte) (Mathf.clamp(player.getVelocity().y, -Unit.maxAbsVelocity, Unit.maxAbsVelocity) * Unit.velocityPercision));
|
||||
//saving 4 bytes, yay?
|
||||
buffer.putShort((short) (player.rotation * 2));
|
||||
buffer.putShort((short) (player.baseRotation * 2));
|
||||
|
||||
buffer.putInt(player.getMineTile() == null ? -1 : player.getMineTile().packedPosition());
|
||||
|
||||
buffer.putShort((short)player.getPlaceQueue().size);
|
||||
for(BuildRequest request : player.getPlaceQueue()){
|
||||
buffer.put(request.remove ? (byte) 1 : 0);
|
||||
buffer.putInt(world.toPacked(request.x, request.y));
|
||||
if(!request.remove){
|
||||
buffer.put(request.recipe.id);
|
||||
buffer.put((byte) request.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer){
|
||||
lastSnapshot = buffer.getInt();
|
||||
snapid = buffer.getInt();
|
||||
timeSent = buffer.getLong();
|
||||
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
pointerX = buffer.getFloat();
|
||||
pointerY = buffer.getFloat();
|
||||
boosting = buffer.get() == 1;
|
||||
shooting = buffer.get() == 1;
|
||||
alting = buffer.get() == 1;
|
||||
xv = buffer.get() / Unit.velocityPercision;
|
||||
yv = buffer.get() / Unit.velocityPercision;
|
||||
rotation = buffer.getShort() / 2f;
|
||||
baseRotation = buffer.getShort() / 2f;
|
||||
mining = world.tile(buffer.getInt());
|
||||
requests.clear();
|
||||
|
||||
short reqamount = buffer.getShort();
|
||||
for(int i = 0; i < reqamount; i++){
|
||||
byte type = buffer.get();
|
||||
int position = buffer.getInt();
|
||||
BuildRequest currentRequest;
|
||||
|
||||
if(type == 1){ //remove
|
||||
currentRequest = new BuildRequest(position % world.width(), position / world.width());
|
||||
}else{ //place
|
||||
byte recipe = buffer.get();
|
||||
byte rotation = buffer.get();
|
||||
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, content.recipe(recipe));
|
||||
}
|
||||
|
||||
requests.add(currentRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the beginning of a stream.
|
||||
*/
|
||||
/**Marks the beginning of a stream.*/
|
||||
public static class StreamBegin implements Packet{
|
||||
private static int lastid;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ public class Registrator{
|
||||
new ClassEntry(StreamChunk.class, StreamChunk::new),
|
||||
new ClassEntry(WorldStream.class, WorldStream::new),
|
||||
new ClassEntry(ConnectPacket.class, ConnectPacket::new),
|
||||
new ClassEntry(ClientSnapshotPacket.class, ClientSnapshotPacket::new),
|
||||
new ClassEntry(InvokePacket.class, InvokePacket::new)
|
||||
};
|
||||
private static ObjectIntMap<Class> ids = new ObjectIntMap<>();
|
||||
|
||||
Reference in New Issue
Block a user