Skip to content

Commit 7327084

Browse files
committed
Reworked Mirror events for some performance gain
1 parent 08a0f53 commit 7327084

24 files changed

Lines changed: 240 additions & 177 deletions

LabExtended/Events/Mirror/MirrorAddedObserverEventArgs.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ namespace LabExtended.Events.Mirror
99
/// </summary>
1010
public class MirrorAddedObserverEventArgs : MirrorIdentityEventArgs
1111
{
12+
/// <summary>
13+
/// Gets the singleton instance of the <see cref="MirrorAddedObserverEventArgs"/> class.
14+
/// </summary>
15+
internal static MirrorAddedObserverEventArgs Singleton { get; } = new();
16+
1217
/// <summary>
1318
/// Gets the player who was added. May be null if no instance was created for this connection.
1419
/// </summary>
15-
public ExPlayer? Observer { get; }
20+
public ExPlayer? Observer { get; internal set; }
1621

1722
/// <summary>
1823
/// Gets the connection of the player who was added as observer.
1924
/// </summary>
20-
public NetworkConnectionToClient Connection { get; }
21-
22-
public MirrorAddedObserverEventArgs(NetworkIdentity identity, ExPlayer? observer, NetworkConnectionToClient connection) : base(identity)
23-
{
24-
Observer = observer;
25-
Connection = connection;
26-
}
25+
public NetworkConnectionToClient Connection { get; internal set; }
2726
}
2827
}

LabExtended/Events/Mirror/MirrorAddingObserverEventArgs.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ namespace LabExtended.Events.Mirror
99
/// </summary>
1010
public class MirrorAddingObserverEventArgs : MirrorIdentityBooleanEventArgs
1111
{
12+
/// <summary>
13+
/// Gets the singleton instance of the <see cref="MirrorAddingObserverEventArgs"/> class.
14+
/// </summary>
15+
internal static MirrorAddingObserverEventArgs Singleton { get; } = new();
16+
1217
/// <summary>
1318
/// Gets the player who should be added. May be null if no instance was created for this connection.
1419
/// </summary>
15-
public ExPlayer? Observer { get; }
20+
public ExPlayer? Observer { get; internal set; }
1621

1722
/// <summary>
1823
/// Gets the connection of the player to be added as observer.
1924
/// </summary>
20-
public NetworkConnectionToClient Connection { get; }
21-
22-
public MirrorAddingObserverEventArgs(NetworkIdentity identity, ExPlayer? observer, NetworkConnectionToClient connection) : base(identity)
23-
{
24-
Observer = observer;
25-
Connection = connection;
26-
}
25+
public NetworkConnectionToClient Connection { get; internal set; }
2726
}
2827
}

LabExtended/Events/Mirror/MirrorDestroyedIdentityEventArgs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace LabExtended.Events.Mirror
88
public class MirrorDestroyedIdentityEventArgs : MirrorIdentityEventArgs
99
{
1010
/// <summary>
11-
/// Gets the destroy mode.
11+
/// Gets the singleton instance of the <see cref="MirrorDestroyedIdentityEventArgs"/> class.
1212
/// </summary>
13-
public NetworkServer.DestroyMode Mode { get; }
13+
internal static MirrorDestroyedIdentityEventArgs Singleton { get; } = new();
1414

15-
public MirrorDestroyedIdentityEventArgs(NetworkIdentity identity, NetworkServer.DestroyMode mode) : base(identity)
16-
{
17-
Mode = mode;
18-
}
15+
/// <summary>
16+
/// Gets the destroy mode.
17+
/// </summary>
18+
public NetworkServer.DestroyMode Mode { get; internal set; }
1919
}
2020
}

LabExtended/Events/Mirror/MirrorDestroyingIdentityEventArgs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace LabExtended.Events.Mirror
88
public class MirrorDestroyingIdentityEventArgs : MirrorIdentityBooleanEventArgs
99
{
1010
/// <summary>
11-
/// Gets the destroy mode.
11+
/// Gets the singleton instance of the <see cref="MirrorDestroyingIdentityEventArgs"/> class.
1212
/// </summary>
13-
public NetworkServer.DestroyMode Mode { get; }
13+
internal static MirrorDestroyingIdentityEventArgs Singleton { get; } = new();
1414

15-
public MirrorDestroyingIdentityEventArgs(NetworkIdentity identity, NetworkServer.DestroyMode mode) : base(identity)
16-
{
17-
Mode = mode;
18-
}
15+
/// <summary>
16+
/// Gets the destroy mode.
17+
/// </summary>
18+
public NetworkServer.DestroyMode Mode { get; internal set; }
1919
}
2020
}

