Assets/Deps/emotitron/Network/NST/NetworkSyncTransform.cs
/// <summary>
/// The network sim generates a lot of garbage. But it will never run in production code so not a concern.
/// </summary>
The network sim generates a lot of garbage. But it will never run in production code so not a concern.
The network sim generates a lot of garbage . But it will never run in production code so not a concern .
private static IEnumerator NetworkSim(NetworkSyncTransform nst, MsgType msgType, byte[] _data, int _Ptr, int qosChannel = Channels.DefaultUnreliable)
		{
			byte[] delayedByteArray = new byte[_data.Length];
			_data.CopyTo(delayedByteArray, 0);
			UdpKit.UdpBitStream copyBitstream = new UdpKit.UdpBitStream(delayedByteArray, _data.Length)
			{
				Ptr = _Ptr,
				Length = _data.Length
			};
			if (UnityEngine.Random.Range(0f, 1f) < NSTSettings.single.packetLossSimulation)
			{
				if (qosChannel == Channels.DefaultReliable)
				{
					nst.StartCoroutine(NetworkSim(nst, msgType, _data, _Ptr, qosChannel));
				}
				yield break;
			}
			float waittime = NSTSettings.single.latencySimulation + UnityEngine.Random.Range(0f, NSTSettings.single.jitterSimulation);
			yield return new WaitForSeconds(waittime);
			SendBuffer(nst, msgType, ref copyBitstream, qosChannel);
		}
private static IEnumerator NetworkSim ( NetworkSyncTransform nst , MsgType msgType , byte [ ] _data , int _Ptr , int qosChannel = Channels . DefaultUnreliable ) { byte [ ] delayedByteArray = new byte [ _data . Length ] ; _data . CopyTo ( delayedByteArray , 0 ) ; UdpKit . UdpBitStream copyBitstream = new UdpKit . UdpBitStream ( delayedByteArray , _data . Length ) { Ptr = _Ptr , Length = _data . Length } ; if ( UnityEngine . Random . Range ( 0f , 1f ) < NSTSettings . single . packetLossSimulation ) { if ( qosChannel == Channels . DefaultReliable ) { nst . StartCoroutine ( NetworkSim ( nst , msgType , _data , _Ptr , qosChannel ) ) ; } yield break ; } float waittime = NSTSettings . single . latencySimulation + UnityEngine . Random . Range ( 0f , NSTSettings . single . jitterSimulation ) ; yield return new WaitForSeconds ( waittime ) ; SendBuffer ( nst , msgType , ref copyBitstream , qosChannel ) ; }
The network sim generates a lot of garbage.
The network sim generates a lot of garbage .
// need to copy the bitstream's parts to make a copy. // If packetloss simulation wants packet lost, stop here (unless its teleport which is sent RUDP) // Teleport is a reliable message - so resend if it failed here for testing purposes (a very bad recration of RUDP at work)
nst
NetworkSyncTransform
msgType
MsgType
_data
byte[]
_Ptr
int
qosChannel
int