Skip to content

Commit 22c8db8

Browse files
refactor!: tick param removal (#853)
* refactor: remove tick params from ReadField, etc * disable test, fix missed send / rcv
1 parent 4b15869 commit 22c8db8

8 files changed

Lines changed: 51 additions & 83 deletions

File tree

com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,6 @@ private void NetworkVariableUpdate(ulong clientId, int behaviourIndex)
607607
writer.WriteUInt64Packed(NetworkObjectId);
608608
writer.WriteUInt16Packed(NetworkObject.GetNetworkBehaviourOrderIndex(this));
609609

610-
// Write the current tick frame
611-
// todo: this is currently done per channel, per tick. The snapshot system might improve on this
612-
writer.WriteUInt16Packed(CurrentTick);
613-
614610
bool writtenAny = false;
615611
for (int k = 0; k < NetworkVariableFields.Count; k++)
616612
{
@@ -654,10 +650,6 @@ private void NetworkVariableUpdate(ulong clientId, int behaviourIndex)
654650
{
655651
writtenAny = true;
656652

657-
// write the network tick at which this NetworkVariable was modified remotely
658-
// this will allow lag-compensation
659-
writer.WriteUInt16Packed(NetworkVariableFields[k].RemoteTick);
660-
661653
if (NetworkManager.NetworkConfig.EnsureNetworkVariableLengthSafety)
662654
{
663655
using (var varBuffer = PooledNetworkBuffer.Get())
@@ -711,9 +703,6 @@ internal static void HandleNetworkVariableDeltas(List<INetworkVariable> networkV
711703
{
712704
using (var reader = PooledNetworkReader.Get(stream))
713705
{
714-
// read the remote network tick at which this variable was written.
715-
ushort remoteTick = reader.ReadUInt16Packed();
716-
717706
for (int i = 0; i < networkVariableList.Count; i++)
718707
{
719708
ushort varSize = 0;
@@ -766,13 +755,9 @@ internal static void HandleNetworkVariableDeltas(List<INetworkVariable> networkV
766755
return;
767756
}
768757

769-
// read the local network tick at which this variable was written.
770-
// if this var was updated from our machine, this local tick will be locally valid
771-
ushort localTick = reader.ReadUInt16Packed();
772-
773758
long readStartPos = stream.Position;
774759

775-
networkVariableList[i].ReadDelta(stream, networkManager.IsServer, localTick, remoteTick);
760+
networkVariableList[i].ReadDelta(stream, networkManager.IsServer);
776761
PerformanceDataManager.Increment(ProfilerConstants.NetworkVarDeltas);
777762

778763
ProfilerStatManager.NetworkVarsRcvd.Record();
@@ -859,7 +844,7 @@ internal static void HandleNetworkVariableUpdate(List<INetworkVariable> networkV
859844

860845
long readStartPos = stream.Position;
861846

862-
networkVariableList[i].ReadField(stream, NetworkTickSystem.NoTick, NetworkTickSystem.NoTick);
847+
networkVariableList[i].ReadField(stream);
863848
PerformanceDataManager.Increment(ProfilerConstants.NetworkVarUpdates);
864849

865850
ProfilerStatManager.NetworkVarsRcvd.Record();
@@ -974,7 +959,7 @@ internal static void SetNetworkVariableData(List<INetworkVariable> networkVariab
974959

975960
long readStartPos = stream.Position;
976961

977-
networkVariableList[j].ReadField(stream, NetworkTickSystem.NoTick, NetworkTickSystem.NoTick);
962+
networkVariableList[j].ReadField(stream);
978963

979964
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety)
980965
{

com.unity.multiplayer.mlapi/Runtime/Core/SnapshotSystem.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ private void ReadBuffer(NetworkReader reader, Stream snapshotStream)
317317

318318
// todo --M1--
319319
// Review whether tick still belong in netvar or in the snapshot table.
320-
nv.ReadDelta(m_ReceivedSnapshot.Stream, m_NetworkManager.IsServer,
321-
m_NetworkManager.NetworkTickSystem.GetTick(), m_ReceivedSnapshot.Entries[i].TickWritten);
320+
nv.ReadDelta(m_ReceivedSnapshot.Stream, m_NetworkManager.IsServer);
322321
}
323322

324323
m_ReceivedSnapshot.Entries[i].Fresh = false;

com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public NetworkChannel GetChannel()
8888
}
8989

9090
/// <inheritdoc />
91-
public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
91+
public void ReadDelta(Stream stream, bool keepDirtyDelta)
9292
{
9393
using (var reader = PooledNetworkReader.Get(stream))
9494
{
@@ -236,7 +236,7 @@ public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, usho
236236
}
237237

238238
/// <inheritdoc />
239-
public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
239+
public void ReadField(Stream stream)
240240
{
241241
using (var reader = PooledNetworkReader.Get(stream))
242242
{

com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void WriteField(Stream stream)
223223
}
224224

225225
/// <inheritdoc />
226-
public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
226+
public void ReadField(Stream stream)
227227
{
228228
using (var reader = PooledNetworkReader.Get(stream))
229229
{
@@ -237,7 +237,7 @@ public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
237237
}
238238

239239
/// <inheritdoc />
240-
public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
240+
public void ReadDelta(Stream stream, bool keepDirtyDelta)
241241
{
242242
using (var reader = PooledNetworkReader.Get(stream))
243243
{

com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void WriteField(Stream stream)
209209
}
210210

211211
/// <inheritdoc />
212-
public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
212+
public void ReadField(Stream stream)
213213
{
214214
using (var reader = PooledNetworkReader.Get(stream))
215215
{
@@ -224,7 +224,7 @@ public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
224224
}
225225

226226
/// <inheritdoc />
227-
public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
227+
public void ReadDelta(Stream stream, bool keepDirtyDelta)
228228
{
229229
using (var reader = PooledNetworkReader.Get(stream))
230230
{

com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public interface INetworkVariable
5757
/// <param name="stream">The stream to read the state from</param>
5858
/// <param name="localTick">The local network tick at which this var was written, on the machine it was written </param>
5959
/// <param name="remoteTick">The remote network tick at which this var was sent by the host </param>
60-
void ReadField(Stream stream, ushort localTick, ushort remoteTick);
60+
void ReadField(Stream stream);
6161

6262
/// <summary>
6363
/// Reads delta from the reader and applies them to the internal value
@@ -66,17 +66,13 @@ public interface INetworkVariable
6666
/// <param name="keepDirtyDelta">Whether or not the delta should be kept as dirty or consumed</param>
6767
/// <param name="localTick">The local network tick at which this var was written, on the machine it was written </param>
6868
/// <param name="remoteTick">The remote network tick at which this var was sent by the host </param>
69-
void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick);
69+
void ReadDelta(Stream stream, bool keepDirtyDelta);
7070

7171
/// <summary>
7272
/// Sets NetworkBehaviour the container belongs to.
7373
/// </summary>
7474
/// <param name="behaviour">The behaviour the container behaves to</param>
7575
void SetNetworkBehaviour(NetworkBehaviour behaviour);
7676

77-
/// <summary>
78-
/// Accessor for the RemoteTick stored in the networkVariable, list, set or dictionary
79-
/// </summary>
80-
ushort RemoteTick { get; }
8177
}
8278
}

com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ public class NetworkVariable<T> : INetworkVariable
1818
/// </summary>
1919
public readonly NetworkVariableSettings Settings = new NetworkVariableSettings();
2020

21-
/// <summary>
22-
/// The last time the variable was written to locally
23-
/// </summary>
24-
public ushort LocalTick { get; internal set; }
25-
/// <summary>
26-
/// The last time the variable was written to remotely. Uses the remote timescale
27-
/// </summary>
28-
public ushort RemoteTick { get; internal set; }
2921
/// <summary>
3022
/// Delegate type for value changed event
3123
/// </summary>
@@ -89,10 +81,6 @@ public T Value
8981
return;
9082
}
9183

92-
// Setter is assumed to be called locally, by game code.
93-
// When used by the host, it is its responsibility to set the RemoteTick
94-
RemoteTick = NetworkTickSystem.NoTick;
95-
9684
m_IsDirty = true;
9785
T previousValue = m_InternalValue;
9886
m_InternalValue = value;
@@ -185,13 +173,8 @@ public bool CanClientWrite(ulong clientId)
185173
/// </summary>
186174
/// <param name="stream">The stream to read the value from</param>
187175
/// <param name="keepDirtyDelta">Whether or not the container should keep the dirty delta, or mark the delta as consumed</param>
188-
public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
176+
public void ReadDelta(Stream stream, bool keepDirtyDelta)
189177
{
190-
// todo: This allows the host-returned value to be set back to an old value
191-
// this will need to be adjusted to check if we're have a most recent value
192-
LocalTick = localTick;
193-
RemoteTick = remoteTick;
194-
195178
using (var reader = PooledNetworkReader.Get(stream))
196179
{
197180
T previousValue = m_InternalValue;
@@ -213,17 +196,15 @@ public void SetNetworkBehaviour(NetworkBehaviour behaviour)
213196
}
214197

215198
/// <inheritdoc />
216-
public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
199+
public void ReadField(Stream stream)
217200
{
218-
ReadDelta(stream, false, localTick, remoteTick);
201+
ReadDelta(stream, false);
219202
}
220203

221204
/// <inheritdoc />
222205
public void WriteField(Stream stream)
223206
{
224-
// Store the local tick at which this NetworkVariable was modified
225-
LocalTick = NetworkBehaviour.CurrentTick;
226-
using (var writer = PooledNetworkWriter.Get(stream))
207+
using (var writer = PooledNetworkWriter.Get(stream))
227208
{
228209
writer.WriteObjectPacked(m_InternalValue); //BOX
229210
}

testproject/Assets/Tests/Manual/Scripts/ManualNetworkVariableTest.cs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,41 @@ private void ValueChanged(int before, int after)
106106
{
107107
// compute the delta in tick between client and server,
108108
// as seen from the client, when it receives a value not from itself
109-
if (m_TestVar.LocalTick != NetworkTickSystem.NoTick)
110-
{
111-
int delta = m_TestVar.LocalTick - m_TestVar.RemoteTick;
112-
m_Count++;
113-
114-
if (!m_Valid)
115-
{
116-
m_Valid = true;
117-
m_MinDelta = delta;
118-
m_MaxDelta = delta;
119-
m_LastRemoteTick = m_TestVar.RemoteTick;
120-
}
121-
else
122-
{
123-
m_MinDelta = Math.Min(delta, m_MinDelta);
124-
m_MaxDelta = Math.Max(delta, m_MaxDelta);
125-
126-
// tick should not go backward until wrap around (which should be a long time)
127-
if (m_TestVar.RemoteTick == m_LastRemoteTick)
128-
{
129-
m_Problems += "Same remote tick receive twice\n";
130-
}
131-
else if (m_TestVar.RemoteTick < m_LastRemoteTick)
132-
{
133-
m_Problems += "Ticks went backward\n";
134-
}
135-
}
136-
}
109+
110+
// MSW: This test relies on the LocalTick variable which was otherwise dormant
111+
// and remove from MLAPI.
112+
//
113+
// I'm assuming This test will be superseded by the snapshot variable sync
114+
//
115+
116+
// if (m_TestVar.LocalTick != NetworkTickSystem.NoTick)
117+
// {
118+
// int delta = m_TestVar.LocalTick - m_TestVar.RemoteTick;
119+
// m_Count++;
120+
//
121+
// if (!m_Valid)
122+
// {
123+
// m_Valid = true;
124+
// m_MinDelta = delta;
125+
// m_MaxDelta = delta;
126+
// m_LastRemoteTick = m_TestVar.RemoteTick;
127+
// }
128+
// else
129+
// {
130+
// m_MinDelta = Math.Min(delta, m_MinDelta);
131+
// m_MaxDelta = Math.Max(delta, m_MaxDelta);
132+
//
133+
// // tick should not go backward until wrap around (which should be a long time)
134+
// if (m_TestVar.RemoteTick == m_LastRemoteTick)
135+
// {
136+
// m_Problems += "Same remote tick receive twice\n";
137+
// }
138+
// else if (m_TestVar.RemoteTick < m_LastRemoteTick)
139+
// {
140+
// m_Problems += "Ticks went backward\n";
141+
// }
142+
// }
143+
// }
137144
}
138145

139146
if (m_Count == k_EndIterations)

0 commit comments

Comments
 (0)