Exemplo n.º 1
0
 protected IReplayFrameRecorder(IReplayWriter replayWriter, IReplayFrameRecorder baseFrame)
 {
     ReplayWriter   = replayWriter;
     ReplayEntities = ReplayManager.Instance.ReplayEntities;
     StaticEntities = ReplayManager.Instance.ReplayStaticEntities;
     BaseFrame      = baseFrame;
 }
Exemplo n.º 2
0
        private void WriteTimelineHeaderToStream(IReplayWriter writer)
        {
            _replayStartPositionsInStream.Add((int)_replayWriter.GetStream().Position, 0);
            // add last byte position
            var timelineHeader = new ReplayMetaTimelineHeader(
                (byte)TimelineInheritance,
                _fromFrame,
                _replayStartPositionsInStream);

            timelineHeader.WriteFrame(writer);
        }
Exemplo n.º 3
0
        private int WriteReplayHeader(IReplayWriter writer)
        {
            var header = new ReplayMetaHeader(
                1,
                (byte)SceneManager.GetActiveScene().buildIndex,
                (byte)_hz,
                _replayDeltaMode,
                (byte)(TimeLineNumber + 1)
                );

            return(header.WriteFrame(writer));
        }
Exemplo n.º 4
0
        public int WriteFrame(IReplayWriter writer)
        {
            writer.Write(TimelineInheritance);
            writer.Write(StartFromFrame);
            writer.Write(ReplayPointer.Count);

            foreach (var memoryPosition in ReplayPointer.GetEntries())
            {
                writer.Write(memoryPosition.Index);
            }

            Debug.Log("Write Timelineheader\n" + this);
            return(SizeInBytes);
        }
        public static IReplayFrameRecorder CreateReplayDeltaRecorder(IReplayWriter writer,
                                                                     IReplayFrameRecorder baseFrame, ReplayDeltaMode replayDeltaMode)
        {
            switch (replayDeltaMode)
            {
            case ReplayDeltaMode.DeltaCompression:
                return(new ReplayDeltaRecorder(writer, baseFrame));

            case ReplayDeltaMode.SubFrame:
                return(new ReplaySubframeRecorder(writer, baseFrame));

            default:
                return(null);
            }
        }
Exemplo n.º 6
0
        private void Init(System.IO.Stream stream, float recTime = 0)
        {
            _replayWriter           = new ReplayWriteStream(stream);
            _replaySnapshotRecorder = new ReplaySnapshotRecorder(_replayWriter);
            _replayDeltaRecorder    = ReplayDeltaFactory.CreateReplayDeltaRecorder(
                _replayWriter,
                _replaySnapshotRecorder,
                _replayDeltaMode);

            _replayStartPositionsInStream.Clear();
            RegisterEnitites();
            RecordingTime = recTime;
            OnRecordStarted?.Invoke(this);

            Debug.Log("ASDASDASA");
            _tick = 1;
        }
Exemplo n.º 7
0
        public void RecordAllReplayObservable(IReplayWriter writer, ReplayInfo info)
        {
            foreach (var childEntity in _childEntities)
            {
                if (Debug.isDebugBuild)
                {
                    // sizeof(int) weil die position um 4 nachruckt
                    writer.Write(childEntity.ToString());
                    writer.Write((int)writer.GetStream().Position + sizeof(int));
                }

                childEntity.OnReplayRecord(writer, info);

                if (Debug.isDebugBuild)
                {
                    writer.Write((int)writer.GetStream().Position + sizeof(int));
                }
            }
        }
Exemplo n.º 8
0
 public ReplayRecorderBehaviour(IReplayWriter replayWriter, bool debug = false)
 {
     m_writer = replayWriter;
     m_debug  = debug;
 }
    public void OnReplayRecord(IReplayWriter stream, ReplayInfo info)
    {
        _transformFlags = TransformFlags.None;
        if (info.ReplayStateMode == ReplayStateMode.Snapshot)
        {
            _snapshotPosition = transform.position;
            _snapshotRotation = transform.rotation;

            stream.Write(_snapshotPosition);
            stream.Write(_snapshotRotation);

            if (_rigidbody && trackRigid)
            {
                _snapshotVelocity        = _rigidbody.velocity;
                _snapshotAngularVelocity = _rigidbody.angularVelocity;
                stream.Write(_snapshotVelocity);
                stream.Write(_snapshotAngularVelocity);
            }
        }
        else if (info.ReplayStateMode == ReplayStateMode.Delta)
        {
            if (!ReplayMath.IsApproximatelyEqual(transform.position, _snapshotPosition))
            {
                _transformFlags |= TransformFlags.Transform;
            }

            if (!ReplayMath.IsApproximatelyEqual(transform.rotation, _snapshotRotation))
            {
                _transformFlags |= TransformFlags.Rotation;
            }

            if (_rigidbody && trackRigid)
            {
                if (!ReplayMath.IsApproximatelyEqual(_rigidbody.velocity, _snapshotVelocity))
                {
                    _transformFlags |= TransformFlags.Velocity;
                }

                if (!ReplayMath.IsApproximatelyEqual(_rigidbody.angularVelocity, _snapshotAngularVelocity))
                {
                    _transformFlags |= TransformFlags.AngularVelocity;
                }
            }

            stream.Write((byte)_transformFlags);
            if (_transformFlags.HasFlag(TransformFlags.Transform))
            {
                if (info.ReplayDeltaMode == ReplayDeltaMode.DeltaCompression)
                {
                    stream.Write(transform.position - _snapshotPosition);
                    _snapshotPosition = transform.position;
                }
                else if (info.ReplayDeltaMode == ReplayDeltaMode.SubFrame)
                {
                    stream.Write(transform.position);
                }
            }

            if (_transformFlags.HasFlag(TransformFlags.Rotation))
            {
                if (info.ReplayDeltaMode == ReplayDeltaMode.DeltaCompression)
                {
                    stream.Write(transform.rotation * Quaternion.Inverse(_snapshotRotation));
                    _snapshotRotation = transform.rotation;
                }
                else if (info.ReplayDeltaMode == ReplayDeltaMode.SubFrame)
                {
                    stream.Write(transform.rotation);
                }
            }

            if (_transformFlags.HasFlag(TransformFlags.Velocity))
            {
                if (info.ReplayDeltaMode == ReplayDeltaMode.DeltaCompression)
                {
                    stream.Write(_rigidbody.velocity - _snapshotVelocity);
                    _snapshotVelocity = _rigidbody.velocity;
                }
                else if (info.ReplayDeltaMode == ReplayDeltaMode.SubFrame)
                {
                    stream.Write(_rigidbody.velocity);
                }
            }

            if (_transformFlags.HasFlag(TransformFlags.AngularVelocity))
            {
                if (info.ReplayDeltaMode == ReplayDeltaMode.DeltaCompression)
                {
                    stream.Write(_rigidbody.angularVelocity - _snapshotAngularVelocity);
                    _snapshotAngularVelocity = _rigidbody.angularVelocity;
                }
                else if (info.ReplayDeltaMode == ReplayDeltaMode.SubFrame)
                {
                    stream.Write(_rigidbody.angularVelocity);
                }
            }
        }
    }
Exemplo n.º 10
0
 public ReplayDeltaRecorder(IReplayWriter replayWriter, IReplayFrameRecorder baseFrame) : base(replayWriter, baseFrame)
 {
 }
Exemplo n.º 11
0
 public ReplaySnapshotRecorder(IReplayWriter replayWriter) : base(replayWriter, null)
 {
 }