예제 #1
0
        public static EntityMapComparaeStatisticOne Diff(EntityMap left, EntityMap right, IEntityMapCompareHandler handler, IGameEntityComparator gameEntityComparator, bool skipMissHandle = false)
        {
            int      entityCount    = 0;
            int      componentCount = 0;
            DateTime startTime      = DateTime.Now;

            foreach (var rightEntry in right)
            {
                entityCount++;
                if (handler.IsBreak())
                {
                    break;
                }
                var         entityKey   = rightEntry.Key;
                var         rightEntity = rightEntry.Value;
                IGameEntity leftEntity;
                left.TryGetValue(entityKey, out leftEntity);

                if (leftEntity == null)
                {
                    if (!skipMissHandle)
                    {
                        handler.OnLeftEntityMissing(rightEntity);
                    }
                    continue;
                }

                componentCount += gameEntityComparator.Diff(leftEntity, rightEntity, skipMissHandle);
            }

            if (!handler.IsBreak() && !skipMissHandle)
            {
                foreach (var leftEntry in left)
                {
                    var entityKey  = leftEntry.Key;
                    var leftEntity = leftEntry.Value;

                    IGameEntity rightEntity;
                    if (!right.TryGetValue(entityKey, out rightEntity))
                    {
                        entityCount++;
                        handler.OnRightEntityMissing(leftEntity);
                    }
                }
            }

            return(new EntityMapComparaeStatisticOne
            {
                EntityCount = entityCount,
                ComponentCount = componentCount,
                CreateTime = DateTime.Now,
                Interval = (int)(startTime - startTime).TotalMilliseconds
            });
        }
#pragma warning disable RefCounter002
        public override int Diff(IGameEntity leftEntity, IGameEntity rightEntity, bool skipMissHandle)
#pragma warning restore RefCounter002
        {
            bool        needSkip = false;
            IGameEntity localEntity;

            localEntityMap.TryGetValue(leftEntity.EntityKey, out localEntity);
            if (localEntity != null) // entity存在,但是不是playback
            {
                if (localEntity.HasFlagImmutabilityComponent)
                {
                    var local = localEntity.FlagImmutabilityComponent;
                    if (local.JudgeNeedSkipPlayback(interpolationInfo.LeftServerTime, true))
                    {
                        needSkip = true;
                    }
                }
            }
            else
            {
                needSkip = true;
            }

            if (needSkip)
            {
                return(0);
            }

            {
                diffCacheData.LeftEntity  = leftEntity;
                diffCacheData.RightEntity = rightEntity;
                handler.DoDiffEntityStart(leftEntity, rightEntity);


                int count = 0;

                try
                {
                    infos[leftEntity.EntityKey.EntityType].BeginProfileOnlyEnableProfile();

                    var left  = leftEntity.PlayBackComponentDictionary;
                    var right = rightEntity.PlayBackComponentDictionary;
                    foreach (var kv in left)
                    {
                        count++;
                        var lv = kv.Value;
                        var k  = kv.Key;

                        IGameComponent rv;
                        if (right.TryGetValue(k, out rv))
                        {
                            handler.OnDiffComponent(diffCacheData.LeftEntity, lv, diffCacheData.RightEntity, rv);
                        }
                    }
                }
                finally
                {
                    infos[leftEntity.EntityKey.EntityType].EndProfileOnlyEnableProfile();
                }
                handler.DoDiffEntityFinish(leftEntity, rightEntity);
                return(count);
            }
        }
예제 #3
0
#pragma warning disable RefCounter002
        public override int Diff(IGameEntity leftEntity, IGameEntity rightEntity, bool skipMissHandle)
#pragma warning restore RefCounter002
        {
            bool        needSkip = false;
            IGameEntity localEntity;

            _localEntityMap.TryGetValue(leftEntity.EntityKey, out localEntity);
            if (localEntity != null) // entity存在,但是不是playback
            {
                if (localEntity.HasFlagImmutabilityComponent)
                {
                    var local = localEntity.FlagImmutabilityComponent;
                    if (local.JudgeNeedSkipPlayback(_interpolationInfo.LeftServerTime))
                    {
                        needSkip = true;
                    }
                }
            }
            else
            {
                needSkip = true;
            }

            if (needSkip)
            {
                return(0);
            }

            _componentComparator.LeftEntity  = leftEntity;
            _componentComparator.RightEntity = rightEntity;
            _handler.OnDiffEntityStart(leftEntity, rightEntity);
            int count = 0;

            try
            {
                _infos[leftEntity.EntityKey.EntityType].BeginProfileOnlyEnableProfile();
                var left    = leftEntity.PlayBackComponentDictionary;
                var right   = rightEntity.PlayBackComponentDictionary;
                var handler = _componentComparator;
                foreach (var kv in left)
                {
                    count++;
                    var lv = kv.Value;
                    var k  = kv.Key;

                    IGameComponent rv;
                    if (right.TryGetValue(k, out rv))
                    {
                        handler.OnItemSame(lv, rv);
                    }
                    else
                    {
                        handler.OnRightItemMissing(lv);
                    }
                }
                foreach (var kv in right)
                {
                    count++;
                    var k = kv.Key;
                    if (!left.ContainsKey(k))
                    {
                        var rv = kv.Value;
                        handler.OnLeftItemMissing(rv);
                    }
                }
            }
            finally
            {
                _infos[leftEntity.EntityKey.EntityType].EndProfileOnlyEnableProfile();
            }


            _handler.OnDiffEntityFinish(leftEntity, rightEntity);
            return(count);
        }