LabExtended/Events/Mirror/MirrorIdentityBooleanEventArgs.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace LabExtended.Events.Mirror
55
/// <summary>
66
/// Base class for Mirror events with a network identity.
77
/// </summary>
8-
public abstract class MirrorIdentityBooleanEventArgs : BooleanEventArgs
8+
public class MirrorIdentityBooleanEventArgs : BooleanEventArgs
99
{
1010
/// <summary>
11-
/// Gets the targeted network identity.
11+
/// Gets the singleton instance of the <see cref="MirrorIdentityBooleanEventArgs"/> class.
1212
/// </summary>
13-
public NetworkIdentity Identity { get; }
13+
internal static MirrorIdentityBooleanEventArgs Instance { get; } = new();
1414

15-
public MirrorIdentityBooleanEventArgs(NetworkIdentity identity)
16-
{
17-
Identity = identity;
18-
}
15+
/// <summary>
16+
/// Gets the targeted network identity.
17+
/// </summary>
18+
public NetworkIdentity Identity { get; internal set; }
1919
}
2020
}

LabExtended/Events/Mirror/MirrorIdentityEventArgs.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace LabExtended.Events.Mirror
55
/// <summary>
66
/// Base class for Mirror events with a network identity.
77
/// </summary>
8-
public abstract class MirrorIdentityEventArgs : EventArgs
8+
public class MirrorIdentityEventArgs : EventArgs
99
{
1010
/// <summary>
11-
/// Gets the targeted network identity.
11+
/// Gets the singleton instance of the <see cref="MirrorIdentityEventArgs"/> class.
1212
/// </summary>
13-
public NetworkIdentity Identity { get; }
13+
internal static MirrorIdentityEventArgs Instance { get; } = new();
1414

15-
public MirrorIdentityEventArgs(NetworkIdentity identity)
16-
{
17-
Identity = identity;
18-
}
15+
/// <summary>
16+
/// Gets the targeted network identity.
17+
/// </summary>
18+
public NetworkIdentity Identity { get; internal set; }
1919
}
2020
}

LabExtended/Events/Mirror/MirrorRemovedObserverEventArgs.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ namespace LabExtended.Events.Mirror
99
/// </summary>
1010
public class MirrorRemovedObserverEventArgs : MirrorIdentityBooleanEventArgs
1111
{
12+
/// <summary>
13+
/// Gets the singleton instance of the <see cref="MirrorRemovedObserverEventArgs"/> class.
14+
/// </summary>
15+
internal static MirrorRemovedObserverEventArgs Singleton { get; } = new();
16+
1217
/// <summary>
1318
/// Gets the player who should be removed. May be null if no instance was created for this connection.
1419
/// </summary>
15-
public ExPlayer? Observer { get; }
20+
public ExPlayer? Observer { get; internal set; }
1621

1722
/// <summary>
1823
/// Gets the connection of the player to be removed as observer.
1924
/// </summary>
20-
public NetworkConnection Connection { get; }
21-
22-
public MirrorRemovedObserverEventArgs(NetworkIdentity identity, ExPlayer? observer, NetworkConnection connection) : base(identity)
23-
{
24-
Observer = observer;
25-
Connection = connection;
26-
}
25+
public NetworkConnection Connection { get; internal set; }
2726
}
2827
}

