Ejemplo n.º 1
0
        private void PlaybackEventTrigger(ChartEvent evt, PlayDirection direction)
        {
            if (direction == PlayDirection.Forward)
            {
                switch (evt)
                {
                case EffectKindEvent effectKind:
                {
                    var effect = m_currentEffects[effectKind.EffectIndex] = effectKind.Effect;
                    if (effect == null)
                    {
                        m_audioController.RemoveEffect(effectKind.EffectIndex);
                    }
                    else
                    {
                        m_audioController.SetEffect(effectKind.EffectIndex, CurrentQuarterNodeDuration, effect, 1.0f);
                    }
                }
                break;

                case LaserApplicationEvent app: m_highwayControl.LaserApplication = app.Application; break;

                // TODO(local): left/right lasers separate + allow both independent if needed
                case LaserFilterGainEvent filterGain: laserGain = filterGain.Gain; break;

                case LaserFilterKindEvent filterKind:
                {
                    m_audioController.SetEffect(6, CurrentQuarterNodeDuration, currentLaserEffectDef = filterKind.Effect, m_audioController.GetEffectMix(6));
                }
                break;

                case LaserParamsEvent pars:
                {
                    if (pars.LaserIndex.HasFlag(LaserIndex.Left))
                    {
                        m_highwayControl.LeftLaserParams = pars.Params;
                    }
                    if (pars.LaserIndex.HasFlag(LaserIndex.Right))
                    {
                        m_highwayControl.RightLaserParams = pars.Params;
                    }
                }
                break;

                case SlamVolumeEvent pars: m_slamSample.Volume = pars.Volume; break;
                }
            }

            switch (evt)
            {
            case SpinImpulseEvent spin: m_highwayControl.ApplySpin(spin.Params, spin.AbsolutePosition); break;

            case SwingImpulseEvent swing: m_highwayControl.ApplySwing(swing.Params, swing.AbsolutePosition); break;

            case WobbleImpulseEvent wobble: m_highwayControl.ApplyWobble(wobble.Params, wobble.AbsolutePosition); break;
            }
        }
