Skip to content

Commit

Permalink
refactor!: converting Channel to enum
Browse files Browse the repository at this point in the history
also moving channel to Mirage asmdef

BREAKING CHANGE: Channel is not an enum instead of an int
  • Loading branch information
James-Frowen committed Mar 31, 2023
1 parent ed92bee commit 9142513
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirage/Components/LobbyReady.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void SetAllClientsNotReady()
}
}

public void SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner = true, int channelId = Channel.Reliable)
public void SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner = true, Channel channelId = Channel.Reliable)
{
if (logger.LogEnabled()) logger.Log("Server.SendToReady msgType:" + typeof(T));

Expand Down
8 changes: 8 additions & 0 deletions Assets/Mirage/Runtime/Channel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Mirage
{
public enum Channel
{
Reliable = 0,
Unreliable = 1,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/CustomAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public enum SyncHookType
[AttributeUsage(AttributeTargets.Method)]
public class ServerRpcAttribute : Attribute
{
public int channel = Channel.Reliable;
public Channel channel = Channel.Reliable;
public bool requireAuthority = true;
}

Expand Down Expand Up @@ -93,7 +93,7 @@ public enum RpcTarget
[AttributeUsage(AttributeTargets.Method)]
public class ClientRpcAttribute : Attribute
{
public int channel = Channel.Reliable;
public Channel channel = Channel.Reliable;
public RpcTarget target = RpcTarget.Observers;
public bool excludeOwner;
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/INetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Mirage
/// </summary>
public interface IMessageSender
{
void Send<T>(T message, int channelId = Channel.Reliable);
void Send(ArraySegment<byte> segment, int channelId = Channel.Reliable);
void Send<T>(T message, Channel channelId = Channel.Reliable);
void Send(ArraySegment<byte> segment, Channel channelId = Channel.Reliable);
void Send<T>(T message, INotifyCallBack notifyCallBack);
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void Disconnect()
/// <param name="message"></param>
/// <param name="channelId"></param>
/// <returns>True if message was sent.</returns>
public void Send<T>(T message, int channelId = Channel.Reliable)
public void Send<T>(T message, Channel channelId = Channel.Reliable)
{
// Coburn, 2022-12-19: Fix NetworkClient.Send triggering NullReferenceException
// This is caused by Send() being fired after the Player object is disposed or reset
Expand All @@ -297,7 +297,7 @@ public void Send<T>(T message, int channelId = Channel.Reliable)
Player.Send(message, channelId);
}

public void Send(ArraySegment<byte> segment, int channelId = Channel.Reliable)
public void Send(ArraySegment<byte> segment, Channel channelId = Channel.Reliable)
{
// For more information, see notes in Send<T> ...
if (Player == null)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ private void ResetEvents()
/// <param name="msg">The message to deliver to clients.</param>
/// <param name="includeOwner">Should the owner should receive this message too?</param>
/// <param name="channelId">The transport channel that should be used to deliver the message. Default is the Reliable channel.</param>
internal void SendToRemoteObservers<T>(T msg, bool includeOwner = true, int channelId = Channel.Reliable)
internal void SendToRemoteObservers<T>(T msg, bool includeOwner = true, Channel channelId = Channel.Reliable)
{
if (logger.LogEnabled()) logger.Log($"Server.SendToObservers: Sending message Id: {typeof(T)}");

Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/NetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public NetworkPlayer(IConnection connection)
/// <param name="msg">The message to send.</param>
/// <param name="channelId">The transport layer channel to send on.</param>
/// <returns></returns>
public void Send<T>(T message, int channelId = Channel.Reliable)
public void Send<T>(T message, Channel channelId = Channel.Reliable)
{
if (_isDisconnected) { return; }

Expand All @@ -172,7 +172,7 @@ public void Send<T>(T message, int channelId = Channel.Reliable)
/// </summary>
/// <param name="segment"></param>
/// <param name="channelId"></param>
public void Send(ArraySegment<byte> segment, int channelId = Channel.Reliable)
public void Send(ArraySegment<byte> segment, Channel channelId = Channel.Reliable)
{
if (_isDisconnected) { return; }

Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ internal void InvokeLocalConnected()
/// <typeparam name="T">Message type</typeparam>
/// <param name="msg">Message</param>
/// <param name="channelId">Transport channel to use</param>
public void SendToAll<T>(T msg, int channelId = Channel.Reliable)
public void SendToAll<T>(T msg, Channel channelId = Channel.Reliable)
{
if (logger.LogEnabled()) logger.Log("Server.SendToAll id:" + typeof(T));

Expand Down Expand Up @@ -479,7 +479,7 @@ public void SendToAll<T>(T msg, int channelId = Channel.Reliable)
/// <param name="players"></param>
/// <param name="msg"></param>
/// <param name="channelId"></param>
public static void SendToMany<T>(IEnumerable<INetworkPlayer> players, T msg, int channelId = Channel.Reliable)
public static void SendToMany<T>(IEnumerable<INetworkPlayer> players, T msg, Channel channelId = Channel.Reliable)
{
using (var writer = NetworkWriterPool.GetWriter())
{
Expand Down Expand Up @@ -507,7 +507,7 @@ public static void SendToMany<T>(IEnumerable<INetworkPlayer> players, T msg, int
/// <remarks>
/// Using list in foreach loop causes Unity's mono version to box the struct which causes allocations, <see href="https://docs.unity3d.com/2019.4/Documentation/Manual/BestPracticeUnderstandingPerformanceInUnity4-1.html">Understanding the managed heap</see>
/// </remarks>
public static void SendToMany<T>(IReadOnlyList<INetworkPlayer> players, T msg, int channelId = Channel.Reliable)
public static void SendToMany<T>(IReadOnlyList<INetworkPlayer> players, T msg, Channel channelId = Channel.Reliable)
{
using (var writer = NetworkWriterPool.GetWriter())
{
Expand Down Expand Up @@ -537,7 +537,7 @@ public static void SendToMany<T>(IReadOnlyList<INetworkPlayer> players, T msg, i
/// <param name="excluded">player to exclude, Can be null</param>
/// <param name="msg"></param>
/// <param name="channelId"></param>
public static void SendToManyExcept<T>(IEnumerable<INetworkPlayer> players, INetworkPlayer excluded, T msg, int channelId = Channel.Reliable)
public static void SendToManyExcept<T>(IEnumerable<INetworkPlayer> players, INetworkPlayer excluded, T msg, Channel channelId = Channel.Reliable)
{
using (var writer = NetworkWriterPool.GetWriter())
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/RemoteCalls/ClientRpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class ClientRpcSender
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientRpcSender));

public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, int channelId, bool excludeOwner)
public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool excludeOwner)
{
var message = CreateMessage(behaviour, index, writer);

Expand All @@ -21,7 +21,7 @@ public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter wri
behaviour.Identity.SendToRemoteObservers(message, includeOwner, channelId);
}

public static void SendTarget(NetworkBehaviour behaviour, int index, NetworkWriter writer, int channelId, INetworkPlayer player)
public static void SendTarget(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, INetworkPlayer player)
{
var message = CreateMessage(behaviour, index, writer);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/RemoteCalls/ServerRpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Mirage.RemoteCalls
/// </summary>
public static class ServerRpcSender
{
public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, int channelId, bool requireAuthority)
public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool requireAuthority)
{
Validate(behaviour, index, requireAuthority);

Expand All @@ -24,7 +24,7 @@ public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter wri
behaviour.Client.Send(message, channelId);
}

public static UniTask<T> SendWithReturn<T>(NetworkBehaviour behaviour, int index, NetworkWriter writer, int channelId, bool requireAuthority)
public static UniTask<T> SendWithReturn<T>(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool requireAuthority)
{
Validate(behaviour, index, requireAuthority);
var message = new ServerRpcWithReplyMessage
Expand Down
11 changes: 0 additions & 11 deletions Assets/Mirage/Runtime/SocketLayer/Channel.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/Serialization/NetworkPlayerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class NetworkPlayerMessageSendingTest : NetworkPlayerTestBase
[Test]
[TestCase(Channel.Reliable)]
[TestCase(Channel.Unreliable)]
public void SendCallsSendOnConnection(int channel)
public void SendCallsSendOnConnection(Channel channel)
{
var message = new byte[] { 0, 1, 2 };
player.Send(new ArraySegment<byte>(message), channel);
Expand Down

0 comments on commit 9142513

Please sign in to comment.