Assets/Deps/emotitron/Network/NST/NetworkSyncTransform.cs
/// <summary>
/// Serialize the appropriate data the NetworkWriter.
/// </summary>
Serialize the appropriate data the NetworkWriter.
Serialize the appropriate data the NetworkWriter .
private static void WriteGenericTransMessage(NetworkSyncTransform nst, MsgType msgType, CompressedElement compPos, byte[] externalData, bool isOffTick)
		{
			UdpKit.UdpBitStream bitstream = new UdpKit.UdpBitStream(reusableByteArray, 32);
			if (nst.debugXform == DebugXform.LocalSend)
				NSTHelper.UpdateLclTransformDebug(nst, compPos, nst.lastSentCompPos);
			bitstream.WriteUInt(nst._nstIdSyncvar, NSTSettings.single.bitsForNstId);
			int packetid = isOffTick ? 0 : nst.PacketCount++;
			bitstream.WriteInt(packetid, NSTSettings.single.bitsForPacketCount);
			if (msgType.IsPosType())
			{
				compPos.WriteCompPosToBitstream(ref bitstream, nst.includeXYZ , msgType.IsPosLowerType());
				nst.lastSentPos = compPos.Decompress();
				nst.lastSentCompPos = compPos;
				if (!isOffTick && msgType.IsPosKeyType())
				{
					nst.lastSentCompPosKey = compPos;
				}
			}
			TransformElement.WriteAllElements(ref bitstream, msgType, nst.buffer, packetid, nst.positionElements);
			TransformElement.WriteAllElements(ref bitstream, msgType, nst.buffer, packetid, nst.rotationElements);
			if (msgType == MsgType.Cust_Msg)
			{
				bitstream.WriteByteArray(externalData, externalData.Length);
				if (OnCustomMsgSndEvent != null)
					OnCustomMsgSndEvent(nst.NI.clientAuthorityOwner, externalData, nst, nst.lastSentPos, nst.buffer.frames[packetid].positions, nst.buffer.frames[packetid].rotations);
			}
			int qosChannel = msgType == MsgType.SvrTPort || msgType == MsgType.Teleport ? Channels.DefaultReliable : Channels.DefaultUnreliable;
			if (NSTSettings.single.enabledNetSimulation)
			{
				nst.StartCoroutine(NetworkSim(nst, msgType, bitstream.Data, bitstream.Ptr, qosChannel));
			}
			else
			{
				SendBuffer(nst, msgType, ref bitstream, qosChannel);
			}
			if (NetworkServer.active && msgType == MsgType.Cust_Msg)
			{
				if (OnCustomMsgRcvEvent != null)
					OnCustomMsgRcvEvent(nst.NI.clientAuthorityOwner, externalData, nst, compPos.Decompress(), nst.buffer.frames[packetid].positions, nst.buffer.frames[packetid].rotations);
				if (OnCustomMsgBeginInterpolationEvent != null)
					OnCustomMsgBeginInterpolationEvent(nst.NI.clientAuthorityOwner, externalData, nst, compPos.Decompress(), nst.buffer.frames[packetid].positions, nst.buffer.frames[packetid].rotations);
				if (OnCustomMsgEndInterpolationEvent != null)
					OnCustomMsgEndInterpolationEvent(nst.NI.clientAuthorityOwner, externalData, nst, compPos.Decompress(), nst.buffer.frames[packetid].positions, nst.buffer.frames[packetid].rotations);
			}
			DebugX.Log(
				(msgType.IsPosLowerType()) ?
				(Time.time + " NST:" + nst.NstId + "<b> sent packet:" + packetid + "</b> msg: " + msgType + " <color=blue>Sending LOWER POS BITS ONLY - you want to see lots of these or else skipping upper bits isn't very effective for your map size/movement speed.</color>") :
				(msgType.IsPosKeyType()) ?
				(Time.time + " NST:" + nst.NstId + "<b> sent packet:" + packetid + "</b> msg: " + msgType + " <color=green>sending ALL POS BITS</color>") :
				(Time.time + " NST:" + nst.NstId + "<b> sent packet:" + packetid + "</b> msg: " + msgType + " <color=purple>sending ROT ONLY BITS</color>"));
		}
