Assets/Deps/emotitron/Network/NST/NetworkSyncTransform.cs
/// <summary>Deserialize the reader into the appropriate fields, and add Frame to buffer Queue (if applicable)</summary>
Deserialize the reader into the appropriate fields, and add Frame to buffer Queue (if applicable)
Deserialize the reader into the appropriate fields and add Frame to buffer Queue ( if applicable )
private static void ReceieveGeneric(NetworkMessage msg)
		{
			MsgType msgType = (MsgType)msg.msgType;
			DebugX.Log(Time.time + " Received msg size: " + msg.reader.Length);
			UdpKit.UdpBitStream bitstream = new UdpKit.UdpBitStream(msg.reader.ReadBytesNonAlloc(reusableByteArray, msg.reader.Length), msg.reader.Length);
			uint nid;
			int packetid;
			nid = bitstream.ReadUInt(NSTSettings.single.bitsForNstId);
			packetid = bitstream.ReadInt(NSTSettings.single.bitsForPacketCount);
			NetworkSyncTransform nst =
				(NSTSettings.single.bitsForNstId >= 6) ? nst = nstIdToNSTLookup[nid] :
				nst = NstIds[nid];
			if (nst == null)
			{
				DebugX.LogWarning("NST received but no object exists with msgtype:" + msg.msgType + " index: " + packetid);
				return;
			}
			Frame frame = nst.buffer.frames[packetid];
			CompressedElement compPos =
				msgType.IsPosLowerType() ? NSTCompressVector.ReadCompressedPosFromBitstream(ref bitstream, nst.includeXYZ, true) :
				msgType.IsPosKeyType()   ? NSTCompressVector.ReadCompressedPosFromBitstream(ref bitstream, nst.includeXYZ) :
				CompressedElement.zero;
			Vector3 pos = compPos.Decompress();
			DebugX.Log(Time.time + " NST:" + nst.NstId + " " + nst.name + " <color=green><b>Received Update " + packetid + " </b></color>\n" + pos + " " + (MsgType)msg.msgType + " size:" + msg.reader.Length + "bytes");
			TransformElement.ReadAllElements(ref bitstream, msgType, nst.buffer, packetid, nst.positionElements);
			TransformElement.ReadAllElements(ref bitstream, msgType, nst.buffer, packetid, nst.rotationElements);
			if(nst.debugXform == DebugXform.RawReceive && !nst.hasAuthority)
			{
				if (nst.rootPosSync != RootPositionSync.Disabled)
				nst.debugXformGO.transform.position = 
					(msgType.IsPosLowerType()) ? 
					NSTCompressVector.GuessUpperBits(compPos, nst.buffer.BestPreviousKeyframe(packetid).compPos).Decompress() : 
					pos;
				if (BitTools.GetBitInMask(frame.rotationsMask, 0))
					nst.debugXformGO.transform.rotation = frame.rotations[0];
			}
			if (msg.msgType == (short)MsgType.SvrTPort)
			{
				nst.ClientSvrTeleportCommandHandler(pos, frame.rotations);
			}
			else if (msg.msgType == (short)MsgType.Cust_Msg)
			{
				int remainingbuffer = (bitstream.Length - bitstream.Ptr) / 8;
				bitstream.ReadByteArray(frame.customMsg, remainingbuffer);
				frame.customMsgSize = remainingbuffer;
				if (OnCustomMsgRcvEvent != null)
					OnCustomMsgRcvEvent(msg.conn, frame.customMsg, nst, pos, frame.positions, frame.rotations);
				if (OnCustomMsgBeginInterpolationEvent != null && packetid == 0)
					OnCustomMsgBeginInterpolationEvent(msg.conn, frame.customMsg, nst, pos, frame.positions, frame.rotations);
				if (OnCustomMsgEndInterpolationEvent != null && packetid == 0)
					OnCustomMsgEndInterpolationEvent(msg.conn, frame.customMsg, nst, pos, frame.positions, frame.rotations);
			}
			if (NetworkServer.active && msg.conn == nst.NI.clientAuthorityOwner)
			{
				writer.StartMessage(msg.msgType);
				writer.WriteUncountedByteArray(bitstream.Data, msg.reader.Length);
				writer.SendPayloadArrayToAllClients(msg.msgType);
			}
			if (!nst.hasAuthority)
			{
				nst.buffer.AddFrameToBuffer(msgType, compPos, packetid);
			}
		}
