Skip to content

fix: network time arguments #1194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 17, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ internal interface IInterpolatorTime
{
double BufferedServerTime { get; }
double BufferedServerFixedTime { get; }
int TickRate { get; }
uint TickRate { get; }
}

private class InterpolatorTime : IInterpolatorTime
{
public double BufferedServerTime => NetworkManager.Singleton.ServerTime.Time;
public double BufferedServerFixedTime => NetworkManager.Singleton.ServerTime.FixedTime;
public int TickRate => NetworkManager.Singleton.ServerTime.TickRate;
public uint TickRate => NetworkManager.Singleton.ServerTime.TickRate;
}

internal IInterpolatorTime InterpolatorTimeProxy = new InterpolatorTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class NetworkConfig
/// The tickrate of network ticks. This value controls how often netcode runs user code and sends out data.
/// </summary>
[Tooltip("The tickrate. This value controls how often netcode runs user code and sends out data. The value is in 'ticks per seconds' which means a value of 50 will result in 50 ticks being executed per second or a fixed delta time of 0.02.")]
public int TickRate = 30;
public uint TickRate = 30;

/// <summary>
/// The amount of seconds to wait for handshake to complete before timing out a client
Expand Down Expand Up @@ -162,7 +162,7 @@ public string ToBase64()
using var buffer = PooledNetworkBuffer.Get();
using var writer = PooledNetworkWriter.Get(buffer);
writer.WriteUInt16Packed(config.ProtocolVersion);
writer.WriteInt32Packed(config.TickRate);
writer.WriteUInt32Packed(config.TickRate);
writer.WriteInt32Packed(config.ClientConnectionBufferTimeout);
writer.WriteBool(config.ConnectionApproval);
writer.WriteInt32Packed(config.LoadSceneTimeOut);
Expand Down Expand Up @@ -192,7 +192,7 @@ public void FromBase64(string base64)

config.ProtocolVersion = reader.ReadUInt16Packed();
ushort sceneCount = reader.ReadUInt16Packed();
config.TickRate = reader.ReadInt32Packed();
config.TickRate = reader.ReadUInt32Packed();
config.ClientConnectionBufferTimeout = reader.ReadInt32Packed();
config.ConnectionApproval = reader.ReadBool();
config.LoadSceneTimeOut = reader.ReadInt32Packed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NetworkTickSystem
/// <summary>
/// The TickRate of the tick system. This is used to decide how often a fixed network tick is run.
/// </summary>
public int TickRate { get; }
public uint TickRate { get; }

/// <summary>
/// The current local time. This is the time at which predicted or client authoritative objects move. This value is accurate when called in Update or during the <see cref="Tick"/> event but does not work correctly for FixedUpdate.
Expand All @@ -40,8 +40,13 @@ public class NetworkTickSystem
/// <param name="tickRate">The tick rate</param>
/// <param name="localTimeSec">The initial local time to start at.</param>
/// <param name="serverTimeSec">The initial server time to start at.</param>
public NetworkTickSystem(int tickRate, double localTimeSec, double serverTimeSec)
public NetworkTickSystem(uint tickRate, double localTimeSec, double serverTimeSec)
{
if (tickRate == 0)
{
throw new ArgumentException("Tickrate must be a positive value.", nameof(tickRate));
}

TickRate = tickRate;
Tick = null;
LocalTime = new NetworkTime(tickRate, localTimeSec);
Expand Down
10 changes: 5 additions & 5 deletions com.unity.netcode.gameobjects/Runtime/Timing/NetworkTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct NetworkTime
{
private double m_TimeSec;

private int m_TickRate;
private uint m_TickRate;
private double m_TickInterval;

private int m_CachedTick;
Expand Down Expand Up @@ -52,13 +52,13 @@ public struct NetworkTime
/// <summary>
/// Gets the tickrate of the system of this <see cref="NetworkTime"/>.
/// </summary>
public int TickRate => m_TickRate;
public uint TickRate => m_TickRate;

/// <summary>
/// Creates a new instance of the <see cref="NetworkTime"/> struct.
/// </summary>
/// <param name="tickRate">The tickrate.</param>
public NetworkTime(int tickRate)
public NetworkTime(uint tickRate)
{
Assert.IsTrue(tickRate > 0, "Tickrate must be a positive value.");

Expand All @@ -75,7 +75,7 @@ public NetworkTime(int tickRate)
/// <param name="tickRate">The tickrate.</param>
/// <param name="tick">The time will be created with a value where this many tick have already passed.</param>
/// <param name="tickOffset">Can be used to create a <see cref="NetworkTime"/> with a non fixed time value by adding an offset to the given tick value.</param>
public NetworkTime(int tickRate, int tick, double tickOffset = 0d)
public NetworkTime(uint tickRate, int tick, double tickOffset = 0d)
: this(tickRate)
{
Assert.IsTrue(tickOffset < 1d / tickRate);
Expand All @@ -87,7 +87,7 @@ public NetworkTime(int tickRate, int tick, double tickOffset = 0d)
/// </summary>
/// <param name="tickRate">The tickrate.</param>
/// <param name="timeSec">The time value as a float.</param>
public NetworkTime(int tickRate, double timeSec)
public NetworkTime(uint tickRate, double timeSec)
: this(tickRate)
{
this += timeSec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ private class MockInterpolatorTime : BufferedLinearInterpolator<float>.IInterpol
{
public double BufferedServerTime { get; set; }
public double BufferedServerFixedTime { get; }
public int TickRate { get; set; }
public uint TickRate { get; set; }

public MockInterpolatorTime(double serverTime, int tickRate)
public MockInterpolatorTime(double serverTime, uint tickRate)
{
BufferedServerTime = serverTime;
TickRate = tickRate;
Expand All @@ -22,7 +22,7 @@ public MockInterpolatorTime(double serverTime, int tickRate)

private const int k_MockTickRate = 1;

private NetworkTime T(float time, int tickRate = k_MockTickRate)
private NetworkTime T(float time, uint tickRate = k_MockTickRate)
{
return new NetworkTime(tickRate, timeSec: time);
}
Expand Down
Loading