Implemented authoritative movement/shooting, fixed netbugs

This commit is contained in:
Anuken
2018-06-13 17:06:46 -04:00
parent 4ca9a26bdd
commit c077f6e1e8
17 changed files with 268 additions and 87 deletions
@@ -18,6 +18,8 @@ public abstract class NetConnection {
/**ID of last recieved client snapshot.*/
public int lastRecievedSnapshot = -1;
/**Timestamp of last recieved snapshot.*/
public long lastRecievedTime;
public NetConnection(int id, String address){
this.id = id;
@@ -63,9 +63,9 @@ public class NetworkIO {
for(int y = 0; y < world.height(); y ++){
Tile tile = world.tile(x, y);
//TODO will break if block number gets over BYTE_MAX
stream.writeByte(tile.floor().id); //floor ID
stream.writeByte(tile.block().id); //block ID
stream.writeByte(tile.elevation);
if(tile.block() instanceof BlockPart){
stream.writeByte(tile.link);
@@ -162,9 +162,12 @@ public class NetworkIO {
for(int y = 0; y < height; y ++){
byte floorid = stream.readByte();
byte blockid = stream.readByte();
byte elevation = stream.readByte();
Tile tile = new Tile(x, y, floorid, blockid);
tile.elevation = elevation;
if(tile.block() == Blocks.blockpart){
tile.link = stream.readByte();
}
@@ -189,8 +192,6 @@ public class NetworkIO {
}
}
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
player.reset();
state.teams = new TeamInfo();
+5 -1
View File
@@ -101,7 +101,7 @@ public class Packets {
public int snapid;
public long timeSent;
//player snapshot data
public float x, y, rotation, baseRotation, xv, yv;
public float x, y, pointerX, pointerY, rotation, baseRotation, xv, yv;
@Override
public void write(ByteBuffer buffer) {
@@ -113,6 +113,8 @@ public class Packets {
buffer.putFloat(player.x);
buffer.putFloat(player.y);
buffer.putFloat(player.pointerX);
buffer.putFloat(player.pointerY);
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));
@@ -129,6 +131,8 @@ public class Packets {
x = buffer.getFloat();
y = buffer.getFloat();
pointerX = buffer.getFloat();
pointerY = buffer.getFloat();
xv = buffer.get() / Unit.velocityPercision;
yv = buffer.get() / Unit.velocityPercision;
rotation = buffer.getShort()/2f;