// may be on user thread private NetSenderChannelBase CreateSenderChannel(NetMessageType tp) { NetSenderChannelBase chan; lock (m_sendChannels) { NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp); int sequenceChannel = (int)tp - (int)method; int channelSlot = (int)method - 1 + sequenceChannel; if (m_sendChannels[channelSlot] != null) { // we were pre-empted by another call to this method chan = m_sendChannels[channelSlot]; } else { switch (method) { case NetDeliveryMethod.Unreliable: case NetDeliveryMethod.UnreliableSequenced: chan = new NetUnreliableSenderChannel(this, NetUtility.GetWindowSize(method), method); break; case NetDeliveryMethod.ReliableOrdered: chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method)); break; case NetDeliveryMethod.ReliableSequenced: case NetDeliveryMethod.ReliableUnordered: default: chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method)); break; } m_sendChannels[channelSlot] = chan; } } return(chan); }
private NetReceiverChannelBase CreateReceiverChannel(NetMessageType tp) { // create receiver channel NetReceiverChannelBase chan; NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp); switch (method) { case NetDeliveryMethod.Unreliable: chan = new NetUnreliableUnorderedReceiver(this); break; case NetDeliveryMethod.ReliableOrdered: chan = new NetReliableOrderedReceiver(this, NetConstants.ReliableOrderedWindowSize); break; case NetDeliveryMethod.UnreliableSequenced: chan = new NetUnreliableSequencedReceiver(this); break; case NetDeliveryMethod.ReliableUnordered: chan = new NetReliableUnorderedReceiver(this, NetConstants.ReliableOrderedWindowSize); break; case NetDeliveryMethod.ReliableSequenced: chan = new NetReliableSequencedReceiver(this, NetConstants.ReliableSequencedWindowSize); break; default: throw new NetException("Unhandled NetDeliveryMethod!"); } int channelSlot = (int)tp - 1; NetException.Assert(m_receiveChannels[channelSlot] == null); m_receiveChannels[channelSlot] = chan; return(chan); }