Exemplo n.º 1
0
        public override void OnSimulateBefore(NetworkObj obj)
        {
            if (Interpolation.Enabled)
            {
                var root = (NetworkState)obj.Root;

                if (root.Entity.IsOwner)
                {
                    return;
                }

                if (root.Entity.HasControl && !ToController)
                {
                    return;
                }

                var it    = root.Frames.GetIterator();
                var idx   = obj[this];
                var value = NetMath.InterpolateQuaternion(obj.RootState.Frames, idx + 1, obj.RootState.Entity.Frame);

                while (it.Next())
                {
                    it.val.Values[idx].Quaternion = value;
                }
            }
        }
Exemplo n.º 2
0
        public override void OnSimulateBefore(NetworkObj obj)
        {
            var root = (NetworkState)obj.Root;

            if (root.Entity.IsOwner)
            {
                return;
            }

            if (root.Entity.HasControl && !ToController)
            {
                return;
            }

            var nt = obj.Storage.Values[obj[this]].Transform;

            if (nt != null && nt.Simulate)
            {
                var snapped = false;

                Vector3    pos = Vector3.zero;
                Quaternion rot = Quaternion.identity;

                if (Extrapolation.Enabled)
                {
                    if (PositionEnabled)
                    {
                        pos = NetMath.ExtrapolateVector(
                            /* currentPosition */ GetPosition(nt.Simulate),
                            /* receivedPosition */ obj.Storage.Values[obj[this] + POSITION].Vector3,
                            /* receivedVelocity */ obj.Storage.Values[obj[this] + VELOCITY].Vector3,
                            /* receivedFrame */ obj.RootState.Frames.First.Frame,
                            /* entityFrame */ obj.RootState.Entity.Frame,
                            /* extrapolation */ Extrapolation,
                            /* snapping */ ref snapped
                            );

                        // clamp position
                        pos = nt.Clamper(obj.RootState.Entity.UnityObject, pos);
                    }

                    if (RotationEnabled)
                    {
                        rot = NetMath.ExtrapolateQuaternion(
                            /* currentRotation */ GetRotation(nt.Simulate),
                            /* receivedRotation */ obj.Storage.Values[obj[this] + ROTATION].Quaternion,
                            /* receivedFrame */ obj.RootState.Frames.First.Frame,
                            /* entityFrame */ obj.RootState.Entity.Frame,
                            /* extrapolation */ Extrapolation
                            );
                    }
                }
                else if (Interpolation.Enabled)
                {
                    // position
                    if (PositionEnabled)
                    {
                        pos = NetMath.InterpolateVector(
                            obj.RootState.Frames,
                            obj[this] + POSITION,
                            obj.RootState.Entity.Frame,
                            Interpolation.SnapMagnitude,
                            ref snapped
                            );
                    }

                    // rotation
                    if (RotationEnabled)
                    {
                        rot = NetMath.InterpolateQuaternion(
                            obj.RootState.Frames,
                            obj[this] + ROTATION,
                            obj.RootState.Entity.Frame
                            );
                    }
                }
                else
                {
                    // always snapped on this
                    snapped = true;

                    // position
                    if (PositionEnabled)
                    {
                        pos = obj.Storage.Values[obj[this] + POSITION].Vector3;
                    }

                    // rotation
                    if (RotationEnabled)
                    {
                        rot = obj.Storage.Values[obj[this] + ROTATION].Quaternion;
                    }
                }

                if (PositionEnabled)
                {
                    SetPosition(nt.Simulate, pos);

                    if (snapped)
                    {
                        nt.RenderDoubleBufferPosition = nt.RenderDoubleBufferPosition.Shift(nt.Simulate.position).Shift(nt.Simulate.position);
                    }
                }

                if (RotationEnabled)
                {
                    SetRotation(nt.Simulate, rot);
                }
            }
        }