コード例 #1
0
 private bool ChangeTrackerHasChangesForEntity(NetworkEntityGuid interestingEntityGuid)
 {
     try
     {
         return(ChangeTrackingCollections.RetrieveEntity(interestingEntityGuid).HasPendingChanges);
     }
     catch (Exception e)
     {
         throw new InvalidOperationException($"Attempted to load Entity: {interestingEntityGuid}'s interst collection From: {ChangeTrackingCollections.GetType().Name} but failed. No entry matched the key. Exception: {e.Message}", e);
     }
 }
コード例 #2
0
        /// <inheritdoc />
        public void Tick()
        {
            foreach (var entry in GuidToInterestCollectionMappable.EnumerateWithGuid(KnownEntities, EntityType.Player))
            {
                InterestCollection interest = entry.ComponentValue;

                //Even if we only know ourselves we should do this anyway
                //so that the client can receieve entity data changes about itself

                //TODO: We probably won't send an update about ALL entites, so this is some wasted allocations and time
                List <EntityAssociatedData <FieldValueUpdate> > updates = new List <EntityAssociatedData <FieldValueUpdate> >(interest.ContainedEntities.Count);

                foreach (var interestingEntityGuid in interest.ContainedEntities)
                {
                    //Don't build an update for entities that don't have any changes
                    if (!ChangeTrackerHasChangesForEntity(interestingEntityGuid))
                    {
                        continue;
                    }

                    //TODO: We should cache this update value so we don't need to recompute it for ALL players who are interested
                    //This is the update collection for the particular Entity with guid interestingEntityGuid
                    //We want to use the CHANGE TRACKING bitarray for updates. If this was initial discovery we'd use the SIT bitarray to send all set values.
                    FieldValueUpdate update = UpdateFactory.Create(new EntityFieldUpdateCreationContext(ChangeTrackingCollections.RetrieveEntity(interestingEntityGuid), ChangeTrackingCollections.RetrieveEntity(interestingEntityGuid).ChangeTrackingArray));

                    updates.Add(new EntityAssociatedData <FieldValueUpdate>(interestingEntityGuid, update));
                }

                //It's possible no entity had updates, so we should not send a packet update
                if (updates.Count != 0)
                {
                    SendUpdate(entry.EntityGuid, updates);
                }
            }

            foreach (var dataEntityCollection in ChangeTrackingCollections.Enumerate(KnownEntities))
            {
                dataEntityCollection.ClearTrackedChanges();
            }
        }