Sync based on system time

This commit is contained in:
Anuken 2021-03-05 17:22:44 -05:00
parent 24195dac81
commit fce30e6ae5
3 changed files with 7 additions and 5 deletions

View file

@ -35,8 +35,8 @@ import static mindustry.Vars.*;
public class NetServer implements ApplicationListener{
/** note that snapshots are compressed, so the max snapshot size here is above the typical UDP safe limit */
private static final int maxSnapshotSize = 800, timerBlockSync = 0;
private static final float serverSyncTime = 12, blockSyncTime = 60 * 6;
private static final int maxSnapshotSize = 800, timerBlockSync = 0, serverSyncTime = 200;
private static final float blockSyncTime = 60 * 6;
private static final FloatBuffer fbuffer = FloatBuffer.allocate(20);
private static final Vec2 vector = new Vec2();
private static final Rect viewport = new Rect();
@ -967,9 +967,11 @@ public class NetServer implements ApplicationListener{
return;
}
NetConnection connection = player.con;
var connection = player.con;
if(!player.timer(0, serverSyncTime) || !connection.hasConnected) return;
if(Time.timeSinceMillis(connection.syncTime) < serverSyncTime || !connection.hasConnected) return;
connection.syncTime = Time.millis();
try{
writeEntitySnapshot(player);

View file

@ -164,7 +164,6 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
pay.payloads().peek() instanceof BuildPayload p2 ? p2.block() : null) : null;
default -> noSensed;
};
}
@Override

View file

@ -18,6 +18,7 @@ public abstract class NetConnection{
public boolean mobile, modclient;
public @Nullable Player player;
public boolean kicked = false;
public long syncTime;
/** When this connection was established. */
public long connectTime = Time.millis();