-
Notifications
You must be signed in to change notification settings - Fork 450
Client Connection Ids and Game Object registration #863
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 all commits
7673dec
b71d6ab
2752384
3df98a0
71051d0
8d30466
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,4 +1,6 @@ | ||
using Unity.Multiplayer.NetStats.Dispatch; | ||
using System.Collections.Generic; | ||
using MLAPI.Connection; | ||
using Unity.Multiplayer.NetStats.Dispatch; | ||
using Unity.Multiplayer.NetStats.Metrics; | ||
using Unity.Multiplayer.NetworkProfiler; | ||
using Unity.Multiplayer.NetworkProfiler.Models; | ||
|
@@ -7,28 +9,40 @@ namespace MLAPI.Metrics | |
{ | ||
public interface INetworkMetrics | ||
{ | ||
void TrackNamedMessageSent(string messageName, ulong bytesCount); | ||
void TrackNetworkObject(NetworkObject networkObject); | ||
|
||
void TrackNamedMessageReceived(string messageName, ulong bytesCount); | ||
void TrackNamedMessageSent(ulong receiver, string messageName, ulong bytesCount); | ||
|
||
void TrackNamedMessageSent(IReadOnlyCollection<ulong> receivers, string messageName, ulong bytesCount); | ||
|
||
void TrackNamedMessageReceived(ulong sender, string messageName, ulong bytesCount); | ||
|
||
void DispatchFrame(); | ||
} | ||
|
||
public class NullNetworkMetrics : INetworkMetrics | ||
{ | ||
public void TrackNamedMessageSent(string messageName, ulong bytesCount) | ||
public void TrackNetworkObject(NetworkObject networkObject) | ||
{ | ||
} | ||
|
||
public void TrackNamedMessageSent(ulong receiver, string messageName, ulong bytesCount) | ||
{ | ||
} | ||
|
||
public void TrackNamedMessageReceived(string messageName, ulong bytesCount) | ||
public void TrackNamedMessageSent(IReadOnlyCollection<ulong> receivers, string messageName, ulong bytesCount) | ||
{ | ||
} | ||
|
||
public void TrackNamedMessageReceived(ulong sender, string messageName, ulong bytesCount) | ||
{ | ||
} | ||
|
||
public void DispatchFrame() | ||
{ | ||
} | ||
} | ||
|
||
#if true | ||
public class NetworkMetrics : INetworkMetrics | ||
{ | ||
|
@@ -38,24 +52,42 @@ public class NetworkMetrics : INetworkMetrics | |
private EventMetric<NamedMessageEvent> m_NamedMessageSentEvent = new EventMetric<NamedMessageEvent>("Named Message Sent"); | ||
private EventMetric<NamedMessageEvent> m_NamedMessageReceivedEvent = new EventMetric<NamedMessageEvent>("Named Message Received"); | ||
|
||
private Dictionary<ulong, NetworkObjectIdentifier> m_NetworkGameObjects = new Dictionary<ulong, NetworkObjectIdentifier>(); | ||
|
||
public NetworkMetrics(NetworkManager networkManager) | ||
{ | ||
m_NetworkManager = networkManager; | ||
m_Dispatcher = new MetricDispatcherBuilder() | ||
.WithMetricEvents(m_NamedMessageSentEvent, m_NamedMessageReceivedEvent) | ||
.Build(); | ||
|
||
m_Dispatcher.RegisterObserver(MLAPIObserver.Observer); | ||
} | ||
|
||
public void TrackNamedMessageSent(string messageName, ulong bytesCount) | ||
public void TrackNetworkObject(NetworkObject networkObject) | ||
{ | ||
if (!m_NetworkGameObjects.ContainsKey(networkObject.NetworkObjectId)) | ||
{ | ||
m_NetworkGameObjects[networkObject.NetworkObjectId] = new NetworkObjectIdentifier(networkObject.name, networkObject.NetworkObjectId); | ||
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'm not sure if Although 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. This sort of thing add complexity, and we can only guess at the benefits. I'm a fan of keeping this stuff as simple as possible, and then optimizing when we have cold hard data to back it up. If we have to optimize part of this, the solution might turn out to be something else entirely. Make it work, make it clean, make it fast. In that order. 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 I was under that impression that caching would be beneficial if we're going to be reusing the structures a lot. 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 think the cost isn't worth the incidental complexity it adds to the code. |
||
} | ||
} | ||
|
||
public void TrackNamedMessageSent(ulong receiver, string messageName, ulong bytesCount) | ||
{ | ||
m_NamedMessageSentEvent.Mark(new NamedMessageEvent(new ConnectionInfo(receiver), messageName, bytesCount)); | ||
} | ||
|
||
public void TrackNamedMessageSent(IReadOnlyCollection<ulong> receivers, string messageName, ulong bytesCount) | ||
{ | ||
m_NamedMessageSentEvent.Mark(new NamedMessageEvent(new ConnectionInfo(m_NetworkManager.LocalClientId), messageName, bytesCount)); | ||
foreach (var receiver in receivers) | ||
{ | ||
TrackNamedMessageSent(receiver, messageName, bytesCount); | ||
} | ||
} | ||
|
||
public void TrackNamedMessageReceived(string messageName, ulong bytesCount) | ||
public void TrackNamedMessageReceived(ulong sender, string messageName, ulong bytesCount) | ||
{ | ||
m_NamedMessageReceivedEvent.Mark(new NamedMessageEvent(new ConnectionInfo(m_NetworkManager.LocalClientId), messageName, bytesCount)); | ||
m_NamedMessageReceivedEvent.Mark(new NamedMessageEvent(new ConnectionInfo(sender), messageName, bytesCount)); | ||
} | ||
|
||
public void DispatchFrame() | ||
|
@@ -74,4 +106,4 @@ static MLAPIObserver() | |
} | ||
} | ||
#endif | ||
} | ||
} |
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.
Please leave these types of changes out since it's just whitespace, I'm guessing you modified this and then undid the changes later but no need to touch the file with 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.
It was a mistake. I'll revert that.