Beispiel #1
0
        private void Update(EvaluationContext context)
        {
            var startPosition = StartValue.GetValue(context);
            var modulo        = Modulo.GetValue(context);
            var increment     = Increment.GetValue(context);

            _rate     = Rate.GetValue(context);
            _phase    = Phase.GetValue(context);
            _blending = Blending.GetValue(context);
            var reset = TriggerReset.GetValue(context);
            var jump  = TriggerCount.GetValue(context);

            //var jump = false;

            if (!_initialized || reset || float.IsNaN(_count))
            {
                _count       = 0;
                _initialized = true;
                jump         = true;
            }

            _beatTime = EvaluationContext.BeatTime;

            if (UseRate)
            {
                var activationIndex = (int)(_beatTime * _rate + _phase);
                if (activationIndex != _lastActivationIndex)
                {
                    //Log.Debug($"ai {activationIndex}  != {_lastActivationIndex}  rate={_rate} t = {_beatTime} ");
                    _lastActivationIndex = activationIndex;
                    jump = true;
                }
            }

            if (jump)
            {
                if (modulo > 0.001f)
                {
                    _jumpStartOffset   = _jumpTargetOffset;
                    _jumpTargetOffset += 1;
                }
                else
                {
                    _jumpStartOffset  = _count;
                    _jumpTargetOffset = _count + increment;
                }

                // if (_jumpTargetOffset > modulo)
                // {
                //     _count = 0;
                //     _jumpStartOffset = 0;
                //     _jumpTargetOffset = increment;
                // }
                _lastJumpTime = _beatTime;
            }

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

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

            if (modulo > 0.001f)
            {
                Result.Value = (_count % modulo) * increment + startPosition;
            }
            else
            {
                Result.Value = _count + startPosition;
            }

            WasStep.Value = jump;
            Result.DirtyFlag.Clear();
            WasStep.DirtyFlag.Clear();
        }
Beispiel #2
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;
        }
Beispiel #3
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;
        }