private static void HandleObjectComparison(NetworkStream NetworkStream, TokenPropertyComparison ObjectComparison) { // We're guaranteed that before any Replication takes place (at least in a single frame), a comparison will also take place. // So, if this is the very first comparison for a given object class, we'll also need to set up our summary. ObjectReplicationSummary ObjectSummary = null; if (!NetworkStream.ObjectNameToReplicationSummary.TryGetValue(ObjectComparison.ObjectNameIndex, out ObjectSummary)) { // If we don't have a comparison token the first time we see this object, something is broken in the stream. Debug.Assert(ObjectComparison.ExportedPropertyNames != null); ObjectSummary = new ObjectReplicationSummary(ObjectComparison.ObjectNameIndex, ObjectComparison.ExportedPropertyNames); NetworkStream.ObjectNameToReplicationSummary.Add(ObjectSummary.ObjectNameIndex, ObjectSummary); } ObjectSummary.NumberOfComparisons++; ObjectSummary.TimeSpentComparingProperties += ObjectComparison.TimeSpentComparing; ReadOnlyCollection <PropertyReplicationSummary> ObjectProperties = ObjectSummary.Properties; BitArray PropertiesCompared = ObjectComparison.ComparedProperties; BitArray PropertiesChanged = ObjectComparison.ChangedProperties; Debug.Assert(PropertiesChanged.Count == ObjectProperties.Count); Debug.Assert(PropertiesCompared.Count == ObjectProperties.Count); int FrameNum = NetworkStream.Frames.Count; for (int i = 0; i < ObjectProperties.Count; i++) { if (PropertiesCompared[i]) { PropertyReplicationSummary ObjectProperty = ObjectProperties[i]; ObjectProperty.NumberOfComparisons++; if (ObjectProperty.LastComparedFrame != FrameNum) { ObjectProperty.LastComparedFrame++; ObjectProperty.NumberOfFramesCompared++; } if (PropertiesChanged[i]) { ObjectProperty.NumberOfChanges++; if (ObjectProperty.LastChangedFrame != FrameNum) { ObjectProperty.LastChangedFrame = FrameNum; ObjectProperty.NumberOfFramesChanged++; } } } } }
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++; } } } }