public void SendPacket(PacketWrapper packetToSend, Connection conTarget) { //check if packet is dropped if (IsPacketDropped()) { return; } //loop through list of packets in flight to find one not in use for (int i = 0; i < m_lstDataInFlight.Count; i++) { if (m_lstDataInFlight[i].m_fTimeOfDelivery == 0) { m_lstDataInFlight[i] = new TimeStampedWrapper() { m_tWrappedData = packetToSend, m_conTarget = conTarget, m_fTimeOfDelivery = CalcuateDeliveryTime() }; return; } } //if there is not enough room already then add a new entry to the list m_lstDataInFlight.Add(new TimeStampedWrapper() { m_tWrappedData = packetToSend, m_conTarget = conTarget, m_fTimeOfDelivery = CalcuateDeliveryTime() }); }
// Update is called once per frame void Update() { //update the packet outage UpdatePacketOutages(); //loop through all the packets in flight for (int i = 0; i < m_lstDataInFlight.Count; i++) { if (m_lstDataInFlight[i].m_fTimeOfDelivery < Time.timeSinceLevelLoad && m_lstDataInFlight[i].m_tWrappedData != null) { //deliver packet m_lstDataInFlight[i].m_conTarget.ReceivePacket(m_lstDataInFlight[i].m_tWrappedData); m_lstDataInFlight[i] = new TimeStampedWrapper(); } } }