Skip to content

Commit

Permalink
feat!: updating to mirage v149.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Aug 21, 2024
1 parent 816968c commit 712d6d2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Mirage.NetworkProfiler.ModuleGUI.UITable;
using Mirage.RemoteCalls;
using Unity.Profiling;
using Unity.Profiling.Editor;
using UnityEditor;
Expand Down Expand Up @@ -243,9 +244,9 @@ private static List<MessageInfo> GenerateDebugMessages()
var order = 0;
for (var i = 0; i < 5; i++)
{
messages.Add(NewInfo(order++, new RpcMessage { netId = (uint)i }, 20 + i, 5));
messages.Add(NewInfo(order++, new SpawnMessage { netId = (uint)i }, 80 + i, 1));
messages.Add(NewInfo(order++, new SpawnMessage { netId = (uint)i }, 60 + i, 4));
messages.Add(NewInfo(order++, new RpcMessage { NetId = (uint)i }, 20 + i, 5));
messages.Add(NewInfo(order++, new SpawnMessage { NetId = (uint)i }, 80 + i, 1));
messages.Add(NewInfo(order++, new SpawnMessage { NetId = (uint)i }, 60 + i, 4));
messages.Add(NewInfo(order++, new NetworkPingMessage { }, 4, 1));

static MessageInfo NewInfo(int order, object msg, int bytes, int count)
Expand Down
5 changes: 5 additions & 0 deletions Assets/Mirage.Profiler/Editor/ServerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ServerModule : ProfilerModule
private static readonly ProfilerCounterDescriptor[] counters = new ProfilerCounterDescriptor[]
{
new ProfilerCounterDescriptor(Names.PLAYER_COUNT, Counters.Category),
new ProfilerCounterDescriptor(Names.AUTHENTICATED_COUNT, Counters.Category),
new ProfilerCounterDescriptor(Names.CHARACTER_COUNT, Counters.Category),
new ProfilerCounterDescriptor(Names.OBJECT_COUNT, Counters.Category),
};
Expand Down Expand Up @@ -50,6 +51,7 @@ protected void SetText(Label label, string name)
public sealed class ServerViewController : BaseViewController
{
private Label PlayerLabel;
private Label AuthenticatedLabel;
private Label CharacterLabel;
private Label ObjectLabel;

Expand All @@ -60,10 +62,12 @@ protected override VisualElement CreateView()
var root = new VisualElement();

PlayerLabel = AddLabelWithPadding(root);
AuthenticatedLabel = AddLabelWithPadding(root);
CharacterLabel = AddLabelWithPadding(root);
ObjectLabel = AddLabelWithPadding(root);

PlayerLabel.tooltip = Names.PLAYER_COUNT_TOOLTIP;
AuthenticatedLabel.tooltip = Names.AUTHENTICATED_COUNT_TOOLTIP;
CharacterLabel.tooltip = Names.CHARACTER_COUNT_TOOLTIP;
ObjectLabel.tooltip = Names.OBJECT_COUNT_TOOLTIP;

Expand Down Expand Up @@ -96,6 +100,7 @@ protected override void Dispose(bool disposing)
private void ReloadData()
{
SetText(PlayerLabel, Names.PLAYER_COUNT);
SetText(AuthenticatedLabel, Names.AUTHENTICATED_COUNT);
SetText(CharacterLabel, Names.CHARACTER_COUNT);
SetText(ObjectLabel, Names.OBJECT_COUNT);
}
Expand Down
5 changes: 3 additions & 2 deletions Assets/Mirage.Profiler/Runtime/Counters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ internal static class Counters
private const ProfilerMarkerDataUnit COUNT = ProfilerMarkerDataUnit.Count;
private const ProfilerMarkerDataUnit BYTES = ProfilerMarkerDataUnit.Bytes;

public static readonly ProfilerCounter<int> PlayerCount = new ProfilerCounter<int>(Category, Names.PLAYER_COUNT, COUNT);
public static readonly ProfilerCounter<int> CharCount = new ProfilerCounter<int>(Category, Names.CHARACTER_COUNT, COUNT);
public static readonly ProfilerCounter<int> AllPlayersCount = new ProfilerCounter<int>(Category, Names.PLAYER_COUNT, COUNT);
public static readonly ProfilerCounter<int> AuthenticatedPlayersCount = new ProfilerCounter<int>(Category, Names.AUTHENTICATED_COUNT, COUNT);
public static readonly ProfilerCounter<int> CharacterCount = new ProfilerCounter<int>(Category, Names.CHARACTER_COUNT, COUNT);
public static readonly ProfilerCounter<int> ObjectCount = new ProfilerCounter<int>(Category, Names.OBJECT_COUNT, COUNT);

public static readonly ProfilerCounter<int> SentCount = new ProfilerCounter<int>(Category, Names.SENT_COUNT, COUNT);
Expand Down
5 changes: 4 additions & 1 deletion Assets/Mirage.Profiler/Runtime/Names.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ namespace Mirage.NetworkProfiler
{
public static class Names
{
public const string PLAYER_COUNT = "Player Count";
public const string PLAYER_COUNT = "All Players Count";
public const string PLAYER_COUNT_TOOLTIP = "Number of players connected to the server";
public const string AUTHENTICATED_COUNT = "Authenticated Players Count";
public const string AUTHENTICATED_COUNT_TOOLTIP = "Number of Authenticated players connected to the server, This should be same as total players most of the time";
public const string CHARACTER_COUNT = "Character Count";
public const string CHARACTER_COUNT_TOOLTIP = "Number of players with spawned GameObjects";


public const string OBJECT_COUNT = "Object Count";
public const string OBJECT_COUNT_TOOLTIP = "Number of NetworkIdentities spawned on the server";

Expand Down
32 changes: 15 additions & 17 deletions Assets/Mirage.Profiler/Runtime/NetworkInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Mirage.RemoteCalls;

namespace Mirage.NetworkProfiler
{
/// <summary>
Expand All @@ -23,14 +25,13 @@ public NetworkInfoProvider(NetworkWorld world)
{
switch (info.message)
{
case ServerRpcMessage msg: return msg.netId;
case ServerRpcWithReplyMessage msg: return msg.netId;
case RpcMessage msg: return msg.netId;
case SpawnMessage msg: return msg.netId;
case RemoveAuthorityMessage msg: return msg.netId;
case ObjectDestroyMessage msg: return msg.netId;
case ObjectHideMessage msg: return msg.netId;
case UpdateVarsMessage msg: return msg.netId;
case RpcMessage msg: return msg.NetId;
case RpcWithReplyMessage msg: return msg.NetId;
case SpawnMessage msg: return msg.NetId;
case RemoveAuthorityMessage msg: return msg.NetId;
case ObjectDestroyMessage msg: return msg.NetId;
case ObjectHideMessage msg: return msg.NetId;
case UpdateVarsMessage msg: return msg.NetId;
default: return default;
}
}
Expand All @@ -52,25 +53,22 @@ public string GetRpcName(NetworkDiagnostics.MessageInfo info)
{
switch (info.message)
{
case ServerRpcMessage msg:
return GetRpcName(msg.netId, msg.componentIndex, msg.functionIndex);
case ServerRpcWithReplyMessage msg:
return GetRpcName(msg.netId, msg.componentIndex, msg.functionIndex);
case RpcMessage msg:
return GetRpcName(msg.netId, msg.componentIndex, msg.functionIndex);
return GetRpcName(msg.NetId, msg.FunctionIndex);
case RpcWithReplyMessage msg:
return GetRpcName(msg.NetId, msg.FunctionIndex);
default: return string.Empty;
}
}

private string GetRpcName(uint netId, int componentIndex, int functionIndex)
private string GetRpcName(uint netId, int functionIndex)
{
var identity = GetNetworkIdentity(netId);
if (identity == null)
return string.Empty;

var behaviour = identity.NetworkBehaviours[componentIndex];
var rpc = behaviour.RemoteCallCollection.Get(functionIndex);
return rpc.name;
var rpc = identity.RemoteCallCollection.GetAbsolute(functionIndex);
return rpc.Name;
}
}
}
7 changes: 5 additions & 2 deletions Assets/Mirage.Profiler/Runtime/NetworkProfilerRecorder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Mirage.Logging;
using UnityEngine;
using System.Linq;


#if UNITY_EDITOR
using UnityEditorInternal;
Expand Down Expand Up @@ -149,8 +151,9 @@ private void SampleCounts()
{
if (instance == (object)Server)
{
Counters.PlayerCount.Sample(Server.Players.Count);
Counters.PlayerCount.Sample(Server.NumberOfPlayers);
Counters.AllPlayersCount.Sample(Server.AllPlayers.Count);
Counters.AuthenticatedPlayersCount.Sample(Server.AuthenticatedPlayers.Count);
Counters.CharacterCount.Sample(Server.AuthenticatedPlayers.Count(x => x.Identity != null));
Counters.ObjectCount.Sample(Server.World.SpawnedIdentities.Count);
}
}
Expand Down

0 comments on commit 712d6d2

Please sign in to comment.