Improved snapshot netcode

This commit is contained in:
Anuken
2018-12-29 22:46:46 -05:00
parent 7c35b6e95a
commit d01b8c7ad1
17 changed files with 99 additions and 216 deletions

View File

@@ -15,7 +15,7 @@ public class Interpolator{
public Vector2 pos = new Vector2();
public float[] values = {};
public void read(float cx, float cy, float x, float y, long sent, float... target1ds){
public void read(float cx, float cy, float x, float y, float... target1ds){
if(lastUpdated != 0) updateSpacing = Time.timeSinceMillis(lastUpdated);
lastUpdated = Time.millis();

View File

@@ -21,6 +21,8 @@ import io.anuke.mindustry.net.Packets.StreamChunk;
import io.anuke.mindustry.net.Streamable.StreamBuilder;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import static io.anuke.mindustry.Vars.*;
@@ -58,7 +60,9 @@ public class Net{
String error = t.getMessage() == null ? "" : t.getMessage().toLowerCase();
String type = t.getClass().toString().toLowerCase();
if(error.equals("mismatch")){
if(e instanceof BufferUnderflowException || e instanceof BufferOverflowException){
error = Core.bundle.get("text.error.io");
}else if(error.equals("mismatch")){
error = Core.bundle.get("text.error.mismatch");
}else if(error.contains("port out of range") || error.contains("invalid argument") || (error.contains("invalid") && error.contains("address"))){
error = Core.bundle.get("text.error.invalidaddress");

View File

@@ -111,13 +111,6 @@ 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){
throw new RuntimeException(e);
}
@@ -163,7 +156,7 @@ public class NetworkIO{
Entities.clear();
int id = stream.readInt();
player.resetNoAdd();
player.read(stream, Time.millis());
player.read(stream);
player.resetID(id);
player.add();
@@ -252,9 +245,6 @@ public class NetworkIO{
world.endMapLoad();
//read raw snapshot
netClient.readSnapshot(stream);
}catch(IOException e){
throw new RuntimeException(e);
}