LabExtended/Events/Mirror/MirrorRemovingObserverEventArgs.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ namespace LabExtended.Events.Mirror
99
/// </summary>
1010
public class MirrorRemovingObserverEventArgs : MirrorIdentityBooleanEventArgs
1111
{
12+
/// <summary>
13+
/// Gets the singleton instance of the <see cref="MirrorRemovingObserverEventArgs"/> class.
14+
/// </summary>
15+
internal static MirrorRemovingObserverEventArgs Singleton { get; } = new();
16+
1217
/// <summary>
1318
/// Gets the player who should be removed. May be null if no instance was created for this connection.
1419
/// </summary>
15-
public ExPlayer? Observer { get; }
20+
public ExPlayer? Observer { get; internal set; }
1621

1722
/// <summary>
1823
/// Gets the connection of the player to be removed as observer.
1924
/// </summary>
20-
public NetworkConnection Connection { get; }
21-
22-
public MirrorRemovingObserverEventArgs(NetworkIdentity identity, ExPlayer? observer, NetworkConnection connection) : base(identity)
23-
{
24-
Observer = observer;
25-
Connection = connection;
26-
}
25+
public NetworkConnection Connection { get; internal set; }
2726
}
2827
}

LabExtended/Events/Mirror/MirrorSendingRpcEventArgs.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace LabExtended.Events.Mirror
99
/// </summary>
1010
public class MirrorSendingRpcEventArgs : MirrorIdentityBooleanEventArgs
1111
{
12+
/// <summary>
13+
/// Gets the singleton instance of the <see cref="MirrorSendingRpcEventArgs"/> class.
14+
/// </summary>
15+
internal static MirrorSendingRpcEventArgs Singleton { get; } = new();
16+
1217
/// <summary>
1318
/// Gets the player who will receive the RPC.
1419
/// </summary>
@@ -22,25 +27,16 @@ public class MirrorSendingRpcEventArgs : MirrorIdentityBooleanEventArgs
2227
/// <summary>
2328
/// Gets the behaviour sending the RPC.
2429
/// </summary>
25-
public NetworkBehaviour Behaviour { get; }
30+
public NetworkBehaviour Behaviour { get; internal set; }
2631

2732
/// <summary>
2833
/// Gets the hash of the RPC method name.
2934
/// </summary>
30-
public int RpcHash { get; }
35+
public int RpcHash { get; internal set; }
3136

3237
/// <summary>
3338
/// Gets the full name of the RPC method.
3439
/// </summary>
35-
public string RpcName { get; }
36-
37-
public MirrorSendingRpcEventArgs(ExPlayer player, NetworkWriter writer, NetworkBehaviour behaviour, int rpcHash, string rpcName) : base(behaviour.netIdentity)
38-
{
39-
Player = player;
40-
Writer = writer;
41-
Behaviour = behaviour;
42-
RpcHash = rpcHash;
43-
RpcName = rpcName;
44-
}
40+
public string RpcName { get; internal set; }
4541
}
4642
}

LabExtended/Events/Mirror/MirrorSentRpcEventArgs.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace LabExtended.Events.Mirror
99
/// </summary>
1010
public class MirrorSentRpcEventArgs : MirrorIdentityEventArgs
1111
{
12+
/// <summary>
13+
/// Gets the singleton instance of the <see cref="MirrorSentRpcEventArgs"/> class.
14+
/// </summary>
15+
internal static MirrorSentRpcEventArgs Singleton { get; } = new();
16+
1217
/// <summary>
1318
/// Gets the player who received the RPC.
1419
/// </summary>
@@ -22,25 +27,16 @@ public class MirrorSentRpcEventArgs : MirrorIdentityEventArgs
2227
/// <summary>
2328
/// Gets the behaviour which sent the RPC.
2429
/// </summary>
25-
public NetworkBehaviour Behaviour { get; }
30+
public NetworkBehaviour Behaviour { get; internal set; }
2631

2732
/// <summary>
2833
/// Gets the hash of the RPC method name.
2934
/// </summary>
30-
public int RpcHash { get; }
35+
public int RpcHash { get; internal set; }
3136

3237
/// <summary>
3338
/// Gets the full name of the RPC method.
3439
/// </summary>
35-
public string RpcName { get; }
36-
37-
public MirrorSentRpcEventArgs(ExPlayer player, NetworkWriter writer, NetworkBehaviour behaviour, int rpcHash, string rpcName) : base(behaviour.netIdentity)
38-
{
39-
Player = player;
40-
Writer = writer;
41-
Behaviour = behaviour;
42-
RpcHash = rpcHash;
43-
RpcName = rpcName;
44-
}
40+
public string RpcName { get; internal set; }
4541
}
4642
}

0 commit comments

Comments
 (0)