MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / checkPacketSend

Method checkPacketSend

Engine/source/sim/netConnection.cpp:794–861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

792};
793
794void NetConnection::checkPacketSend(bool force)
795{
796 U32 curTime = Platform::getVirtualMilliseconds();
797 U32 delay = isConnectionToServer() ? gPacketUpdateDelayToServer : mCurRate.updateDelay;
798
799 if(!force)
800 {
801 if(curTime < mLastUpdateTime + delay - mSendDelayCredit)
802 return;
803
804 mSendDelayCredit = curTime - (mLastUpdateTime + delay - mSendDelayCredit);
805 if(mSendDelayCredit > 1000)
806 mSendDelayCredit = 1000;
807
808 if(mDemoWriteStream)
809 recordBlock(BlockTypeSendPacket, 0, 0);
810 }
811 if(windowFull())
812 return;
813
814 BitStream *stream = BitStream::getPacketStream(mCurRate.packetSize);
815 buildSendPacketHeader(stream);
816
817 mLastUpdateTime = curTime;
818
819 PacketNotify *note = allocNotify();
820 if(!mNotifyQueueHead)
821 mNotifyQueueHead = note;
822 else
823 mNotifyQueueTail->nextPacket = note;
824 mNotifyQueueTail = note;
825 note->nextPacket = NULL;
826 note->sendTime = curTime;
827
828 note->rateChanged = mCurRate.changed;
829 note->maxRateChanged = mMaxRate.changed;
830
831 if(stream->writeFlag(mCurRate.changed))
832 {
833 stream->writeInt(mCurRate.updateDelay, 12);
834 stream->writeInt(mCurRate.packetSize, 12);
835 mCurRate.changed = false;
836 }
837 if(stream->writeFlag(mMaxRate.changed))
838 {
839 stream->writeInt(mMaxRate.updateDelay, 12);
840 stream->writeInt(mMaxRate.packetSize, 12);
841 mMaxRate.changed = false;
842 }
843#ifdef TORQUE_DEBUG_NET
844 U32 start = stream->getCurPos();
845#endif
846
847 DEBUG_LOG(("PKLOG %d START", getId()) );
848 writePacket(stream, note);
849 DEBUG_LOG(("PKLOG %d END - %d", getId(), stream->getCurPos() - start) );
850 if(mSimulatedPacketLoss && Platform::getRandom() < mSimulatedPacketLoss)
851 {

Callers 2

processClientMethod · 0.80
processServerMethod · 0.80

Calls 6

sendPacketFunction · 0.85
writeIntMethod · 0.80
getCurPosMethod · 0.80
postEventFunction · 0.50
getCurrentTimeFunction · 0.50
writeFlagMethod · 0.45

Tested by

no test coverage detected