private bool IsHistoryDifferentFrom(EntityMap remoteEntityMap)
        {
            checkDiffHandler.SetRemoteCmdSeq(provider.LastSelfUserCmdSeqId);
            HistoryEntityMap historyEntityMap = GetTargetHistory(provider.LastSelfUserCmdSeqId);

            if (historyEntityMap != null)
            {
                EntityMapCompareExecutor.Diff(historyEntityMap.EntityMap, remoteEntityMap, checkDiffHandler, "predicteCompare", gameEntityComparator);
                if (checkDiffHandler.IsDiff)
                {
                    SingletonManager.Get <DurationHelp>().IncreaseRewindCount();
                    logger.InfoFormat("should rewind for history diff, historyId {0} {1}", provider.LastSelfUserCmdSeqId,
                                      historyEntityMap.SeqId);
                }

                return(checkDiffHandler.IsDiff);
            }

            int oldestHistory = histories.Count > 0 ? histories.First().SeqId : 0;
            int latestHistory = histories.Count > 0 ? histories.Last().SeqId : 0;

            logger.InfoFormat("should rewind for history not saved, historyId {0}, saved history = {1}-{2}",
                              provider.LastSelfUserCmdSeqId, oldestHistory, latestHistory);
            return(true);
        }
Beispiel #2
0
        public void SyncLatest()
        {
            var lastestSnapshot = snapshotSelector.LatestSnapshot;

            if (null == lastestSnapshot)
            {
                return;
            }
            if (latestSnapshotSeq != lastestSnapshot.SnapshotSeq)
            {
                gameContexts.Self = lastestSnapshot.Self;
                latestSnapshotSeq = lastestSnapshot.SnapshotSeq;
                EntityMap remoteEntityMap = SyncLatestEntityMap.Allocate(false);
                EntityMap localEntityMap  = SyncLatestEntityMap.Allocate(false);

                remoteEntityMap.AddAll(RemoteEntityMap);
                localEntityMap.AddAll(LocalEntityMap);
                latestCompareAgent.Init(diffHandler, lastestSnapshot.ServerTime);
                EntityMapCompareExecutor.Diff(localEntityMap, remoteEntityMap, diffHandler, "syncLatest",
                                              latestCompareAgent);

                RefCounterRecycler.Instance.ReleaseReference(remoteEntityMap);
                RefCounterRecycler.Instance.ReleaseReference(localEntityMap);
            }
        }
        private void RewindTo(EntityMap remoteEntityMap)
        {
            var localEntityMapClone = PredictionEntityMap.Allocate(false);

            localEntityMapClone.AddAll(provider.LocalEntityMap);
            EntityMapCompareExecutor.Diff(localEntityMapClone, remoteEntityMap, rewindDiffHandler, "predicateRewind", gameEntityRewindComparator);
            RefCounterRecycler.Instance.ReleaseReference(localEntityMapClone);
        }
Beispiel #4
0
        protected override EntityMap CreateEntityMap(int serverTime)
        {
            SnapshotPair pair = _snapshotSelector.SelectSnapshot(serverTime);

            if (pair != null)
            {
                CompensationMapDiffHandler diffHandler = new CompensationMapDiffHandler(new InterpolationInfo(pair));
                EntityMap left  = pair.LeftSnapshot.CompensationEntityMap;
                EntityMap right = pair.RightSnapshot.CompensationEntityMap;
                EntityMapCompareExecutor.Diff(left, right, diffHandler, "compensation", null);
                return(diffHandler.TheSnapshot.EntityMap);
            }
            _logger.ErrorFormat("can't get snapshot at {0}, current range: {1}-{2}",
                                serverTime,
                                _snapshotSelector.OldestSnapshot.ServerTime,
                                _snapshotSelector.LatestSnapshot.ServerTime);
            return(null);
        }
        private void PlayBackInterpolationAll(EntityMap localEntityMap, EntityMap remoteEntityMapLeft,
                                              EntityMap remoteEntityMapRight)
        {
            try
            {
                SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.PlaybackInit2);
                PlaybackLMapIntroplateDiffHandler interpolateDiffHandler = introplateDiffHandler.init(localEntityMap,
                                                                                                      infoProvider.InterpolationInfo, playBackInfos);

                EntityMapCompareExecutor.Diff(remoteEntityMapLeft, remoteEntityMapRight, interpolateDiffHandler,
                                              "playbackInterpolate",
                                              interpolateCompareAgent.Init(interpolateDiffHandler, infoProvider.InterpolationInfo,
                                                                           localEntityMap));
            }
            finally
            {
                SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.PlaybackInit2);
            }
        }
Beispiel #6
0
        public int Serialize(ISnapshot baseSnap, ISnapshot snap, Stream stream)
        {
//            _binaryWriter = new MyBinaryWriter(stream);
            _binaryWriter = MyBinaryWriter.Allocate(stream);
            Reset();
            snap.Header.Serialize(_binaryWriter, _version);
            var baseMap    = baseSnap.EntityMap;
            var currentMap = snap.EntityMap;
            SnapshotPatchGenerator handler = new SnapshotPatchGenerator(_serializerManager);

            EntityMapCompareExecutor.Diff(baseMap, currentMap, handler, "serialize", null);
            SnapshotPatch patch = handler.Detach();

            patch.BaseSnapshotSeq = baseSnap.SnapshotSeq;
            patch.Serialize(_binaryWriter, _serializerManager);
            _binaryWriter.ReleaseReference();
            patch.ReleaseReference();
            return(_binaryWriter.WriterLenght);
        }
        private void PlayBackInit(EntityMap localEntityMap, EntityMap remoteEntityMapLeft)
        {
            diffHandler.init();

            var localEntityMapClone = PlayBackEntityMap.Allocate(false);

            localEntityMapClone.AddAll(infoProvider.LocalEntityMap);
            lastLeftPlaybackSnapshotServerTime = infoProvider.InterpolationInfo.LeftServerTime;
            try
            {
                SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.PlaybackInit1);
                EntityMapCompareExecutor.Diff(localEntityMapClone, remoteEntityMapLeft, diffHandler, "playbackInit",
                                              compareAgent.Init(diffHandler, infoProvider.InterpolationInfo, localEntityMap));
                RefCounterRecycler.Instance.ReleaseReference(localEntityMapClone);
            }
            finally
            {
                SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.PlaybackInit1);
            }
        }
        public void RewindFirstSnapshot(EntityKey self)
        {
            var localEntityMapClone = PredictionEntityMap.Allocate(false);

            provider.SetSelf(self);
            provider.Update();
            localEntityMapClone.AddAll(provider.LocalEntityMap);
            logger.InfoFormat("{0}   {1}", provider.LocalEntityMap.Count, localEntityMapClone.Count);
            checkDiffHandler.SetRemoteCmdSeq(provider.LastSelfUserCmdSeqId);
            EntityMapCompareExecutor.Diff(localEntityMapClone, provider.RemoteEntityMap, checkDiffHandler,
                                          "RewindFirstSnapshotompare", gameEntityComparator);
            foreach (var gameEntity in provider.RemoteEntityMap.ToArray())
            {
                foreach (var gameComponent in gameEntity.ComponentList)
                {
                    logger.InfoFormat("{0}", gameComponent);
                }
            }

            EntityMapCompareExecutor.Diff(localEntityMapClone, provider.RemoteEntityMap, rewindDiffHandler,
                                          "rewindFirstSnapshot", gameEntityRewindComparator);
            RefCounterRecycler.Instance.ReleaseReference(localEntityMapClone);
        }