Esempio n. 1
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);
        }
Esempio n. 2
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));
                }
            }
        }
    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);
                }
            }
        }
    }