#pragma warning disable RefCounter001,RefCounter002 // possible reference counter error
        public GameEntityPlayBackCompareAgent Init(IEntityMapDiffHandler handler, IInterpolationInfo interpolationInfo,
                                                   EntityMap localEntityMap)
        {
            base.Init(handler);
            this.interpolationInfo = interpolationInfo;
            this.localEntityMap    = localEntityMap;
            return(this);
        }
        public static void Diff(
            EntityMap left,
            EntityMap right,
            IEntityMapDiffHandler handler,
            string staticsticId,
            IGameEntityCompareAgent gameEntityComparator, bool skipMissHandle = false)
        {
            if (gameEntityComparator == null)
            {
                gameEntityComparator = new GameEntityDefaultCompareAgent(handler);
            }

            EntityMapComparaeStatisticOne oneStat = Diff(left, right, handler, gameEntityComparator, skipMissHandle);

            RecordStatistics(staticsticId, oneStat);
        }
        public static int CompareEnumeratableGameComponents(IDictionary <int, IGameComponent> left,
                                                            IDictionary <int, IGameComponent> right, IEntityMapDiffHandler handler,
                                                            EntityDiffData diffCacheData)
        {
            var count = 0;

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

                IGameComponent rv;
                if (right.TryGetValue(k, out rv))
                {
                    if (!handler.IsExcludeComponent(rv))
                    {
                        handler.OnDiffComponent(diffCacheData.LeftEntity, lv, diffCacheData.RightEntity, rv);
                    }
                }
                else
                {
                    if (!handler.IsExcludeComponent(lv))
                    {
                        handler.OnRightComponentMissing(diffCacheData.LeftEntity, diffCacheData.RightEntity, lv);
                    }
                }
            }

            foreach (var kv in right)
            {
                count++;

                var k = kv.Key;
                if (!left.ContainsKey(k))
                {
                    var rv = kv.Value;
                    if (!handler.IsExcludeComponent(rv))
                    {
                        handler.OnLeftComponentMissing(diffCacheData.LeftEntity, diffCacheData.RightEntity, rv);
                    }
                }
            }

            return(count);
        }
        public static int CompareEnumeratableGameComponents(List <IGameComponent> left, List <IGameComponent> right,
                                                            IEntityMapDiffHandler diffHandler, EntityDiffData diffCacheData)
        {
            int  loopCount        = 0;
            var  leftEnumerator   = 0;
            var  rightEnumberator = 0;
            int  leftCount        = left.Count;
            int  rightCount       = right.Count;
            bool hasLeft          = leftEnumerator < leftCount;
            bool hasRight         = rightEnumberator < rightCount;

            while (hasLeft && hasRight && !diffHandler.IsBreak())
            {
                loopCount++;
                var leftComponent  = left[leftEnumerator];
                var rightComponent = right[rightEnumberator];
                int result         = GameComponentIComparer.Instance.Compare(leftComponent, rightComponent);
                if (result == 0)
                {
                    // component wise
                    leftEnumerator++;
                    rightEnumberator++;
                    hasLeft  = leftEnumerator < leftCount;
                    hasRight = rightEnumberator < rightCount;
                    if (!diffHandler.IsExcludeComponent(leftComponent))
                    {
                        diffHandler.OnDiffComponent(diffCacheData.LeftEntity, leftComponent, diffCacheData.RightEntity,
                                                    rightComponent);
                    }
                }
                else if (result < 0)
                {
                    if (!diffHandler.IsExcludeComponent(leftComponent))
                    {
                        diffHandler.OnRightComponentMissing(diffCacheData.LeftEntity, diffCacheData.RightEntity,
                                                            leftComponent);
                    }

                    leftEnumerator++;
                    hasLeft = leftEnumerator < leftCount;
                }
                else
                {
                    if (!diffHandler.IsExcludeComponent(rightComponent))
                    {
                        diffHandler.OnLeftComponentMissing(diffCacheData.LeftEntity, diffCacheData.RightEntity,
                                                           rightComponent);
                    }

                    rightEnumberator++;
                    hasRight = rightEnumberator < rightCount;
                }
            }

            while (hasLeft && !diffHandler.IsBreak())
            {
                loopCount++;
                var leftComponent = left[leftEnumerator];
                leftEnumerator++;
                hasLeft = leftEnumerator < leftCount;
                if (!diffHandler.IsExcludeComponent(leftComponent))
                {
                    diffHandler.OnRightComponentMissing(diffCacheData.LeftEntity, diffCacheData.RightEntity,
                                                        leftComponent);
                }
            }

            while (hasRight && !diffHandler.IsBreak())
            {
                loopCount++;

                var rightComponent = right[rightEnumberator];
                rightEnumberator++;
                hasRight = rightEnumberator < rightCount;
                if (!diffHandler.IsExcludeComponent(rightComponent))
                {
                    diffHandler.OnLeftComponentMissing(diffCacheData.LeftEntity, diffCacheData.RightEntity,
                                                       rightComponent);
                }
            }

            return(loopCount);
        }
 public virtual void Init(IEntityMapDiffHandler handler)
 {
     this.handler = handler;
 }
 public GameEntityDefaultCompareAgent(IEntityMapDiffHandler handler)
 {
     base.Init(handler);
 }
 public void Init(IEntityMapDiffHandler handler, int serverTime)
 {
     base.Init(handler);
     this.serverTime = serverTime;
 }
        public static EntityMapComparaeStatisticOne Diff(EntityMap left, EntityMap right, IEntityMapDiffHandler handler, IGameEntityCompareAgent 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
            });
        }