private static void ReceieveGeneric ( NetworkMessage msg ) { MsgType msgType = ( MsgType ) msg . msgType ; DebugX . Log ( Time . time + " " + msg . reader . Length ) ; UdpKit . UdpBitStream bitstream = new UdpKit . UdpBitStream ( msg . reader . ReadBytesNonAlloc ( reusableByteArray , msg . reader . Length ) , msg . reader . Length ) ; uint nid ; int packetid ; nid = bitstream . ReadUInt ( NSTSettings . single . bitsForNstId ) ; packetid = bitstream . ReadInt ( NSTSettings . single . bitsForPacketCount ) ; NetworkSyncTransform nst = ( NSTSettings . single . bitsForNstId >= 6 ) ? nst = nstIdToNSTLookup [ nid ] : nst = NstIds [ nid ] ; if ( nst == null ) { DebugX . LogWarning ( " " + msg . msgType + " " + packetid ) ; return ; } Frame frame = nst . buffer . frames [ packetid ] ; CompressedElement compPos = msgType . IsPosLowerType ( ) ? NSTCompressVector . ReadCompressedPosFromBitstream ( ref bitstream , nst . includeXYZ , true ) : msgType . IsPosKeyType ( ) ? NSTCompressVector . ReadCompressedPosFromBitstream ( ref bitstream , nst . includeXYZ ) : CompressedElement . zero ; Vector3 pos = compPos . Decompress ( ) ; DebugX . Log ( Time . time + " " + nst . NstId + " " + nst . name + " " + packetid + " \n " + pos + " " + ( MsgType ) msg . msgType + " " + msg . reader . Length + " " ) ; TransformElement . ReadAllElements ( ref bitstream , msgType , nst . buffer , packetid , nst . positionElements ) ; TransformElement . ReadAllElements ( ref bitstream , msgType , nst . buffer , packetid , nst . rotationElements ) ; if ( nst . debugXform == DebugXform . RawReceive && ! nst . hasAuthority ) { if ( nst . rootPosSync != RootPositionSync . Disabled ) nst . debugXformGO . transform . position = ( msgType . IsPosLowerType ( ) ) ? NSTCompressVector . GuessUpperBits ( compPos , nst . buffer . BestPreviousKeyframe ( packetid ) . compPos ) . Decompress ( ) : pos ; if ( BitTools . GetBitInMask ( frame . rotationsMask , 0 ) ) nst . debugXformGO . transform . rotation = frame . rotations [ 0 ] ; } if ( msg . msgType == ( short ) MsgType . SvrTPort ) { nst . ClientSvrTeleportCommandHandler ( pos , frame . rotations ) ; } else if ( msg . msgType == ( short ) MsgType . Cust_Msg ) { int remainingbuffer = ( bitstream . Length - bitstream . Ptr ) / 8 ; bitstream . ReadByteArray ( frame . customMsg , remainingbuffer ) ; frame . customMsgSize = remainingbuffer ; if ( OnCustomMsgRcvEvent != null ) OnCustomMsgRcvEvent ( msg . conn , frame . customMsg , nst , pos , frame . positions , frame . rotations ) ; if ( OnCustomMsgBeginInterpolationEvent != null && packetid == 0 ) OnCustomMsgBeginInterpolationEvent ( msg . conn , frame . customMsg , nst , pos , frame . positions , frame . rotations ) ; if ( OnCustomMsgEndInterpolationEvent != null && packetid == 0 ) OnCustomMsgEndInterpolationEvent ( msg . conn , frame . customMsg , nst , pos , frame . positions , frame . rotations ) ; } if ( NetworkServer . active && msg . conn == nst . NI . clientAuthorityOwner ) { writer . StartMessage ( msg . msgType ) ; writer . WriteUncountedByteArray ( bitstream . Data , msg . reader . Length ) ; writer . SendPayloadArrayToAllClients ( msg . msgType ) ; } if ( ! nst . hasAuthority ) { nst . buffer . AddFrameToBuffer ( msgType , compPos , packetid ) ; } }
Deserialize the reader into the appropriate fields, and add Frame to buffer Queue (if applicable)
Deserialize the reader into the appropriate fields and add Frame to buffer Queue ( if applicable )
// Deserialize the correct header (based on the NSTSettings for max objects // The NST is stored differently depending on the developer selected size. // Discard if this NST has gone away (removed from game) // This will only be a valid position if the was a pos key. TODO: Move this inside an if so this only happens for Teleport/CustomMessges // Read any incoming transform elements into their appropriate lists //if this a server teleport command from server to clients - TODO: MAY NOT BE NEEDED // if this is a Custom message, pass it along as an event. // Read the custom data directly into the frame buffer to skip some steps.  // send out the event that a weapon fire message has arrived // if this is an offtick custom msg, it will never be on the queue so fire the begin and end interp messages now. // Write a clone message and pass it to all the clients if this is the server // if update is required for this pass (client or headless server) Update pos - add to lastpos in the case of pos_delta
msg
NetworkMessage