From fce30e6ae562ca4ae8dcbe699bf5f44ac47c574c Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 5 Mar 2021 17:22:44 -0500 Subject: [PATCH] Sync based on system time --- core/src/mindustry/core/NetServer.java | 10 ++++++---- core/src/mindustry/entities/comp/UnitComp.java | 1 - core/src/mindustry/net/NetConnection.java | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index 565134b9a9..bead4b8a92 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -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); diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index 1db14dcc41..18c04df545 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -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 diff --git a/core/src/mindustry/net/NetConnection.java b/core/src/mindustry/net/NetConnection.java index be2455c53a..1d5cec3143 100644 --- a/core/src/mindustry/net/NetConnection.java +++ b/core/src/mindustry/net/NetConnection.java @@ -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();