Esempio n. 1
0
        private void Update(EvaluationContext context)
        {
            var startPosition = Position.GetValue(context);
            var limitRange    = MaxRange.GetValue(context);
            var seed          = Seed.GetValue(context);
            var jumpDistance  = JumpDistance.GetValue(context);

            _rate = Rate.GetValue(context);

            var reset = Reset.GetValue(context);
            var jump  = Jump.GetValue(context);

            if (!_initialized || reset || float.IsNaN(_offset.X) || float.IsNaN(_offset.Y) || seed != _seed)
            {
                _random      = new Random(seed);
                _seed        = seed;
                _offset      = Vector2.Zero;
                _initialized = true;
                jump         = true;
            }

            _beatTime = EvaluationContext.BeatTime;

            if (UseRate)
            {
                var activationIndex = (int)(_beatTime * _rate);
                if (activationIndex != _lastActivationIndex)
                {
                    _lastActivationIndex = activationIndex;
                    jump = true;
                }
            }

            if (jump)
            {
                _jumpStartOffset  = _offset;
                _jumpTargetOffset = _offset + new Vector2(
                    (float)((_random.NextDouble() - 0.5f) * jumpDistance * 2f),
                    (float)((_random.NextDouble() - 0.5f) * jumpDistance * 2f));

                if (limitRange > 0.001f)
                {
                    var d = _jumpTargetOffset.Length();
                    if (d > limitRange)
                    {
                        var overshot            = Math.Min(d - limitRange, limitRange);
                        var random              = _random.NextDouble() * overshot;
                        var distanceWithinLimit = limitRange - (float)random;
                        var normalized          = _jumpTargetOffset / d;
                        _jumpTargetOffset = normalized * distanceWithinLimit;
                    }
                }

                _lastJumpTime = _beatTime;
            }

            var blending = Blending.GetValue(context);

            if (blending >= 0.001)
            {
                var t = (Fragment / blending).Clamp(0, 1);
                if (SmoothBlending.GetValue(context))
                {
                    t = MathUtils.SmootherStep(0, 1, t);
                }

                _offset = Vector2.Lerp(_jumpStartOffset, _jumpTargetOffset, t);
            }
            else
            {
                _offset = _jumpTargetOffset;
            }

            NewPosition.Value = _offset + startPosition;
        }
Esempio n. 2
0
        private void Update(EvaluationContext context)
        {
            var startValue   = Value.GetValue(context);
            var limitRange   = MaxRange.GetValue(context);
            var seed         = Seed.GetValue(context);
            var jumpDistance = JumpDistance.GetValue(context);

            _rate = Rate.GetValue(context);

            var reset = Reset.GetValue(context);
            var jump  = Jump.GetValue(context);

            if (!_initialized || reset || float.IsNaN(_offset))
            {
                _random      = new Random(seed);
                _offset      = 0;
                _initialized = true;
                jump         = true;
            }

            _beatTime = context.Playback.FxTimeInBars;

            if (UseRate)
            {
                var activationIndex = (int)(_beatTime * _rate);
                if (activationIndex != _lastActivationIndex)
                {
                    _lastActivationIndex = activationIndex;
                    jump = true;
                }
            }

            if (jump)
            {
                _jumpStartOffset  = _offset;
                _jumpTargetOffset = _offset + (float)((_random.NextDouble() - 0.5f) * jumpDistance * 2f);

                if (limitRange > 0.001f)
                {
                    var d = Math.Abs(_jumpTargetOffset);
                    if (d > limitRange)
                    {
                        var overshot = Math.Min(d - limitRange, limitRange);
                        var random   = (_random.NextDouble() * overshot);

                        _jumpTargetOffset = _jumpTargetOffset > 0
                                                ? (limitRange - (float)random)
                                                : (-limitRange + (float)random);
                    }
                }

                _lastJumpTime = _beatTime;
            }

            var blending = Blending.GetValue(context);

            if (blending >= 0.001)
            {
                var t = (Fragment / blending).Clamp(0, 1);
                if (SmoothBlending.GetValue(context))
                {
                    t = MathUtils.SmootherStep(0, 1, t);
                }

                _offset = MathUtils.Lerp(_jumpStartOffset, _jumpTargetOffset, t);
            }
            else
            {
                _offset = _jumpTargetOffset;
            }

            Result.Value = _offset + startValue;
        }