-
Notifications
You must be signed in to change notification settings - Fork 461
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
Changes from 3 commits
7c1ebbc
92de75a
49a0ceb
95ba089
d748605
23a0f5b
1461103
55a131c
87144f0
3093b22
838485b
3abb7b0
9263fd1
afbcdcc
5063a87
61e04e5
af4f757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| // NetSim Implementation compilation boilerplate | ||
| // All references to UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED should be defined in the same way, | ||
| // as any discrepancies are likely to result in build failures | ||
| // --------------------------------------------------------------------------------------------------------------------- | ||
|
Rosme marked this conversation as resolved.
Outdated
|
||
| #if UNITY_EDITOR || ((DEVELOPMENT_BUILD && !UNITY_MP_TOOLS_NETSIM_DISABLED_IN_DEVELOP) || (!DEVELOPMENT_BUILD && UNITY_MP_TOOLS_NETSIM_ENABLED_IN_RELEASE)) | ||
|
Rosme marked this conversation as resolved.
Outdated
|
||
| #define UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
| #endif | ||
| // --------------------------------------------------------------------------------------------------------------------- | ||
|
Rosme marked this conversation as resolved.
Outdated
|
||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
@@ -346,6 +355,10 @@ private struct PacketLossCache | |
| public float PacketLoss; | ||
| }; | ||
|
|
||
| internal static event Action<UnityTransport> TransportInitialized; | ||
| internal static event Action<UnityTransport> TransportDisposed; | ||
|
Contributor
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. Should a reference to the Transport be included in the disposed message? Is it still valid at that point?
Author
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. Yes, since we are using the Instance ID to track the adapter.
Contributor
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. 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?
Author
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. 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. |
||
| internal NetworkDriver NetworkDriver => m_Driver; | ||
|
|
||
| private PacketLossCache m_PacketLossCache = new PacketLossCache(); | ||
|
|
||
| private State m_State = State.Disconnected; | ||
|
|
@@ -389,6 +402,8 @@ private void InitDriver() | |
| out m_UnreliableFragmentedPipeline, | ||
| out m_UnreliableSequencedFragmentedPipeline, | ||
| out m_ReliableSequencedPipeline); | ||
|
|
||
| TransportInitialized?.Invoke(this); | ||
| } | ||
|
|
||
| private void DisposeInternals() | ||
|
|
@@ -406,6 +421,8 @@ private void DisposeInternals() | |
| } | ||
|
|
||
| m_SendQueue.Clear(); | ||
|
|
||
| TransportDisposed?.Invoke(this); | ||
| } | ||
|
|
||
| private NetworkPipeline SelectSendPipeline(NetworkDelivery delivery) | ||
|
|
@@ -1330,6 +1347,10 @@ private void ConfigureSimulator() | |
| , mode: ApplyMode.AllPackets | ||
| #endif | ||
| ); | ||
|
|
||
| #if UTP_TRANSPORT_2_0_ABOVE | ||
|
becksebenius-unity marked this conversation as resolved.
Outdated
|
||
| m_NetworkSettings.WithNetworkSimulatorParameters(); | ||
| #endif | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -1348,12 +1369,12 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver, | |
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| #if !UTP_TRANSPORT_2_0_ABOVE | ||
| NetworkPipelineStageCollection.RegisterPipelineStage(new NetworkMetricsPipelineStage()); | ||
| #endif | ||
| #endif | ||
| #endif //!UTP_TRANSPORT_2_0_ABOVE | ||
|
DenninDalke marked this conversation as resolved.
Outdated
|
||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
|
|
||
| #if UNITY_EDITOR || DEVELOPMENT_BUILD | ||
| #if UNITY_EDITOR || DEVELOPMENT_BUILD || UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
|
Contributor
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. Is UNITY_EDITOR || DEVELOPMENT_BUILD here because the NETSIM define is 2.0 only? Can't we simplify these cases in the first define?
Author
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. 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. |
||
| ConfigureSimulator(); | ||
| #endif | ||
| #endif //UNITY_EDITOR || DEVELOPMENT_BUILD || UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
|
|
||
| m_NetworkSettings.WithNetworkConfigParameters( | ||
| maxConnectAttempts: transport.m_MaxConnectAttempts, | ||
|
|
@@ -1362,76 +1383,81 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver, | |
| #if UTP_TRANSPORT_2_0_ABOVE | ||
| sendQueueCapacity: m_MaxPacketQueueSize, | ||
| receiveQueueCapacity: m_MaxPacketQueueSize, | ||
| #endif | ||
| #endif //UTP_TRANSPORT_2_0_ABOVE | ||
| heartbeatTimeoutMS: transport.m_HeartbeatTimeoutMS); | ||
|
|
||
| driver = NetworkDriver.Create(m_NetworkSettings); | ||
|
|
||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| #if UTP_TRANSPORT_2_0_ABOVE | ||
| driver.RegisterPipelineStage<NetworkMetricsPipelineStage>(new NetworkMetricsPipelineStage()); | ||
| #endif | ||
| #endif | ||
| #endif //UTP_TRANSPORT_2_0_ABOVE | ||
|
DenninDalke marked this conversation as resolved.
Outdated
|
||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
|
|
||
| #if UNITY_EDITOR || DEVELOPMENT_BUILD | ||
| #if !UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
|
DenninDalke marked this conversation as resolved.
Outdated
|
||
| if (DebugSimulator.PacketDelayMS > 0 || DebugSimulator.PacketDropRate > 0) | ||
| #endif //!UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
| { | ||
| unreliableFragmentedPipeline = driver.CreatePipeline( | ||
| typeof(FragmentationPipelineStage), | ||
| typeof(SimulatorPipelineStage) | ||
| #if !UTP_TRANSPORT_2_0_ABOVE | ||
| , typeof(SimulatorPipelineStageInSend) | ||
| #endif | ||
| #endif //!UTP_TRANSPORT_2_0_ABOVE | ||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| , typeof(NetworkMetricsPipelineStage) | ||
| #endif | ||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| ); | ||
| unreliableSequencedFragmentedPipeline = driver.CreatePipeline( | ||
| typeof(FragmentationPipelineStage), | ||
| typeof(UnreliableSequencedPipelineStage), | ||
| typeof(SimulatorPipelineStage) | ||
| #if !UTP_TRANSPORT_2_0_ABOVE | ||
| , typeof(SimulatorPipelineStageInSend) | ||
| #endif | ||
| #endif //!UTP_TRANSPORT_2_0_ABOVE | ||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| , typeof(NetworkMetricsPipelineStage) | ||
| #endif | ||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| ); | ||
| reliableSequencedPipeline = driver.CreatePipeline( | ||
| typeof(ReliableSequencedPipelineStage), | ||
| typeof(SimulatorPipelineStage) | ||
| #if !UTP_TRANSPORT_2_0_ABOVE | ||
| , typeof(SimulatorPipelineStageInSend) | ||
| #endif | ||
| #endif //!UTP_TRANSPORT_2_0_ABOVE | ||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| , typeof(NetworkMetricsPipelineStage) | ||
| #endif | ||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| ); | ||
| } | ||
| #if !UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
| else | ||
| #endif | ||
| { | ||
| unreliableFragmentedPipeline = driver.CreatePipeline( | ||
| typeof(FragmentationPipelineStage) | ||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| , typeof(NetworkMetricsPipelineStage) | ||
| #endif | ||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| ); | ||
| unreliableSequencedFragmentedPipeline = driver.CreatePipeline( | ||
| typeof(FragmentationPipelineStage), | ||
| typeof(UnreliableSequencedPipelineStage) | ||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| , typeof(NetworkMetricsPipelineStage) | ||
| #endif | ||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| ); | ||
| reliableSequencedPipeline = driver.CreatePipeline( | ||
| typeof(ReliableSequencedPipelineStage) | ||
| #if MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| , typeof(NetworkMetricsPipelineStage) | ||
| #endif | ||
| #endif //MULTIPLAYER_TOOLS_1_0_0_PRE_7 | ||
| ); | ||
| } | ||
| } | ||
| #endif //UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED | ||
| #endif //UNITY_EDITOR || DEVELOPMENT_BUILD | ||
| } | ||
|
|
||
| // -------------- Utility Types ------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.