From b2411c1513766b51886283a0883f903c47754ebb Mon Sep 17 00:00:00 2001 From: "M. Fatih MAR" Date: Wed, 4 Aug 2021 18:20:32 +0100 Subject: [PATCH] chore: rename MLAPI types to Netcode --- .../Editor/MLAPIProfilerModule.cs | 117 ------------------ .../{MLAPIProfiler.cs => NetcodeProfiler.cs} | 6 +- ...ofiler.cs.meta => NetcodeProfiler.cs.meta} | 0 .../Editor/NetcodeProfilerModule.cs | 117 ++++++++++++++++++ ....cs.meta => NetcodeProfilerModule.cs.meta} | 0 .../Runtime/Profiling/ProfilerCountersInfo.cs | 2 +- .../Transports/MultiplexTransportAdapter.cs | 4 +- .../Runtime/Transports/NetworkTransport.cs | 14 +-- .../Runtime/Transports/UNET/UNetTransport.cs | 32 ++--- .../Runtime/UTPTransport.cs | 6 +- 10 files changed, 149 insertions(+), 149 deletions(-) delete mode 100644 com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs rename com.unity.multiplayer.mlapi/Editor/{MLAPIProfiler.cs => NetcodeProfiler.cs} (99%) rename com.unity.multiplayer.mlapi/Editor/{MLAPIProfiler.cs.meta => NetcodeProfiler.cs.meta} (100%) create mode 100644 com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs rename com.unity.multiplayer.mlapi/Editor/{MLAPIProfilerModule.cs.meta => NetcodeProfilerModule.cs.meta} (100%) diff --git a/com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs b/com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs deleted file mode 100644 index 6b321366da..0000000000 --- a/com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Collections.Generic; -using Unity.Profiling; -using UnityEditor; -using UnityEngine; - -namespace Unity.Netcode.Editor -{ - [InitializeOnLoad] - internal static class MLAPIProfilerModule - { -#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER - private const string k_RpcModuleName = "MLAPI RPCs"; - private const string k_OperationModuleName = "MLAPI Operations"; - private const string k_MessageModuleName = "MLAPI Messages"; - -#pragma warning disable IDE1006 // disable naming rule violation check - /// - /// This needs to be in synced with the internal dynamic module structure to provide our own counters - /// - [Serializable] - private class MLAPIProfilerCounter - { - // Note: These fields are named this way for internal serialization - public string m_Name; - public string m_Category; - } - - /// - /// This needs to be in synced with the internal dynamic module structure to provide our own counters - /// - [Serializable] - private class MLAPIProfilerModuleData - { - // Note: These fields are named this way for internal serialization - public List m_ChartCounters = new List(); - public List m_DetailCounters = new List(); - public string m_Name; - } - - /// - /// This needs to be in synced with the internal dynamic module structure to provide our own counters - /// - [Serializable] - private class MLAPIModules - { - // Note: These fields are named this way for internal serialization - public List m_Modules; - } -#pragma warning restore IDE1006 // restore naming rule violation check - - private static List CreateRPCCounters() => new List() - { - new MLAPIProfilerCounter { m_Name = ProfilerConstants.RpcSent, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.RpcReceived, m_Category = ProfilerCategory.Network.Name }, - }; - - private static List CreateOperationsCounters() => new List() - { - new MLAPIProfilerCounter { m_Name = ProfilerConstants.Connections, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.ReceiveTickRate, m_Category = ProfilerCategory.Network.Name }, - }; - - private static List CreateMessagesCounters() => new List() - { - new MLAPIProfilerCounter { m_Name = ProfilerConstants.NamedMessageReceived, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.UnnamedMessageReceived, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.NamedMessageSent, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.UnnamedMessageSent, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.ByteSent, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.ByteReceived, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.NetworkVarUpdates, m_Category = ProfilerCategory.Network.Name }, - new MLAPIProfilerCounter { m_Name = ProfilerConstants.NetworkVarDeltas, m_Category = ProfilerCategory.Network.Name }, - }; - - private delegate List CounterListFactoryDelegate(); - - private static bool CreateMLAPIDynamicModule(ref MLAPIModules mlapiModules, string moduleName, CounterListFactoryDelegate counterListFactoryDelegate) - { - var module = mlapiModules.m_Modules.Find(x => x.m_Name == moduleName); - if (module == null) - { - var newModule = new MLAPIProfilerModuleData - { - m_Name = moduleName, - m_ChartCounters = counterListFactoryDelegate(), - m_DetailCounters = counterListFactoryDelegate(), - }; - mlapiModules.m_Modules.Add(newModule); - return true; - } - - return false; - } -#endif - - static MLAPIProfilerModule() - { -#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER - var dynamicModulesJson = EditorPrefs.GetString("ProfilerWindow.DynamicModules"); - var dynamicModules = JsonUtility.FromJson(dynamicModulesJson); - - if (dynamicModules != null) - { - bool wasCreated = CreateMLAPIDynamicModule(ref dynamicModules, k_RpcModuleName, CreateRPCCounters); - wasCreated |= CreateMLAPIDynamicModule(ref dynamicModules, k_OperationModuleName, CreateOperationsCounters); - wasCreated |= CreateMLAPIDynamicModule(ref dynamicModules, k_MessageModuleName, CreateMessagesCounters); - - if (wasCreated) - { - EditorPrefs.SetString("ProfilerWindow.DynamicModules", JsonUtility.ToJson(dynamicModules)); - } - } -#endif - } - } -} diff --git a/com.unity.multiplayer.mlapi/Editor/MLAPIProfiler.cs b/com.unity.multiplayer.mlapi/Editor/NetcodeProfiler.cs similarity index 99% rename from com.unity.multiplayer.mlapi/Editor/MLAPIProfiler.cs rename to com.unity.multiplayer.mlapi/Editor/NetcodeProfiler.cs index 0ce90849b9..5273f32b13 100644 --- a/com.unity.multiplayer.mlapi/Editor/MLAPIProfiler.cs +++ b/com.unity.multiplayer.mlapi/Editor/NetcodeProfiler.cs @@ -5,13 +5,13 @@ namespace Unity.Netcode.Editor { - public class MLAPIProfiler : EditorWindow + public class NetcodeProfiler : EditorWindow { #if !UNITY_2020_2_OR_NEWER - [MenuItem("Window/MLAPI Profiler")] + [MenuItem("Window/Netcode Profiler")] public static void ShowWindow() { - GetWindow(); + GetWindow(); } #endif diff --git a/com.unity.multiplayer.mlapi/Editor/MLAPIProfiler.cs.meta b/com.unity.multiplayer.mlapi/Editor/NetcodeProfiler.cs.meta similarity index 100% rename from com.unity.multiplayer.mlapi/Editor/MLAPIProfiler.cs.meta rename to com.unity.multiplayer.mlapi/Editor/NetcodeProfiler.cs.meta diff --git a/com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs b/com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs new file mode 100644 index 0000000000..98c35eff62 --- /dev/null +++ b/com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using Unity.Profiling; +using UnityEditor; +using UnityEngine; + +namespace Unity.Netcode.Editor +{ + [InitializeOnLoad] + internal static class NetcodeProfilerModule + { +#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER + private const string k_RpcModuleName = "MLAPI RPCs"; + private const string k_OperationModuleName = "MLAPI Operations"; + private const string k_MessageModuleName = "MLAPI Messages"; + +#pragma warning disable IDE1006 // disable naming rule violation check + /// + /// This needs to be in synced with the internal dynamic module structure to provide our own counters + /// + [Serializable] + private class NetcodeProfilerCounter + { + // Note: These fields are named this way for internal serialization + public string m_Name; + public string m_Category; + } + + /// + /// This needs to be in synced with the internal dynamic module structure to provide our own counters + /// + [Serializable] + private class NetcodeProfilerModuleData + { + // Note: These fields are named this way for internal serialization + public List m_ChartCounters = new List(); + public List m_DetailCounters = new List(); + public string m_Name; + } + + /// + /// This needs to be in synced with the internal dynamic module structure to provide our own counters + /// + [Serializable] + private class NetcodeModules + { + // Note: These fields are named this way for internal serialization + public List m_Modules; + } +#pragma warning restore IDE1006 // restore naming rule violation check + + private static List CreateRPCCounters() => new List() + { + new NetcodeProfilerCounter { m_Name = ProfilerConstants.RpcSent, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.RpcReceived, m_Category = ProfilerCategory.Network.Name }, + }; + + private static List CreateOperationsCounters() => new List() + { + new NetcodeProfilerCounter { m_Name = ProfilerConstants.Connections, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.ReceiveTickRate, m_Category = ProfilerCategory.Network.Name }, + }; + + private static List CreateMessagesCounters() => new List() + { + new NetcodeProfilerCounter { m_Name = ProfilerConstants.NamedMessageReceived, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.UnnamedMessageReceived, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.NamedMessageSent, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.UnnamedMessageSent, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.ByteSent, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.ByteReceived, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.NetworkVarUpdates, m_Category = ProfilerCategory.Network.Name }, + new NetcodeProfilerCounter { m_Name = ProfilerConstants.NetworkVarDeltas, m_Category = ProfilerCategory.Network.Name }, + }; + + private delegate List CounterListFactoryDelegate(); + + private static bool CreateNetcodeDynamicModule(ref NetcodeModules mlapiModules, string moduleName, CounterListFactoryDelegate counterListFactoryDelegate) + { + var module = mlapiModules.m_Modules.Find(x => x.m_Name == moduleName); + if (module == null) + { + var newModule = new NetcodeProfilerModuleData + { + m_Name = moduleName, + m_ChartCounters = counterListFactoryDelegate(), + m_DetailCounters = counterListFactoryDelegate(), + }; + mlapiModules.m_Modules.Add(newModule); + return true; + } + + return false; + } +#endif + + static NetcodeProfilerModule() + { +#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER + var dynamicModulesJson = EditorPrefs.GetString("ProfilerWindow.DynamicModules"); + var dynamicModules = JsonUtility.FromJson(dynamicModulesJson); + + if (dynamicModules != null) + { + bool wasCreated = CreateNetcodeDynamicModule(ref dynamicModules, k_RpcModuleName, CreateRPCCounters); + wasCreated |= CreateNetcodeDynamicModule(ref dynamicModules, k_OperationModuleName, CreateOperationsCounters); + wasCreated |= CreateNetcodeDynamicModule(ref dynamicModules, k_MessageModuleName, CreateMessagesCounters); + + if (wasCreated) + { + EditorPrefs.SetString("ProfilerWindow.DynamicModules", JsonUtility.ToJson(dynamicModules)); + } + } +#endif + } + } +} diff --git a/com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs.meta b/com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs.meta similarity index 100% rename from com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs.meta rename to com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs.meta diff --git a/com.unity.multiplayer.mlapi/Runtime/Profiling/ProfilerCountersInfo.cs b/com.unity.multiplayer.mlapi/Runtime/Profiling/ProfilerCountersInfo.cs index 4f587091cf..8cee14d250 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Profiling/ProfilerCountersInfo.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Profiling/ProfilerCountersInfo.cs @@ -60,7 +60,7 @@ internal static class ProfilerCountersInfo ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); [RuntimeInitializeOnLoadMethod] - private static void RegisterMLAPIPerformanceEvent() + private static void RegisterNetcodePerformanceEvent() { InitializeCounters(); ProfilerNotifier.OnPerformanceDataEvent += OnPerformanceTickData; diff --git a/com.unity.multiplayer.mlapi/Runtime/Transports/MultiplexTransportAdapter.cs b/com.unity.multiplayer.mlapi/Runtime/Transports/MultiplexTransportAdapter.cs index 8c22fbd42a..1cc4309776 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Transports/MultiplexTransportAdapter.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Transports/MultiplexTransportAdapter.cs @@ -101,7 +101,7 @@ public override NetworkEvent PollEvent(out ulong clientId, out NetworkChannel ne if (networkEvent != NetworkEvent.Nothing) { - clientId = GetMLAPIClientId(i, connectionId, false); + clientId = GetNetcodeClientId(i, connectionId, false); return networkEvent; } @@ -165,7 +165,7 @@ public override SocketTasks StartServer() } - public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServer) + public ulong GetNetcodeClientId(byte transportId, ulong connectionId, bool isServer) { if (isServer) { diff --git a/com.unity.multiplayer.mlapi/Runtime/Transports/NetworkTransport.cs b/com.unity.multiplayer.mlapi/Runtime/Transports/NetworkTransport.cs index 0826cdcab0..4450fe6e64 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Transports/NetworkTransport.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Transports/NetworkTransport.cs @@ -57,7 +57,7 @@ internal void ResetChannelCache() m_ChannelsCache = null; } - public TransportChannel[] MLAPI_CHANNELS + public TransportChannel[] NETCODE_CHANNELS { get { @@ -67,16 +67,16 @@ public TransportChannel[] MLAPI_CHANNELS OnChannelRegistration?.Invoke(transportChannels); - m_ChannelsCache = new TransportChannel[MLAPI_INTERNAL_CHANNELS.Length + transportChannels.Count]; + m_ChannelsCache = new TransportChannel[NETCODE_INTERNAL_CHANNELS.Length + transportChannels.Count]; - for (int i = 0; i < MLAPI_INTERNAL_CHANNELS.Length; i++) + for (int i = 0; i < NETCODE_INTERNAL_CHANNELS.Length; i++) { - m_ChannelsCache[i] = MLAPI_INTERNAL_CHANNELS[i]; + m_ChannelsCache[i] = NETCODE_INTERNAL_CHANNELS[i]; } for (int i = 0; i < transportChannels.Count; i++) { - m_ChannelsCache[i + MLAPI_INTERNAL_CHANNELS.Length] = transportChannels[i]; + m_ChannelsCache[i + NETCODE_INTERNAL_CHANNELS.Length] = transportChannels[i]; } } @@ -85,10 +85,10 @@ public TransportChannel[] MLAPI_CHANNELS } /// - /// The channels the MLAPI will use when sending internal messages. + /// The channels the Netcode will use when sending internal messages. /// #pragma warning disable IDE1006 // disable naming rule violation check - private readonly TransportChannel[] MLAPI_INTERNAL_CHANNELS = + private readonly TransportChannel[] NETCODE_INTERNAL_CHANNELS = #pragma warning restore IDE1006 // restore naming rule violation check { new TransportChannel(NetworkChannel.Internal, NetworkDelivery.ReliableSequenced), diff --git a/com.unity.multiplayer.mlapi/Runtime/Transports/UNET/UNetTransport.cs b/com.unity.multiplayer.mlapi/Runtime/Transports/UNET/UNetTransport.cs index cb3b69bb10..e7148d119d 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Transports/UNET/UNetTransport.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Transports/UNET/UNetTransport.cs @@ -42,9 +42,9 @@ public enum SendMode public List Channels = new List(); // Relay - public bool UseMLAPIRelay = false; - public string MLAPIRelayAddress = "184.72.104.138"; - public int MLAPIRelayPort = 8888; + public bool UseNetcodeRelay = false; + public string NetcodeRelayAddress = "127.0.0.1"; + public int NetcodeRelayPort = 8888; public SendMode MessageSendMode = SendMode.Immediately; @@ -59,7 +59,7 @@ public enum SendMode private int m_ServerHostId; private SocketTask m_ConnectTask; - public override ulong ServerClientId => GetMLAPIClientId(0, 0, true); + public override ulong ServerClientId => GetNetcodeClientId(0, 0, true); #if UNITY_EDITOR private void OnValidate() @@ -177,7 +177,7 @@ public override NetworkEvent PollEvent(out ulong clientId, out NetworkChannel ne { var eventType = RelayTransport.Receive(out int hostId, out int connectionId, out int channelId, m_MessageBuffer, m_MessageBuffer.Length, out int receivedSize, out byte error); - clientId = GetMLAPIClientId((byte)hostId, (ushort)connectionId, false); + clientId = GetNetcodeClientId((byte)hostId, (ushort)connectionId, false); receiveTime = Time.realtimeSinceStartup; var networkError = (NetworkError)error; @@ -303,7 +303,7 @@ public override SocketTasks StartServer() if (SupportWebsocket) { - if (!UseMLAPIRelay) + if (!UseNetcodeRelay) { int websocketHostId = UnityEngine.Networking.NetworkTransport.AddWebsocketHost(topology, ServerWebsocketListenPort); } @@ -337,7 +337,7 @@ public override ulong GetCurrentRtt(ulong clientId) { GetUNetConnectionDetails(clientId, out byte hostId, out ushort connectionId); - if (UseMLAPIRelay) + if (UseNetcodeRelay) { return 0; } @@ -365,7 +365,7 @@ public override void Init() UnityEngine.Networking.NetworkTransport.Init(); } - public ulong GetMLAPIClientId(byte hostId, ushort connectionId, bool isServer) + public ulong GetNetcodeClientId(byte hostId, ushort connectionId, bool isServer) { if (isServer) { @@ -396,12 +396,12 @@ public ConnectionConfig GetConfig() var connectionConfig = new ConnectionConfig(); // MLAPI built-in channels - for (int i = 0; i < MLAPI_CHANNELS.Length; i++) + for (int i = 0; i < NETCODE_CHANNELS.Length; i++) { - int channelId = AddMLAPIChannel(MLAPI_CHANNELS[i].Delivery, connectionConfig); + int channelId = AddNetcodeChannel(NETCODE_CHANNELS[i].Delivery, connectionConfig); - m_ChannelIdToName.Add(channelId, MLAPI_CHANNELS[i].Channel); - m_ChannelNameToId.Add(MLAPI_CHANNELS[i].Channel, channelId); + m_ChannelIdToName.Add(channelId, NETCODE_CHANNELS[i].Channel); + m_ChannelNameToId.Add(NETCODE_CHANNELS[i].Channel, channelId); } // Custom user-added channels @@ -423,7 +423,7 @@ public ConnectionConfig GetConfig() return connectionConfig; } - public int AddMLAPIChannel(NetworkDelivery type, ConnectionConfig config) + public int AddNetcodeChannel(NetworkDelivery type, ConnectionConfig config) { switch (type) { @@ -475,9 +475,9 @@ public int AddUNETChannel(QosType type, ConnectionConfig config) private void UpdateRelay() { - RelayTransport.Enabled = UseMLAPIRelay; - RelayTransport.RelayAddress = MLAPIRelayAddress; - RelayTransport.RelayPort = (ushort)MLAPIRelayPort; + RelayTransport.Enabled = UseNetcodeRelay; + RelayTransport.RelayAddress = NetcodeRelayAddress; + RelayTransport.RelayPort = (ushort)NetcodeRelayPort; } public void BeginNewTick() diff --git a/com.unity.multiplayer.transport.utp/Runtime/UTPTransport.cs b/com.unity.multiplayer.transport.utp/Runtime/UTPTransport.cs index b525b8afa3..8dbf8d91d0 100644 --- a/com.unity.multiplayer.transport.utp/Runtime/UTPTransport.cs +++ b/com.unity.multiplayer.transport.utp/Runtime/UTPTransport.cs @@ -304,7 +304,7 @@ private void Update() UnsafeUtility.MemClear(data.GetUnsafePtr(), message.Length); UnsafeUtility.MemCpy(data.GetUnsafePtr(), message.Data, message.Length); } - var clientId = GetMLAPIClientId((uint)message.Id, false); + var clientId = GetNetcodeClientId((uint)message.Id, false); switch ((NetcodeEvent)message.Type) { @@ -406,7 +406,7 @@ public override SocketTasks StartClient() return SocketTask.Working.AsTasks(); } - public int MLAPIChannelToPipeline(UTPDelivery type) + public int NetcodeChannelToPipeline(UTPDelivery type) { switch (type) { @@ -421,7 +421,7 @@ public int MLAPIChannelToPipeline(UTPDelivery type) return 0; } - public ulong GetMLAPIClientId(uint peerId, bool isServer) + public ulong GetNetcodeClientId(uint peerId, bool isServer) { if (isServer) {