private void RewindTo(EntityMap remoteEntityMap) { PredictionRewindHandler <TPredictionComponent> rewindHandler = new PredictionRewindHandler <TPredictionComponent>(_handler); var localEntityMapClone = PredictionEntityMap.Allocate(false); localEntityMapClone.AddAll(_handler.LocalEntityMap); EntityMapComparator.Diff(localEntityMapClone, remoteEntityMap, rewindHandler, "predicateRewind"); RefCounterRecycler.Instance.ReleaseReference(localEntityMapClone); }
public void 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); EntityMapComparator.Diff(baseMap, currentMap, handler, "serialize"); SnapshotPatch patch = handler.Detach(); patch.BaseSnapshotSeq = baseSnap.SnapshotSeq; patch.Serialize(_binaryWriter, _serializerManager); _binaryWriter.ReleaseReference(); patch.ReleaseReference(); }
private void PlayBackInterpolationAll(EntityMap localEntityMap, EntityMap remoteEntityMapLeft, EntityMap remoteEntityMapRight) { try { SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.PlaybackInit2); PlaybackIntroplateHandler interpolateHandler = _introplateHandler.init(localEntityMap, _infoProvider.InterpolationInfo, _playBackInfos); EntityMapComparator.Diff(remoteEntityMapLeft, remoteEntityMapRight, interpolateHandler, "playbackInterpolate", _interpolateComparator.Init(interpolateHandler, _infoProvider.InterpolationInfo, localEntityMap)); } finally { SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.PlaybackInit2); } }
protected override EntityMap CreateEntityMap(int serverTime) { SnapshotPair pair = _snapshotSelector.SnapshotSelector.SelectSnapshot(serverTime); if (pair != null) { CompensationSnapshotHandler handler = new CompensationSnapshotHandler(new InterpolationInfo(pair)); var left = pair.LeftSnapshot.CompensationEntityMap; var right = pair.RightSnapshot.CompensationEntityMap; EntityMapComparator.Diff(left, right, handler, "compensation"); return(handler.TheSnapshot.EntityMap); } _logger.ErrorFormat("can't get snapshot at {0}, current range: {1}-{2}", serverTime, _snapshotSelector.SnapshotSelector.OldestSnapshot.ServerTime, _snapshotSelector.SnapshotSelector.LatestSnapshot.ServerTime); return(null); }
private void PlayBackInit(EntityMap localEntityMap, EntityMap remoteEntityMapLeft) { PlaybackDiffHandler diffDiffHandler = _diffDiffHandler.init(); var localEntityMapClone = PlayBackEntityMap.Allocate(false); localEntityMapClone.AddAll(_infoProvider.LocalEntityMap); _lastLeftPlayBackSnapshot = _infoProvider.InterpolationInfo.LeftServerTime; try { SingletonManager.Get <DurationHelp>().ProfileStart(CustomProfilerStep.PlaybackInit1); EntityMapComparator.Diff(localEntityMapClone, remoteEntityMapLeft, diffDiffHandler, "playbackInit", _diffComparator.Init(diffDiffHandler, _infoProvider.InterpolationInfo, localEntityMap)); localEntityMapClone.ReleaseReference(); } finally { SingletonManager.Get <DurationHelp>().ProfileEnd(CustomProfilerStep.PlaybackInit1); } }
private bool IsHistoryDifferentFrom(EntityMap remoteEntityMap) { PredictionCompareHandler <TPredictionComponent> compareHandler = new PredictionCompareHandler <TPredictionComponent>(_handler.RemoteHistoryId); SavedHistory history = GetTargetHistory(_handler.RemoteHistoryId); if (history != null) { EntityMapComparator.Diff(history.EntityMap, remoteEntityMap, compareHandler, "predicteCompare"); if (compareHandler.IsDiff) { SingletonManager.Get <DurationHelp>().IncreaseRewindCount(); _logger.InfoFormat("should rewind for history diff, historyId {0} {1}", _handler.RemoteHistoryId, history.HistoryId); } return(compareHandler.IsDiff); } int oldestHistory = _histories.Count > 0 ? _histories[0].HistoryId : 0; int latestHistory = _histories.Count > 0 ? _histories[_histories.Count - 1].HistoryId : 0; _logger.InfoFormat("should rewind for history not saved, historyId {0}, saved history = {1}-{2}", _handler.RemoteHistoryId, oldestHistory, latestHistory); return(true); }
public void SyncLatest() { if (null == _handler.LatestSnapshot) { return; } if (_latestSnapshotSeq != _handler.LatestSnapshot.SnapshotSeq) { _handler.SetSelf(_handler.LatestSnapshot.Self); _latestSnapshotSeq = _handler.LatestSnapshot.SnapshotSeq; EntityMap remoteEntityMap = SyncLatestEntityMap.Allocate(false); EntityMap localEntityMap = SyncLatestEntityMap.Allocate(false); remoteEntityMap.AddAll(_handler.RemoteEntityMap); localEntityMap.AddAll(_handler.LocalEntityMap); SyncLatestRewindHandler rewindHandler = new SyncLatestRewindHandler(_handler); EntityMapComparator.Diff(localEntityMap, remoteEntityMap, rewindHandler, "syncLatest", _latestComparator.Init(rewindHandler, _handler.LatestSnapshot.ServerTime)); RefCounterRecycler.Instance.ReleaseReference(remoteEntityMap); RefCounterRecycler.Instance.ReleaseReference(localEntityMap); } }
public void RewindFirstSnapshot(EntityKey self) { var localEntityMapClone = PredictionEntityMap.Allocate(false); _handler.SetSelf(self); _handler.Update(); localEntityMapClone.AddAll(_handler.LocalEntityMap); _logger.InfoFormat("{0} {1}", _handler.LocalEntityMap.Count, localEntityMapClone.Count); PredictionCompareHandler <TPredictionComponent> compareHandler = new PredictionCompareHandler <TPredictionComponent>(_handler.RemoteHistoryId); EntityMapComparator.Diff(localEntityMapClone, _handler.RemoteEntityMap, compareHandler, "RewindFirstSnapshotompare"); foreach (var gameEntity in _handler.RemoteEntityMap.ToArray()) { foreach (var gameComponent in gameEntity.ComponentList) { _logger.InfoFormat("{0}", gameComponent); } } PredictionRewindHandler <TPredictionComponent> rewindHandler = new PredictionRewindHandler <TPredictionComponent>(_handler); EntityMapComparator.Diff(localEntityMapClone, _handler.RemoteEntityMap, rewindHandler, "rewindFirstSnapshot"); RefCounterRecycler.Instance.ReleaseReference(localEntityMapClone); }