Fixed some snapshot bugs, net crashes
This commit is contained in:
@@ -56,7 +56,7 @@ public class NetClient extends Module {
|
||||
/**Counter of how many chunks have been recieved.*/
|
||||
private int recievedChunkCounter;
|
||||
/**ID of snapshot that is currently being constructed.*/
|
||||
private int currentSnapshotID;
|
||||
private int currentSnapshotID = -1;
|
||||
/**Last snapshot ID recieved.*/
|
||||
private int lastSnapshotID = -1;
|
||||
/**Decoder for uncompressing snapshots.*/
|
||||
@@ -82,7 +82,7 @@ public class NetClient extends Module {
|
||||
lastSent = 0;
|
||||
lastSnapshot = null;
|
||||
currentSnapshot = null;
|
||||
currentSnapshotID = 0;
|
||||
currentSnapshotID = -1;
|
||||
lastSnapshotID = -1;
|
||||
|
||||
ui.chatfrag.clearMessages();
|
||||
@@ -285,7 +285,7 @@ public class NetClient extends Module {
|
||||
if (snapshotID == 0) { //fresh snapshot
|
||||
result = snapshot;
|
||||
length = snapshot.length;
|
||||
netClient.lastSnapshot = snapshot;
|
||||
netClient.lastSnapshot = Arrays.copyOf(snapshot, snapshot.length);
|
||||
} else { //otherwise, last snapshot must not be null, decode it
|
||||
netClient.decoder.init(netClient.lastSnapshot, snapshot);
|
||||
result = netClient.decoder.decode();
|
||||
|
||||
@@ -41,6 +41,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class NetServer extends Module{
|
||||
public final static int maxSnapshotSize = 2047;
|
||||
|
||||
private final static byte[] reusableSnapArray = new byte[maxSnapshotSize];
|
||||
private final static boolean showSnapshotSize = false;
|
||||
private final static float serverSyncTime = 4, kickDuration = 30 * 1000;
|
||||
private final static Vector2 vector = new Vector2();
|
||||
@@ -429,8 +430,13 @@ public class NetServer extends Module{
|
||||
int chunkid = 0;
|
||||
while(remaining > 0){
|
||||
int used = Math.min(remaining, maxSnapshotSize);
|
||||
//TODO optimize to *not* copy the bytes directly, but instead re-use all arrays that are of length = maxSnapshotSize
|
||||
byte[] toSend = Arrays.copyOfRange(bytes, offset, Math.min(offset + maxSnapshotSize, bytes.length));
|
||||
byte[] toSend;
|
||||
if(used == maxSnapshotSize){
|
||||
toSend = reusableSnapArray;
|
||||
System.arraycopy(bytes, offset, toSend, 0, Math.min(offset + maxSnapshotSize, bytes.length) - offset);
|
||||
}else {
|
||||
toSend = Arrays.copyOfRange(bytes, offset, Math.min(offset + maxSnapshotSize, bytes.length));
|
||||
}
|
||||
Call.onSnapshot(userid, toSend, snapshotID, (short)chunkid, (short)bytes.length);
|
||||
|
||||
remaining -= used;
|
||||
|
||||
@@ -38,6 +38,12 @@ public class Interpolator {
|
||||
|
||||
public void update(){
|
||||
|
||||
if(pos.dst(target) > 128){
|
||||
pos.set(target);
|
||||
lastUpdated = 0;
|
||||
updateSpacing = 16;
|
||||
}
|
||||
|
||||
if(lastUpdated != 0 && updateSpacing != 0){
|
||||
float timeSinceUpdate = TimeUtils.timeSinceMillis(lastUpdated);
|
||||
float alpha = Math.min(timeSinceUpdate / updateSpacing, 2f);
|
||||
|
||||
@@ -126,8 +126,11 @@ public class Weapon extends Upgrade {
|
||||
}
|
||||
|
||||
void bullet(ShooterTrait owner, float x, float y, float angle){
|
||||
if(owner == null || !owner.getInventory().hasAmmo()) return;
|
||||
|
||||
tr.trns(angle, 3f);
|
||||
Bullet.create(owner.getInventory().getAmmo().bullet, owner, owner.getTeam(), x + tr.x, y + tr.y, angle, (1f-velocityRnd) + Mathf.random(velocityRnd));
|
||||
Bullet.create(owner.getInventory().getAmmo().bullet,
|
||||
owner, owner.getTeam(), x + tr.x, y + tr.y, angle, (1f-velocityRnd) + Mathf.random(velocityRnd));
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, in = In.entities, unreliable = true)
|
||||
|
||||
Reference in New Issue
Block a user