// Update is called once per frame
    public void Update()
    {
        // Offset by audio calibration
        Vector3 pos = initLocalPos;

        pos.y += TickFunctions.TimeToWorldYPosition(GameSettings.audioCalibrationMS / 1000.0f * GameSettings.gameSpeed);
        transform.localPosition = pos;

        uint currentTickPos = editor.currentSong.WorldYPositionToTick(transform.position.y);

        if (Globals.applicationMode == Globals.ApplicationMode.Playing)
        {
            if (currentTickPos >= nextClapPos)
            {
                if (GameSettings.metronomeActive)
                {
                    sampleStream.volume = GameSettings.sfxVolume * GameSettings.vol_master;
                    sampleStream.pan    = GameSettings.audio_pan;
                    sampleStream.Play();
                }
            }
        }

        nextClapPos = CalculateNextBeatTickPosition(currentTickPos);
    }
 public void SetTime(float time)
 {
     if (Globals.applicationMode == Globals.ApplicationMode.Editor)
     {
         Vector3 pos = initPos;
         pos.y += TickFunctions.TimeToWorldYPosition(time);
         transform.position = pos;
     }
 }
Esempio n. 3
0
 public void SetTime(float time)
 {
     //if (ChartEditor.Instance.currentState == ChartEditor.State.Editor)
     {
         Vector3 pos = initPos;
         pos.y += TickFunctions.TimeToWorldYPosition(time);
         transform.position = pos;
     }
 }
Esempio n. 4
0
    public void PlayingMovement()
    {
        float   speed          = GameSettings.hyperspeed;
        Vector3 pos            = transform.position;
        float   deltaTime      = Time.deltaTime;
        float   positionOffset = initPos.y;

        {
            float timeBeforeMovement = TickFunctions.WorldYPositionToTime(pos.y - positionOffset);
            float timeAfterMovement  = timeBeforeMovement + deltaTime * GameSettings.gameSpeed;

            // Make sure we're staying in sync with the audio
            {
                SongAudioManager songAudioManager = editor.currentSongAudio;

                AudioStream stream = null;

                for (int i = 0; i < EnumX <Song.AudioInstrument> .Count; ++i)
                {
                    Song.AudioInstrument audio = (Song.AudioInstrument)i;
                    if (AudioManager.StreamIsValid(songAudioManager.GetAudioStream(audio)))
                    {
                        stream = songAudioManager.GetAudioStream(audio);
                        break;
                    }
                }

                if (AudioManager.StreamIsValid(stream) && stream.IsPlaying())
                {
                    float audioTimePosition = stream.CurrentPositionInSeconds() - editor.services.totalSongAudioOffset;
                    float desyncAmount      = audioTimePosition - timeAfterMovement;

                    if (Mathf.Abs(desyncAmount) > DESYNCLENIENCE)
                    {
                        timeAfterMovement += desyncAmount;
                    }
                }
            }

            float maxChangeInTimeAllowed = Application.targetFrameRate > 0 ? 2.0f / Application.targetFrameRate : 1.0f / 120.0f;

            float totalChangeInTime = timeAfterMovement - timeBeforeMovement;

            float newTimePosition = TickFunctions.TimeToWorldYPosition(timeBeforeMovement + totalChangeInTime);
            pos.y = newTimePosition + positionOffset;
        }

        selfTransform.position = pos;
        explicitChartPos       = null;

        lastUpdatedRealTime = Time.time;
    }
    void UpdatePosBasedTimelineHandle()
    {
        if (editor.currentChart != null)
        {
            float endYPos       = TickFunctions.TimeToWorldYPosition(editor.currentSong.length);
            float totalDistance = endYPos - initPos.y - strikeLine.localPosition.y;

            if (totalDistance > 0)
            {
                float currentDistance = timeline.handlePos * totalDistance;

                transform.position = initPos + new Vector3(0, currentDistance, 0);
            }
            else
            {
                timeline.handlePos = 0;
                transform.position = initPos;
            }
        }
    }
Esempio n. 6
0
    void ManageGameplay()
    {
        Vector3 notePosition       = transform.position;
        Vector3 strikelinePosition = editor.visibleStrikeline.position;

        bool belowClapLine   = notePosition.y <= strikelinePosition.y + (TickFunctions.TimeToWorldYPosition(GameSettings.audioCalibrationMS / 1000.0f) * GameSettings.gameSpeed);
        bool belowStrikeLine = notePosition.y <= strikelinePosition.y + (Time.deltaTime * GameSettings.hyperspeed / GameSettings.gameSpeed);

        if (GameSettings.bot && belowClapLine)
        {
            GameplayBotHitClap();
        }

        if (hit && belowStrikeLine)
        {
            if (isActivated)
            {
                if (GameSettings.bot)
                {
                    PlayIndicatorAnim();
                }
                DeactivateNote();
            }

            // Resize sustain
            if (!sustainBroken && note.length > 0)
            {
                GameplaySustainHold();
            }
        }

        if (sustainBroken)
        {
            sustainRen.enabled = false;
        }

        if (whammy)
        {
            whammy.canWhammy = hit && !sustainBroken && !GameSettings.bot;
        }
    }