private static void WriteGenericTransMessage ( NetworkSyncTransform nst , MsgType msgType , CompressedElement compPos , byte [ ] externalData , bool isOffTick ) { UdpKit . UdpBitStream bitstream = new UdpKit . UdpBitStream ( reusableByteArray , 32 ) ; if ( nst . debugXform == DebugXform . LocalSend ) NSTHelper . UpdateLclTransformDebug ( nst , compPos , nst . lastSentCompPos ) ; bitstream . WriteUInt ( nst . _nstIdSyncvar , NSTSettings . single . bitsForNstId ) ; int packetid = isOffTick ? 0 : nst . PacketCount ++ ; bitstream . WriteInt ( packetid , NSTSettings . single . bitsForPacketCount ) ; if ( msgType . IsPosType ( ) ) { compPos . WriteCompPosToBitstream ( ref bitstream , nst . includeXYZ , msgType . IsPosLowerType ( ) ) ; nst . lastSentPos = compPos . Decompress ( ) ; nst . lastSentCompPos = compPos ; if ( ! isOffTick && msgType . IsPosKeyType ( ) ) { nst . lastSentCompPosKey = compPos ; } } TransformElement . WriteAllElements ( ref bitstream , msgType , nst . buffer , packetid , nst . positionElements ) ; TransformElement . WriteAllElements ( ref bitstream , msgType , nst . buffer , packetid , nst . rotationElements ) ; if ( msgType == MsgType . Cust_Msg ) { bitstream . WriteByteArray ( externalData , externalData . Length ) ; if ( OnCustomMsgSndEvent != null ) OnCustomMsgSndEvent ( nst . NI . clientAuthorityOwner , externalData , nst , nst . lastSentPos , nst . buffer . frames [ packetid ] . positions , nst . buffer . frames [ packetid ] . rotations ) ; } int qosChannel = msgType == MsgType . SvrTPort || msgType == MsgType . Teleport ? Channels . DefaultReliable : Channels . DefaultUnreliable ; if ( NSTSettings . single . enabledNetSimulation ) { nst . StartCoroutine ( NetworkSim ( nst , msgType , bitstream . Data , bitstream . Ptr , qosChannel ) ) ; } else { SendBuffer ( nst , msgType , ref bitstream , qosChannel ) ; } if ( NetworkServer . active && msgType == MsgType . Cust_Msg ) { if ( OnCustomMsgRcvEvent != null ) OnCustomMsgRcvEvent ( nst . NI . clientAuthorityOwner , externalData , nst , compPos . Decompress ( ) , nst . buffer . frames [ packetid ] . positions , nst . buffer . frames [ packetid ] . rotations ) ; if ( OnCustomMsgBeginInterpolationEvent != null ) OnCustomMsgBeginInterpolationEvent ( nst . NI . clientAuthorityOwner , externalData , nst , compPos . Decompress ( ) , nst . buffer . frames [ packetid ] . positions , nst . buffer . frames [ packetid ] . rotations ) ; if ( OnCustomMsgEndInterpolationEvent != null ) OnCustomMsgEndInterpolationEvent ( nst . NI . clientAuthorityOwner , externalData , nst , compPos . Decompress ( ) , nst . buffer . frames [ packetid ] . positions , nst . buffer . frames [ packetid ] . rotations ) ; } DebugX . Log ( ( msgType . IsPosLowerType ( ) ) ? ( Time . time + " " + nst . NstId + " " + packetid + " " + msgType + " " ) : ( msgType . IsPosKeyType ( ) ) ? ( Time . time + " " + nst . NstId + " " + packetid + " " + msgType + " " ) : ( Time . time + " " + nst . NstId + " " + packetid + " " + msgType + " " ) ) ; }
Serialize the appropriate data the NetworkWriter.
Serialize the appropriate data the NetworkWriter .
// Update the debug transform if it is being used // Get new packetID and write to bitstream // Send position key or lowerbits // If this is a key, log it // Write the transform elements to the buffer // If this is flagged as a weapon fire, then pass along the extra byte[] array for weapon fire // Notify the server/client generating this message that the custom event is now being sent. // If network sim, send a big GC bloated version to the newtwork sim coroutine // Fire the receive events now if this is a host. They will never be received.
nst
NetworkSyncTransform
msgType
MsgType
compPos
CompressedElement
externalData
byte[]
isOffTick
bool