示例#1
0
        /**
         * Reads the next token from the stream and returns it.
         *
         * @param	BinaryStream	Stream used to serialize from
         * @param	InNetworkStream	Network stream this token belongs to
         * @return	Token serialized
         */
        public static TokenBase ReadNextToken(BinaryReader BinaryStream, NetworkStream InNetworkStream)
        {
            TokenBase SerializedToken = null;

            ETokenTypes TokenType = (ETokenTypes)BinaryStream.ReadByte();

            // Handle token specific serialization.
            switch (TokenType)
            {
            case ETokenTypes.FrameMarker:
                SerializedToken = new TokenFrameMarker(BinaryStream);
                break;

            case ETokenTypes.SocketSendTo:
                SerializedToken = new TokenSocketSendTo(BinaryStream);
                break;

            case ETokenTypes.SendBunch:
                SerializedToken = new TokenSendBunch(BinaryStream, InNetworkStream.GetVersion());
                break;

            case ETokenTypes.SendRPC:
                SerializedToken = new TokenSendRPC(BinaryStream, InNetworkStream.GetVersion());
                break;

            case ETokenTypes.ReplicateActor:
                SerializedToken = new TokenReplicateActor(BinaryStream);
                break;

            case ETokenTypes.ReplicateProperty:
                SerializedToken = new TokenReplicateProperty(BinaryStream);
                break;

            case ETokenTypes.EndOfStreamMarker:
                SerializedToken = new TokenEndOfStreamMarker();
                break;

            case ETokenTypes.Event:
                SerializedToken = new TokenEvent(BinaryStream);
                break;

            case ETokenTypes.RawSocketData:
                SerializedToken = new TokenRawSocketData(BinaryStream);
                break;

            case ETokenTypes.SendAck:
                SerializedToken = new TokenSendAck(BinaryStream);
                break;

            case ETokenTypes.WritePropertyHeader:
                SerializedToken = new TokenWritePropertyHeader(BinaryStream);
                break;

            case ETokenTypes.ExportBunch:
                SerializedToken = new TokenExportBunch(BinaryStream);
                break;

            case ETokenTypes.MustBeMappedGuids:
                SerializedToken = new TokenMustBeMappedGuids(BinaryStream);
                break;

            case ETokenTypes.BeginContentBlock:
                SerializedToken = new TokenBeginContentBlock(BinaryStream);
                break;

            case ETokenTypes.EndContentBlock:
                SerializedToken = new TokenEndContentBlock(BinaryStream);
                break;

            case ETokenTypes.WritePropertyHandle:
                SerializedToken = new TokenWritePropertyHandle(BinaryStream);
                break;

            case ETokenTypes.NameReference:
                SerializedToken = new TokenNameReference(BinaryStream);
                break;

            case ETokenTypes.ConnectionReference:
            {
                if (InNetworkStream.GetVersion() < 12)
                {
                    SerializedToken = new TokenConnectionReference(BinaryStream);
                }
                else
                {
                    SerializedToken = new TokenConnectionStringReference(BinaryStream);
                }
            }
            break;

            case ETokenTypes.ConnectionChange:
                SerializedToken = new TokenConnectionChanged(BinaryStream);
                break;

            case ETokenTypes.PropertyComparison:
                SerializedToken = new TokenPropertyComparison(BinaryStream);
                break;

            case ETokenTypes.ReplicatePropertiesMetaData:
                SerializedToken = new TokenReplicatePropertiesMetaData(BinaryStream);
                break;

            default:
                throw new InvalidDataException();
            }

            TokenTypeStats[(int)TokenType]++;
            SerializedToken.TokenType = TokenType;

            SerializedToken.ConnectionIndex = InNetworkStream.CurrentConnectionIndex;
            return(SerializedToken);
        }
示例#2
0
        private static void HandleObjectReplication(NetworkStream NetworkStream, TokenPropertyComparison ObjectComparison, TokenReplicatePropertiesMetaData ObjectReplication)
        {
            // TODO: We may be able to move this data into the Per Frame data so we can display it when selecting a range.
            //			For now, we're just going to show a summary for the entire profile.


            // If we're replicating this object, we're guaranteed that it was compared before
            // so this should be valid.
            ObjectReplicationSummary ObjectSummary = NetworkStream.ObjectNameToReplicationSummary[ObjectReplication.ObjectNameIndex];

            int FrameNum = NetworkStream.Frames.Count;

            ReadOnlyCollection <PropertyReplicationSummary> ObjectProperties = ObjectSummary.Properties;
            BitArray PropertiesCompared = ObjectComparison.ComparedProperties;
            BitArray PropertiesChanged  = ObjectComparison.ChangedProperties;
            BitArray PropertiesFiltered = ObjectReplication.FilteredProperties;

            // At this point, our object summary should be up to date so we can move on to property summaries.
            // We will do that by comparing the bitfields sent
            Debug.Assert(PropertiesChanged.Count == ObjectProperties.Count);
            Debug.Assert(PropertiesCompared.Count == ObjectProperties.Count);
            Debug.Assert(PropertiesFiltered.Count == ObjectProperties.Count);

            ObjectSummary.NumberOfReplications++;
            if (ObjectSummary.LastReplicatedFrame != FrameNum)
            {
                // If this is the first replication for an object on a given frame, we better have compared its properties.
                ObjectSummary.LastReplicatedFrame = FrameNum;
                ObjectSummary.NumberOfFramesReplicated++;
            }

            for (int i = 0; i < ObjectProperties.Count; i++)
            {
                if (PropertiesCompared[i] && PropertiesChanged[i] && !PropertiesFiltered[i])
                {
                    PropertyReplicationSummary ObjectProperty = ObjectProperties[i];

                    // The property was compared, changed, and wasn't filtered, that means it was replicated.
                    // Note, we ignore the WasNewObjectComparison here because we may legitimately replicate this
                    // property multiple times in the same frame to multiple connections and individual connections
                    // can have different filters applied to them.
                    ObjectProperty.NumberOfReplications++;
                    if (ObjectProperty.LastReplicatedFrame != FrameNum)
                    {
                        ObjectProperty.LastReplicatedFrame = FrameNum;
                        ObjectProperty.NumberOfFramesReplicated++;
                    }
                }
            }
        }