-
Notifications
You must be signed in to change notification settings - Fork 447
feat: Added support for client anticipation in NetworkVariables and NetworkTransform and support for throttling functionality in NetworkVariables #2820
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
Changes from 35 commits
e8e717c
124690a
675e6c7
a81e854
c923b86
e3a694a
22722db
c50967a
24f35cd
629e4f9
be6230e
df8f202
d4944fb
109c732
c8da36c
5eca580
0a4f836
068f66e
0ca7d14
bfd34e8
f7be25f
76a3fce
a268bd2
a3e2425
2f35b0d
4683375
49ace5c
481d97e
5618d67
6eec963
2d1615b
052a334
fc60e6c
ef792ef
227a332
5a9eac6
c4d8aa7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Unity.Netcode.Components; | ||
using UnityEditor; | ||
|
||
namespace Unity.Netcode.Editor | ||
{ | ||
/// <summary> | ||
/// The <see cref="CustomEditor"/> for <see cref="AnticipatedNetworkTransform"/> | ||
/// </summary> | ||
[CustomEditor(typeof(AnticipatedNetworkTransform), true)] | ||
public class AnticipatedNetworkTransformEditor : NetworkTransformEditor | ||
{ | ||
public override bool HideInterpolateValue => true; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,15 +45,25 @@ public void NetworkUpdate(NetworkUpdateStage updateStage) | |
|
||
DeferredMessageManager.ProcessTriggers(IDeferredNetworkMessageManager.TriggerType.OnNextFrame, 0); | ||
|
||
AnticipationSystem.SetupForUpdate(); | ||
MessageManager.ProcessIncomingMessageQueue(); | ||
MessageManager.CleanupDisconnectedClients(); | ||
|
||
AnticipationSystem.ProcessReanticipation(); | ||
} | ||
break; | ||
case NetworkUpdateStage.PreUpdate: | ||
{ | ||
NetworkTimeSystem.UpdateTime(); | ||
AnticipationSystem.Update(); | ||
} | ||
break; | ||
case NetworkUpdateStage.PostScriptLateUpdate: | ||
|
||
AnticipationSystem.Sync(); | ||
AnticipationSystem.SetupForRender(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this concept but would like to know more about it for the DA stuff. |
||
break; | ||
|
||
case NetworkUpdateStage.PostLateUpdate: | ||
{ | ||
// This should be invoked just prior to the MessageManager processes its outbound queue. | ||
|
@@ -274,6 +284,25 @@ public event Action OnTransportFailure | |
remove => ConnectionManager.OnTransportFailure -= value; | ||
} | ||
|
||
public delegate void ReanticipateDelegate(double lastRoundTripTime); | ||
|
||
/// <summary> | ||
/// This callback is called after all individual OnReanticipate calls on AnticipatedNetworkVariable | ||
/// and AnticipatedNetworkTransform values have been invoked. The first parameter is a hash set of | ||
/// all the variables that have been changed on this frame (you can detect a particular variable by | ||
/// checking if the set contains it), while the second parameter is a set of all anticipated network | ||
/// transforms that have been changed. Both are passed as their base class type. | ||
/// | ||
/// The third parameter is the local time corresponding to the current authoritative server state | ||
/// (i.e., to determine the amount of time that needs to be re-simulated, you will use | ||
/// NetworkManager.LocalTime.Time - authorityTime). | ||
/// </summary> | ||
public event ReanticipateDelegate OnReanticipate | ||
{ | ||
add => AnticipationSystem.OnReanticipate += value; | ||
remove => AnticipationSystem.OnReanticipate -= value; | ||
} | ||
|
||
/// <summary> | ||
/// The callback to invoke during connection approval. Allows client code to decide whether or not to allow incoming client connection | ||
/// </summary> | ||
|
@@ -518,6 +547,8 @@ public NetworkPrefabHandler PrefabHandler | |
/// </summary> | ||
public NetworkTickSystem NetworkTickSystem { get; private set; } | ||
|
||
internal AnticipationSystem AnticipationSystem { get; private set; } | ||
|
||
/// <summary> | ||
/// Used for time mocking in tests | ||
/// </summary> | ||
|
@@ -813,6 +844,7 @@ internal void Initialize(bool server) | |
|
||
this.RegisterNetworkUpdate(NetworkUpdateStage.EarlyUpdate); | ||
this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate); | ||
this.RegisterNetworkUpdate(NetworkUpdateStage.PostScriptLateUpdate); | ||
this.RegisterNetworkUpdate(NetworkUpdateStage.PostLateUpdate); | ||
|
||
// ComponentFactory needs to set its defaults next | ||
|
@@ -845,6 +877,7 @@ internal void Initialize(bool server) | |
// The remaining systems can then be initialized | ||
NetworkTimeSystem = server ? NetworkTimeSystem.ServerTimeSystem() : new NetworkTimeSystem(1.0 / NetworkConfig.TickRate); | ||
NetworkTickSystem = NetworkTimeSystem.Initialize(this); | ||
AnticipationSystem = new AnticipationSystem(this); | ||
|
||
// Create spawn manager instance | ||
SpawnManager = new NetworkSpawnManager(this); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh... you pulled out from the NetworkObject.Update!
