MultiplexTransport: syntax for readability

This commit is contained in:
vis2k 2022-12-03 18:28:19 -05:00
parent 27a22620db
commit f4d4563a43

View File

@ -23,61 +23,46 @@ public void Awake()
public override void ClientEarlyUpdate() public override void ClientEarlyUpdate()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.ClientEarlyUpdate(); transport.ClientEarlyUpdate();
} }
}
public override void ServerEarlyUpdate() public override void ServerEarlyUpdate()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.ServerEarlyUpdate(); transport.ServerEarlyUpdate();
} }
}
public override void ClientLateUpdate() public override void ClientLateUpdate()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.ClientLateUpdate(); transport.ClientLateUpdate();
} }
}
public override void ServerLateUpdate() public override void ServerLateUpdate()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.ServerLateUpdate(); transport.ServerLateUpdate();
} }
}
void OnEnable() void OnEnable()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.enabled = true; transport.enabled = true;
} }
}
void OnDisable() void OnDisable()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.enabled = false; transport.enabled = false;
} }
}
public override bool Available() public override bool Available()
{ {
// available if any of the transports is available // available if any of the transports is available
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
if (transport.Available()) if (transport.Available())
{
return true; return true;
}
}
return false; return false;
} }
@ -150,20 +135,14 @@ public override void ClientSend(ArraySegment<byte> segment, int channelId)
// transport 0 will produce connection ids [0, 3, 6, 9, ...] // transport 0 will produce connection ids [0, 3, 6, 9, ...]
// transport 1 will produce connection ids [1, 4, 7, 10, ...] // transport 1 will produce connection ids [1, 4, 7, 10, ...]
// transport 2 will produce connection ids [2, 5, 8, 11, ...] // transport 2 will produce connection ids [2, 5, 8, 11, ...]
int FromBaseId(int transportId, int connectionId) int FromBaseId(int transportId, int connectionId) =>
{ connectionId * transports.Length + transportId;
return connectionId * transports.Length + transportId;
}
int ToBaseId(int connectionId) int ToBaseId(int connectionId) =>
{ connectionId / transports.Length;
return connectionId / transports.Length;
}
int ToTransportId(int connectionId) int ToTransportId(int connectionId) =>
{ connectionId % transports.Length;
return connectionId % transports.Length;
}
void AddServerCallbacks() void AddServerCallbacks()
{ {
@ -257,10 +236,8 @@ public override void ServerStart()
public override void ServerStop() public override void ServerStop()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.ServerStop(); transport.ServerStop();
} }
}
#endregion #endregion
public override int GetMaxPacketSize(int channelId = 0) public override int GetMaxPacketSize(int channelId = 0)
@ -288,10 +265,8 @@ public override int GetMaxPacketSize(int channelId = 0)
public override void Shutdown() public override void Shutdown()
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
{
transport.Shutdown(); transport.Shutdown();
} }
}
public override string ToString() public override string ToString()
{ {