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

Method checkPacketSend

Engine/source/sim/netConnection.cpp:799–866  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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