Ejemplo n.º 2
0
        public override void Update(float delta, float total)
        {
            time_t audioPosition  = m_audio?.Position ?? 0;
            time_t visualPosition = audioPosition - m_visualOffset;

            m_audioPlayback.Position = audioPosition;
            m_judge.Position         = audioPosition;

            m_visualPlayback.Position = visualPosition;
            m_highwayControl.Position = visualPosition;

            //Logger.Log($"{ m_visualPlayback.ViewDistanceForward } / { m_visualPlayback.ViewDistanceForward }");

            float GetPathValueLerped(time_t pos, HybridLabel stream)
            {
                var s = m_audioPlayback.Chart[stream];

                var mrPoint = s.MostRecent <GraphPointEvent>(pos);

                if (mrPoint == null)
                {
                    return(((GraphPointEvent?)s.First)?.Value ?? 0);
                }

                if (mrPoint.HasNext)
                {
                    float alpha = (float)((pos - mrPoint.AbsolutePosition).Seconds / (mrPoint.Next.AbsolutePosition - mrPoint.AbsolutePosition).Seconds);
                    return(MathL.Lerp(mrPoint.Value, ((GraphPointEvent)mrPoint.Next).Value, alpha));
                }
                else
                {
                    return(mrPoint.Value);
                }
            }

            for (int i = 0; i < m_queuedSlamSamples.Count;)
            {
                time_t slam = m_queuedSlamSamples[i];
                if (slam < audioPosition)
                {
                    m_queuedSlamSamples.RemoveAt(i);
                    m_slamSample.Replay();
                }
                else
                {
                    i++;
                }
            }

            for (int e = 0; e < m_queuedSlamTiedEvents.Count;)
            {
                var evt = m_queuedSlamTiedEvents[e];
                if (evt.AbsolutePosition < visualPosition)
                {
                    switch (evt)
                    {
                    case SpinImpulseEvent spin: m_highwayControl.ApplySpin(spin.Params, visualPosition); break;

                    case SwingImpulseEvent swing: m_highwayControl.ApplySwing(swing.Params, visualPosition); break;

                    case WobbleImpulseEvent wobble: m_highwayControl.ApplyWobble(wobble.Params, visualPosition); break;

                    default: e++; continue;
                    }

                    m_queuedSlamTiedEvents.RemoveAt(e);
                }
                else
                {
                    e++;
                }
            }

            time_t laserAnticipateLookAhead = visualPosition + m_chart.ControlPoints.MostRecent(visualPosition).MeasureDuration * 0.5;
            time_t laserSlamSwingDuration   = 0.15;

            for (int i = 0; i < 2; i++)
            {
                m_laserInputs[i] = i; // 0 or 1, default values for each side

                var currentLaser = m_chart[i + 6].MostRecent <AnalogEntity>(visualPosition);
                if (currentLaser == null || visualPosition > currentLaser.AbsoluteEndPosition)
                {
                    float inputValue = m_laserInputs[i];
                    if (currentLaser is { } slam&& slam.IsInstant && visualPosition <= slam.AbsoluteEndPosition + laserSlamSwingDuration)
                    {
                        inputValue = slam.FinalValue;
                    }

                    var checkAnalog = m_chart[i + 6].MostRecent <AnalogEntity>(laserAnticipateLookAhead)?.Head;
                    while (checkAnalog != null && checkAnalog.HasPrevious && checkAnalog.Previous is AnalogEntity pAnalog && (pAnalog = pAnalog.Head).AbsolutePosition > visualPosition)
                    {
                        checkAnalog = pAnalog;
                    }

                    if (checkAnalog != null && checkAnalog.AbsolutePosition > visualPosition)
                    {
                        if (i == 0)
                        {
                            inputValue = MathL.Max(checkAnalog !.InitialValue, inputValue);
                        }
                        else
                        {
                            inputValue = MathL.Min(checkAnalog !.InitialValue, inputValue);
                        }
                    }

                    m_laserInputs[i] = inputValue;
                }
                else
                {
                    m_laserInputs[i] = currentLaser.SampleValue(visualPosition);
                }
            }

            m_highwayControl.MeasureDuration = m_chart.ControlPoints.MostRecent(visualPosition).MeasureDuration;

            m_highwayControl.LeftLaserInput  = m_laserInputs[0];
            m_highwayControl.RightLaserInput = 1 - m_laserInputs[1];

            m_highwayControl.Zoom = GetPathValueLerped(visualPosition, NscLane.CameraZoom);
            //m_highwayControl.Zoom = 0;
            m_highwayControl.Pitch = GetPathValueLerped(visualPosition, NscLane.CameraPitch);
            //m_highwayControl.Pitch = m_tempPitch;
            //Console.WriteLine(m_tempPitch);
            m_highwayControl.Offset = GetPathValueLerped(visualPosition, NscLane.CameraOffset);
            m_highwayControl.Roll   = GetPathValueLerped(visualPosition, NscLane.CameraTilt);

            m_highwayView.Split0 = GetPathValueLerped(visualPosition, NscLane.Split2);
            m_highwayView.Split1 = GetPathValueLerped(visualPosition, NscLane.Split2);
            m_highwayView.Split2 = GetPathValueLerped(visualPosition, NscLane.Split2);
            m_highwayView.Split3 = GetPathValueLerped(visualPosition, NscLane.Split2);
            m_highwayView.Split4 = GetPathValueLerped(visualPosition, NscLane.Split2);

            for (int i = 0; i < 8; i++)
            {
                var judge = m_judge[i];
                m_streamHasActiveEffects[i] = judge.IsBeingPlayed;
            }

            for (int i = 0; i < 8; i++)
            {
                bool active = m_streamHasActiveEffects[i] && m_activeObjects[i] != null;
                if (i == 6)
                {
                    active |= m_streamHasActiveEffects[i + 1] && m_activeObjects[i + 1] != null;
                }
                m_audioController.SetEffectActive(i, active);
            }

            UpdateEffects();
            m_audioController.EffectsActive = true;

            m_highwayControl.Update(Time.Delta);
            m_highwayControl.ApplyToView(m_highwayView);

            for (int i = 0; i < 8; i++)
            {
                var obj = m_activeObjects[i];

                m_highwayView.SetStreamActive(i, m_streamHasActiveEffects[i]);

                if (obj == null)
                {
                    continue;
                }

                float glow      = -0.5f;
                int   glowState = 0;

                if (m_streamHasActiveEffects[i])
                {
                    glow      = MathL.Cos(10 * MathL.TwoPi * (float)visualPosition) * 0.35f;
                    glowState = 2 + MathL.FloorToInt(visualPosition.Seconds * 20) % 2;
                }

                m_highwayView.SetObjectGlow(obj, glow, glowState);
            }

            const float SCALING = 1.05f;

            if (Window.Width > Window.Height)
            {
                m_highwayView.Viewport = ((int)(Window.Width - Window.Height * SCALING) / 2, (int)(Window.Height * 0.95f - Window.Height * SCALING), (int)(Window.Height * SCALING));
            }
            else
            {
                m_highwayView.Viewport = (0, (Window.Height - Window.Width) / 2 - Window.Width / 5, Window.Width);
            }
            m_highwayView.Update();

            {
                //var camera = m_highwayView.Camera;

                var defaultTransform     = m_highwayView.DefaultTransform;
                var defaultZoomTransform = m_highwayView.DefaultZoomedTransform;
                var totalWorldTransform  = m_highwayView.WorldTransform;
                var critLineUiTransform  = m_highwayView.CritLineTransform;

                Vector2 comboLeft  = m_highwayView.Project(defaultTransform, new Vector3(-0.8f / 6, 0, 0));
                Vector2 comboRight = m_highwayView.Project(defaultTransform, new Vector3(0.8f / 6, 0, 0));

                m_comboDisplay.DigitSize = (comboRight.X - comboLeft.X) / 4;

                Vector2 critRootUiPosition      = m_highwayView.Project(critLineUiTransform, Vector3.Zero);
                Vector2 critRootUiPositionWest  = m_highwayView.Project(critLineUiTransform, new Vector3(-1, 0, 0));
                Vector2 critRootUiPositionEast  = m_highwayView.Project(critLineUiTransform, new Vector3(1, 0, 0));
                Vector2 critRootPositionForward = m_highwayView.Project(critLineUiTransform, new Vector3(0, 0, -1));

                Vector2 critRootWorldPosition     = m_highwayView.Project(totalWorldTransform, Vector3.Zero);
                Vector2 critRootWorldPositionWest = m_highwayView.Project(totalWorldTransform, new Vector3(-1, 0, 0));
                Vector2 critRootWorldPositionEast = m_highwayView.Project(totalWorldTransform, new Vector3(1, 0, 0));

                for (int i = 0; i < 2; i++)
                {
                    if (m_cursorsActive[i])
                    {
                        m_cursorAlphas[i] = MathL.Min(1, m_cursorAlphas[i] + delta * 3);
                    }
                    else
                    {
                        m_cursorAlphas[i] = MathL.Max(0, m_cursorAlphas[i] - delta * 5);
                    }
                }

                void GetCursorPosition(int lane, out float pos, out float range)
                {
                    var judge = (LaserJudge)m_judge[lane + 6];

                    pos   = judge.CursorPosition;
                    range = judge.LaserRange;
                }

                float GetCursorPositionWorld(float xWorld)
                {
                    var critRootCenter = m_highwayView.Project(defaultZoomTransform, Vector3.Zero);
                    var critRootCursor = m_highwayView.Project(defaultZoomTransform, new Vector3(xWorld, 0, 0));

                    return(critRootCursor.X - critRootCenter.X);
                }

                GetCursorPosition(0, out float leftLaserPos, out float leftLaserRange);
                GetCursorPosition(1, out float rightLaserPos, out float rightLaserRange);

                float critRootWorldWidth = (m_highwayView.Project(defaultZoomTransform, new Vector3(-0.5f, 0, 0)) - m_highwayView.Project(defaultZoomTransform, new Vector3(0.5f, 0, 0))).Length();
                m_critRootWorld.WorldUnitSize = critRootWorldWidth;

                m_critRootWorld.LeftCursorPosition  = 2 * (leftLaserPos - 0.5f) * (5.0f / 6) * leftLaserRange;
                m_critRootWorld.LeftCursorAlpha     = m_cursorAlphas[0];
                m_critRootWorld.RightCursorPosition = 2 * (rightLaserPos - 0.5f) * (5.0f / 6) * rightLaserRange;
                m_critRootWorld.RightCursorAlpha    = m_cursorAlphas[1];

                Vector2 critUiRotationVector = critRootUiPositionEast - critRootUiPositionWest;
                float   critRootUiRotation   = MathL.Atan(critUiRotationVector.Y, critUiRotationVector.X);

                Vector2 critWorldRotationVector = critRootWorldPositionEast - critRootWorldPositionWest;
                float   critRootWorldRotation   = MathL.Atan(critWorldRotationVector.Y, critWorldRotationVector.X);

                m_critRootUi.Position    = critRootUiPosition;
                m_critRootWorld.Position = critRootWorldPosition;

                m_critRootUi.Rotation    = MathL.ToDegrees(critRootUiRotation) + m_highwayControl.CritLineEffectRoll * 25;
                m_critRootWorld.Rotation = MathL.ToDegrees(critRootWorldRotation);
            }

            m_background.HorizonHeight  = m_highwayView.HorizonHeight;
            m_background.CombinedTilt   = m_highwayControl.LaserRoll + m_highwayControl.Roll * 360;
            m_background.EffectRotation = m_highwayControl.EffectRoll * 360;
            m_background.SpinTimer      = m_highwayControl.SpinTimer;
            m_background.SwingTimer     = m_highwayControl.SwingTimer;
            m_background.Update(delta, total);

            SetLuaDynamicData();
            //m_script.Update(delta, total);

            base.Update(delta, total);
        }