-
Notifications
You must be signed in to change notification settings - Fork 450
feat: Adding support for netsim to be able to work with Tools adapter #2184
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
Conversation
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
@@ -346,6 +346,10 @@ private struct PacketLossCache | |||
public float PacketLoss; | |||
}; | |||
|
|||
internal static event Action<UnityTransport> TransportInitialized; | |||
internal static event Action<UnityTransport> TransportDisposed; |
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.
Should a reference to the Transport be included in the disposed message? Is it still valid at that point?
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.
Yes, since we are using the Instance ID to track the adapter.
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.
Can you expand on what the value is of tracking dispose instead of shutdown? Does this need to be an event or can you use a weak reference?
To expand on Ian's concern and my other comment about internals vs public, at the point you have this being invoked the object is essentially "off limits" to other objects as far as best practices go - regardless of how this may be used right now this feels dangerous and dependent on tribal knowledge about the control flow. If all you need is the ID, why not pass that as the event parameter instead of the entire (mostly disposed) object?
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.
There's more to it. We are using the whole UnityTransport to access the Network Driver. Arguably, we could provide the Instance ID and the Network Driver only as arguments. I am not against this change. As for the Disposed, we definitely only need the Instance ID and I can change it in the same manner if you'd prefer that.
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
+ adding back missing parameters
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
@@ -346,6 +346,10 @@ private struct PacketLossCache | |||
public float PacketLoss; | |||
}; | |||
|
|||
internal static event Action<UnityTransport> TransportInitialized; | |||
internal static event Action<UnityTransport> TransportDisposed; |
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.
Can you expand on what the value is of tracking dispose instead of shutdown? Does this need to be an event or can you use a weak reference?
To expand on Ian's concern and my other comment about internals vs public, at the point you have this being invoked the object is essentially "off limits" to other objects as far as best practices go - regardless of how this may be used right now this feels dangerous and dependent on tribal knowledge about the control flow. If all you need is the ID, why not pass that as the event parameter instead of the entire (mostly disposed) object?
|
||
#if UNITY_EDITOR || DEVELOPMENT_BUILD | ||
#if UNITY_EDITOR || DEVELOPMENT_BUILD || UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED |
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.
Is UNITY_EDITOR || DEVELOPMENT_BUILD here because the NETSIM define is 2.0 only? Can't we simplify these cases in the first define?
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.
We need to maintain the existing Debug Simulator as well if the Tools are not present. But since the Network Simulator can also be included in Release builds if the user wished so, we need all three.
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
@JesseOlmer @becksebenius-unity Per our alignment, I've updated the PR to remove Debug Simulator if we are using UTP 2. I split the stuff to avoid a mixtures of weird This also updating the callback for the adapter to avoid passing the whole Unity Transport. |
I understand there's already alignment on this at a higher level than me, but we're okay introducing a breaking API change if someone happens to have UTP 2.0 installed? |
As we see it, UTP 2 is already considered a breaking change. Technically, you need to get UTP2 to have this breaking change. If you just get the latest of NGO, it's not a breaking change. If you are willing to go to UTP2, you are accepting that change. |
I'm not sure I understand what you mean by UTP 2.0 being a breaking change. With the recent changes that landed, someone installing UTP 2.0 will get something that still works without having to modify their code. All breaking API changes introduced by UTP 2.0 are handled by NGO through version defines. But with the proposed changes here, someone could install UTP 2.0 and get a non-compiling project without any indication as to what happened. I understand (and support) the rationale of not wanting to support the existing debug simulator if UTP 2.0 is installed. That's fine. Users with UTP 2.0 should install the tools package to get the new and improved network simulator. But straight out removing the API gives them absolutely no indication that this is what is expected of them. At least change the implementation to throw an exception or log an error or something so that users won't end up with a non-compiling application and no idea of how to proceed. Or at the very least add an entry to the changelog indicating how users are expected to handle this. |
An alternative to this would to be use |
I believe the issue that @JesseOlmer was pointing out though is that we still have an existing API that doesn't do anything in that situation, though the |
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
ca9696b
to
752ddd7
Compare
752ddd7
to
838485b
Compare
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
internal static event Action<int, NetworkDriver> TransportInitialized; | ||
internal static event Action<int> TransportDisposed; |
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.
Any reason we can't make these public and then remove the internalsvisibleto
? I'd love to get rid of "hidden" public apis.
com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
5b05dda
to
61e04e5
Compare
…Unity-Technologies#2184) * Adding support for netsim to be able to work with Tools adapter * Setting up Simulator Pipeline stage if NetSim is available * Deprecate DebugSimulator when using UTP2 Co-authored-by: Jesse Olmer <jesseo@unity3d.com> Co-authored-by: DenninDalke <dennindalke@gmail.com>
This adds an internal callback to tell the tools adapter that the transport is initialized and ready so we can act on it and be aware of it.
Testing and Documentation