Fixed some snapshot bugs, net crashes
This commit is contained in:
@@ -27,7 +27,7 @@ allprojects {
|
|||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
roboVMVersion = '2.3.0'
|
roboVMVersion = '2.3.0'
|
||||||
aiVersion = '1.8.1'
|
aiVersion = '1.8.1'
|
||||||
uCoreVersion = 'dbc818f4ab'
|
uCoreVersion = '5d685fc8b1'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class NetClient extends Module {
|
|||||||
/**Counter of how many chunks have been recieved.*/
|
/**Counter of how many chunks have been recieved.*/
|
||||||
private int recievedChunkCounter;
|
private int recievedChunkCounter;
|
||||||
/**ID of snapshot that is currently being constructed.*/
|
/**ID of snapshot that is currently being constructed.*/
|
||||||
private int currentSnapshotID;
|
private int currentSnapshotID = -1;
|
||||||
/**Last snapshot ID recieved.*/
|
/**Last snapshot ID recieved.*/
|
||||||
private int lastSnapshotID = -1;
|
private int lastSnapshotID = -1;
|
||||||
/**Decoder for uncompressing snapshots.*/
|
/**Decoder for uncompressing snapshots.*/
|
||||||
@@ -82,7 +82,7 @@ public class NetClient extends Module {
|
|||||||
lastSent = 0;
|
lastSent = 0;
|
||||||
lastSnapshot = null;
|
lastSnapshot = null;
|
||||||
currentSnapshot = null;
|
currentSnapshot = null;
|
||||||
currentSnapshotID = 0;
|
currentSnapshotID = -1;
|
||||||
lastSnapshotID = -1;
|
lastSnapshotID = -1;
|
||||||
|
|
||||||
ui.chatfrag.clearMessages();
|
ui.chatfrag.clearMessages();
|
||||||
@@ -285,7 +285,7 @@ public class NetClient extends Module {
|
|||||||
if (snapshotID == 0) { //fresh snapshot
|
if (snapshotID == 0) { //fresh snapshot
|
||||||
result = snapshot;
|
result = snapshot;
|
||||||
length = snapshot.length;
|
length = snapshot.length;
|
||||||
netClient.lastSnapshot = snapshot;
|
netClient.lastSnapshot = Arrays.copyOf(snapshot, snapshot.length);
|
||||||
} else { //otherwise, last snapshot must not be null, decode it
|
} else { //otherwise, last snapshot must not be null, decode it
|
||||||
netClient.decoder.init(netClient.lastSnapshot, snapshot);
|
netClient.decoder.init(netClient.lastSnapshot, snapshot);
|
||||||
result = netClient.decoder.decode();
|
result = netClient.decoder.decode();
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
public class NetServer extends Module{
|
public class NetServer extends Module{
|
||||||
public final static int maxSnapshotSize = 2047;
|
public final static int maxSnapshotSize = 2047;
|
||||||
|
|
||||||
|
private final static byte[] reusableSnapArray = new byte[maxSnapshotSize];
|
||||||
private final static boolean showSnapshotSize = false;
|
private final static boolean showSnapshotSize = false;
|
||||||
private final static float serverSyncTime = 4, kickDuration = 30 * 1000;
|
private final static float serverSyncTime = 4, kickDuration = 30 * 1000;
|
||||||
private final static Vector2 vector = new Vector2();
|
private final static Vector2 vector = new Vector2();
|
||||||
@@ -429,8 +430,13 @@ public class NetServer extends Module{
|
|||||||
int chunkid = 0;
|
int chunkid = 0;
|
||||||
while(remaining > 0){
|
while(remaining > 0){
|
||||||
int used = Math.min(remaining, maxSnapshotSize);
|
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;
|
||||||
byte[] toSend = Arrays.copyOfRange(bytes, offset, Math.min(offset + maxSnapshotSize, bytes.length));
|
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);
|
Call.onSnapshot(userid, toSend, snapshotID, (short)chunkid, (short)bytes.length);
|
||||||
|
|
||||||
remaining -= used;
|
remaining -= used;
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ public class Interpolator {
|
|||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
|
if(pos.dst(target) > 128){
|
||||||
|
pos.set(target);
|
||||||
|
lastUpdated = 0;
|
||||||
|
updateSpacing = 16;
|
||||||
|
}
|
||||||
|
|
||||||
if(lastUpdated != 0 && updateSpacing != 0){
|
if(lastUpdated != 0 && updateSpacing != 0){
|
||||||
float timeSinceUpdate = TimeUtils.timeSinceMillis(lastUpdated);
|
float timeSinceUpdate = TimeUtils.timeSinceMillis(lastUpdated);
|
||||||
float alpha = Math.min(timeSinceUpdate / updateSpacing, 2f);
|
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){
|
void bullet(ShooterTrait owner, float x, float y, float angle){
|
||||||
|
if(owner == null || !owner.getInventory().hasAmmo()) return;
|
||||||
|
|
||||||
tr.trns(angle, 3f);
|
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)
|
@Remote(targets = Loc.server, called = Loc.both, in = In.entities, unreliable = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user