Esempio n. 7
0
    // Update is called once per frame
    public override void OnServiceUpdate()
    {
        // Offset by audio calibration
        Vector3 pos = initLocalPos;

#if BASS_AUDIO
        pos.y += TickFunctions.TimeToWorldYPosition(GameSettings.audioCalibrationMS / 1000.0f * GameSettings.gameSpeed);
#else
        pos.y += Song.TimeToWorldYPosition(Globals.clapCalibrationMS / 1000.0f * Globals.gameSpeed);
#endif
        transform.localPosition = pos;

        uint currentTickPos = editor.currentSong.WorldYPositionToTick(transform.position.y);

        if (Globals.applicationMode == Globals.ApplicationMode.Playing)
        {
            if (currentTickPos >= nextClapPos)
            {
                if (GameSettings.metronomeActive)
                {
#if BASS_AUDIO
                    int channel = Bass.BASS_SampleGetChannel(sample, false); // get a sample channel
                    if (channel != 0)
                    {
                        Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, GameSettings.sfxVolume * GameSettings.vol_master);
                        Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_PAN, GameSettings.audio_pan);
                        Bass.BASS_ChannelPlay(channel, false); // play it
                    }
                    else
                    {
                        Debug.LogError("Clap error: " + Bass.BASS_ErrorGetCode() + ", " + sample);
                    }
#else
                    clapSource.PlayOneShot(clap);
#endif
                }
            }
        }

        nextClapPos = CalculateNextBeatTickPosition(currentTickPos);
    }
    public void PlayingMovement()
    {
        float   speed     = GameSettings.hyperspeed;
        Vector3 pos       = transform.position;
        float   deltaTime = Time.deltaTime;

        //float oldPos = pos.y;

        if (playStartTime != null && playStartPosition != null)
        {
            float time = Time.realtimeSinceStartup - (float)playStartTime; //(float)timeSync.GetTime();//
            if (time < 0)
            {
                time = 0;
            }

            pos.y = (float)playStartPosition + TickFunctions.TimeToWorldYPosition(time * GameSettings.gameSpeed);

            //time -= (Globals.audioCalibrationMS / 1000f * Globals.gameSpeed + editor.currentSong.offset);

            //pos.y = /*(float)playStartPosition +*/ Song.TimeToWorldYPosition(time);
        }
        else
        {
            pos.y += (speed * deltaTime);
        }

        //float newPos = pos.y;

        //if ((newPos - oldPos) > 0.4)
        //Debug.Log("Position difference: " + (newPos - oldPos) + ", Delta time: " + Time.deltaTime + ", Frame: " + Time.frameCount);
        //Debug.Log(Time.renderedFrameCount);
        selfTransform.position = pos;
        explicitChartPos       = null;

        lastUpdatedRealTime = Time.time;
    }
    void UpdateTimelineHandleBasedPos()
    {
        if (editor.currentChart != null)
        {
            // Front cap
            if (Globals.applicationMode == Globals.ApplicationMode.Editor)
            {
                if (transform.position.y < initPos.y)
                {
                    transform.position = initPos;
                }
            }

            float endYPos       = TickFunctions.TimeToWorldYPosition(editor.currentSong.length);
            float totalDistance = endYPos - initPos.y - strikeLine.localPosition.y;

            if (transform.position.y + strikeLine.localPosition.y > endYPos)
            {
                transform.position = new Vector3(transform.position.x, endYPos - strikeLine.localPosition.y, transform.position.z);
            }

            float currentDistance = transform.position.y - initPos.y;

            //if (Globals.applicationMode != Globals.ApplicationMode.Playing)
            //{
            if (totalDistance > 0)
            {
                timeline.handlePos = currentDistance / totalDistance;
            }
            else
            {
                timeline.handlePos = 0;
            }
            //}
        }
    }
Esempio n. 10
0
 public float TickToWorldYPosition(uint position, float resolution)
 {
     return(TickFunctions.TimeToWorldYPosition(TickToTime(position, resolution)));
 }