BurstLinq

make BGM resync when changing pitch (to test)
This commit is contained in:
minenice55 2024-04-05 14:15:37 -04:00
parent ff4b3523af
commit 317b3413f3
20 changed files with 156 additions and 59 deletions

View file

@ -5,7 +5,6 @@ using UnityEngine;
using Jukebox;
using HeavenStudio.Util;
using System.Data.Common;
namespace HeavenStudio
{
@ -20,6 +19,8 @@ namespace HeavenStudio
public List<AddedPitchChange> addedPitchChanges = new List<AddedPitchChange>();
public GameManager gameManager;
// Song beats per minute
// This is determined by the song you're trying to sync up to
public float songBpm;
@ -95,10 +96,10 @@ namespace HeavenStudio
public void SetTimelinePitch(float pitch)
{
if (isPaused) return;
if (isPaused || deferTimeKeeping) return;
if (pitch != 0 && pitch != timelinePitch)
{
Debug.Log("added pitch change " + pitch * minigamePitch + " at" + absTime);
Debug.Log("added pitch change " + pitch * minigamePitch + " at " + absTime);
addedPitchChanges.Add(new AddedPitchChange { time = absTime, pitch = pitch * minigamePitch });
}
@ -106,15 +107,19 @@ namespace HeavenStudio
if (musicSource != null && musicSource.clip != null)
{
musicSource.pitch = SongPitch;
time = MapTimeToPitchChanges(absTime + absTimeAdjust);
songPos = startPos + time;
songPosBeat = GetBeatFromSongPos(songPos);
SeekMusicToTime(songPos, firstBeatOffset);
}
}
public void SetMinigamePitch(float pitch)
{
if (isPaused || !isPlaying) return;
if (isPaused || deferTimeKeeping || !isPlaying) return;
if (pitch != 0 && pitch != minigamePitch)
{
Debug.Log("added pitch change " + pitch * timelinePitch + " at" + absTime);
Debug.Log("added pitch change " + pitch * timelinePitch + " at " + absTime);
addedPitchChanges.Add(new AddedPitchChange { time = absTime, pitch = pitch * timelinePitch });
}
@ -122,6 +127,10 @@ namespace HeavenStudio
if (musicSource != null && musicSource.clip != null)
{
musicSource.pitch = SongPitch;
time = MapTimeToPitchChanges(absTime + absTimeAdjust);
songPos = startPos + time;
songPosBeat = GetBeatFromSongPos(songPos);
SeekMusicToTime(songPos, firstBeatOffset);
}
}
@ -141,7 +150,7 @@ namespace HeavenStudio
public void SetBeat(double beat)
{
var chart = GameManager.instance.Beatmap;
var chart = gameManager.Beatmap;
double offset = chart.data.offset;
startPos = GetSongPosFromBeat(beat);
@ -154,7 +163,7 @@ namespace HeavenStudio
songPosBeat = GetBeatFromSongPos(time);
GameManager.instance.SetCurrentEventToClosest(beat);
gameManager.SetCurrentEventToClosest(beat);
}
public void PlaySetup(double beat)
@ -183,7 +192,7 @@ namespace HeavenStudio
SetMinigameVolume(1f);
}
RiqBeatmap chart = GameManager.instance.Beatmap;
RiqBeatmap chart = gameManager.Beatmap;
double offset = chart.data.offset;
double dspTime = AudioSettings.dspTime;
dspStart = dspTime;
@ -474,14 +483,14 @@ namespace HeavenStudio
private List<RiqEntity> GetSortedTempoChanges()
{
GameManager.instance.SortEventsList();
return GameManager.instance.Beatmap.TempoChanges;
gameManager.SortEventsList();
return gameManager.Beatmap.TempoChanges;
}
public float GetBpmAtBeat(double beat, out float swingRatio)
{
swingRatio = 0.5f;
var chart = GameManager.instance.Beatmap;
var chart = gameManager.Beatmap;
if (chart.TempoChanges.Count == 0)
return 120f;
float bpm = chart.TempoChanges[0]["tempo"];
@ -532,7 +541,7 @@ namespace HeavenStudio
public double GetSongPosFromBeat(double beat)
{
var chart = GameManager.instance.Beatmap;
var chart = gameManager.Beatmap;
float bpm = 120f;
double counter = 0f;
@ -572,7 +581,7 @@ namespace HeavenStudio
double counterSeconds = 0;
float lastBpm = 120f;
foreach (RiqEntity t in GameManager.instance.Beatmap.TempoChanges)
foreach (RiqEntity t in gameManager.Beatmap.TempoChanges)
{
double beatToNext = t.beat - lastTempoChangeBeat;
double secToNext = BeatsToSecs(beatToNext, lastBpm);

View file

@ -1,5 +1,6 @@
using System;
using System.Linq;
using BurstLinq;
using System.Collections.Generic;
using UnityEngine;
using Jukebox;

View file

@ -4,6 +4,7 @@ using UnityEngine;
using HeavenStudio.Util;
using System.Linq;
using BurstLinq;
using Jukebox;
using Jukebox.Legacy;

View file

@ -86,11 +86,13 @@ namespace HeavenStudio
GameObject Conductor = new GameObject();
Conductor.name = "Conductor";
AudioSource source = Conductor.AddComponent<AudioSource>();
Conductor.AddComponent<Conductor>();
Conductor.GetComponent<Conductor>().musicSource = source;
Conductor cond = Conductor.AddComponent<Conductor>();
cond.musicSource = source;
source.priority = 255;
source.outputAudioMixerGroup = Settings.GetMusicMixer();
// Conductor.AddComponent<AudioDspTimeKeeper>();
cond.gameManager = gameManager;
gameManager.conductor = cond;
GlobalGameManager.GameRenderTexture = gameRenderTexture;
GlobalGameManager.OverlayRenderTexture = overlayRenderTexture;

View file

@ -2,6 +2,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BurstLinq;
using UnityEngine;
using UnityEngine.Pool;
@ -87,6 +89,7 @@ namespace HeavenStudio
public static GameManager instance { get; private set; }
private EventCaller eventCaller;
public Conductor conductor;
// average input accuracy (msec)
List<int> inputOffsetSamples = new List<int>();
@ -173,9 +176,9 @@ namespace HeavenStudio
}
SortEventsList();
Conductor.instance.SetBpm(Beatmap.TempoChanges[0]["tempo"]);
Conductor.instance.SetVolume(Beatmap.VolumeChanges[0]["volume"]);
Conductor.instance.firstBeatOffset = Beatmap.data.offset;
conductor.SetBpm(Beatmap.TempoChanges[0]["tempo"]);
conductor.SetVolume(Beatmap.VolumeChanges[0]["volume"]);
conductor.firstBeatOffset = Beatmap.data.offset;
if (!preLoaded)
{
@ -240,7 +243,7 @@ namespace HeavenStudio
Beatmap.AddNewTempoChange(0, 120f);
Beatmap.AddNewVolumeChange(0, 100f);
Beatmap.data.offset = 0f;
Conductor.instance.musicSource.clip = null;
conductor.musicSource.clip = null;
RiqFileHandler.WriteRiq(Beatmap);
AudioLoadDone = true;
}
@ -263,7 +266,7 @@ namespace HeavenStudio
catch (System.IO.FileNotFoundException f)
{
Debug.LogWarning("chart has no music: " + f.Message);
Conductor.instance.musicSource.clip = null;
conductor.musicSource.clip = null;
AudioLoadDone = true;
yield break;
}
@ -277,7 +280,7 @@ namespace HeavenStudio
}
yield return current;
}
Conductor.instance.musicSource.clip = RiqFileHandler.StreamedAudioClip;
conductor.musicSource.clip = RiqFileHandler.StreamedAudioClip;
AudioLoadDone = true;
}
@ -299,9 +302,9 @@ namespace HeavenStudio
if (!editor)
StartCoroutine(LoadMusic());
SortEventsList();
Conductor.instance.SetBpm(Beatmap.TempoChanges[0]["tempo"]);
Conductor.instance.SetVolume(Beatmap.VolumeChanges[0]["volume"]);
Conductor.instance.firstBeatOffset = Beatmap.data.offset;
conductor.SetBpm(Beatmap.TempoChanges[0]["tempo"]);
conductor.SetVolume(Beatmap.VolumeChanges[0]["volume"]);
conductor.firstBeatOffset = Beatmap.data.offset;
if (!playMode)
{
Stop(0);
@ -459,9 +462,9 @@ namespace HeavenStudio
{
if (BeatmapEntities() < 1)
return;
if (!Conductor.instance.isPlaying)
if (!conductor.isPlaying)
return;
Conductor cond = Conductor.instance;
Conductor cond = conductor;
double clampedBeat = Math.Max(cond.songPositionInBeatsAsDouble, 0);
if (currentTempoEvent < Beatmap.TempoChanges.Count && currentTempoEvent >= 0)
@ -543,7 +546,7 @@ namespace HeavenStudio
List<RiqEntity> entitiesInRange = ListPool<RiqEntity>.Get();
List<RiqEntity> fxEntities = ListPool<RiqEntity>.Get();
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
while (currentEvent < eventBeats.Count && clampedBeat >= eventBeats[currentEvent] && Conductor.instance.isPlaying)
while (currentEvent < eventBeats.Count && clampedBeat >= eventBeats[currentEvent] && conductor.isPlaying)
{
fxEntities.Clear();
entitiesInRange.Clear();
@ -609,10 +612,10 @@ namespace HeavenStudio
{
OverlaysManager.instance.TogleOverlaysVisibility(Editor.Editor.instance == null || Editor.Editor.instance.fullscreen || ((PersistentDataManager.gameSettings.overlaysInEditor) && (!Editor.Editor.instance.fullscreen)) || HeavenStudio.Editor.GameSettings.InPreview);
if (!Conductor.instance.isPlaying)
if (!conductor.isPlaying)
return;
if (Conductor.instance.songPositionInBeatsAsDouble >= Math.Ceiling(_playStartBeat) + _latePulseTally)
if (conductor.songPositionInBeatsAsDouble >= Math.Ceiling(_playStartBeat) + _latePulseTally)
{
if (minigame != null) minigame.OnLateBeatPulse(Math.Ceiling(_playStartBeat) + _latePulseTally);
onBeatPulse?.Invoke(Math.Ceiling(_playStartBeat) + _latePulseTally);
@ -668,7 +671,7 @@ namespace HeavenStudio
public void Play(double beat, float delay = 0f)
{
bool paused = Conductor.instance.isPaused;
bool paused = conductor.isPaused;
Debug.Log("Playing at " + beat);
_playStartBeat = beat;
_pulseTally = 0;
@ -711,13 +714,13 @@ namespace HeavenStudio
private IEnumerator PlayCo(double beat, float delay = 0f)
{
bool paused = Conductor.instance.isPaused;
bool paused = conductor.isPaused;
if (!paused)
{
Conductor.instance.SetBpm(Beatmap.TempoChanges[0]["tempo"]);
Conductor.instance.SetVolume(Beatmap.VolumeChanges[0]["volume"]);
Conductor.instance.firstBeatOffset = Beatmap.data.offset;
conductor.SetBpm(Beatmap.TempoChanges[0]["tempo"]);
conductor.SetVolume(Beatmap.VolumeChanges[0]["volume"]);
conductor.firstBeatOffset = Beatmap.data.offset;
SetCurrentEventToClosest(beat);
KillAllSounds();
@ -726,7 +729,7 @@ namespace HeavenStudio
yield return new WaitForSeconds(delay);
}
Conductor.instance.PlaySetup(beat);
conductor.PlaySetup(beat);
Minigame miniGame = null;
if (minigameObj != null && minigameObj.TryGetComponent<Minigame>(out miniGame))
{
@ -765,21 +768,21 @@ namespace HeavenStudio
CircleCursor.LockCursor(true);
}
Application.backgroundLoadingPriority = ThreadPriority.Low;
Conductor.instance.Play(beat);
conductor.Play(beat);
}
public void Pause()
{
Conductor.instance.Pause();
conductor.Pause();
Util.SoundByte.PauseOneShots();
onPause?.Invoke(Conductor.instance.songPositionInBeatsAsDouble);
onPause?.Invoke(conductor.songPositionInBeatsAsDouble);
canInput = false;
}
public void Stop(double beat, bool restart = false, float restartDelay = 0f)
{
// I feel like I should standardize the names
if (Conductor.instance.isPlaying)
if (conductor.isPlaying)
{
SkillStarManager.instance.KillStar();
TimingAccuracyDisplay.instance.StopStarFlash();
@ -796,7 +799,7 @@ namespace HeavenStudio
}
}
Conductor.instance.Stop(beat);
conductor.Stop(beat);
SetCurrentEventToClosest(beat);
KillAllSounds();
@ -1023,12 +1026,12 @@ namespace HeavenStudio
if (allEnds.Count > 0)
endBeat = allEnds.Select(c => c.beat).Min();
else
endBeat = Conductor.instance.SongLengthInBeatsAsDouble();
endBeat = conductor.SongLengthInBeatsAsDouble();
}
else
{
SetGame("noGame");
endBeat = Conductor.instance.SongLengthInBeatsAsDouble();
endBeat = conductor.SongLengthInBeatsAsDouble();
}
if (Beatmap.TempoChanges.Count > 0)
@ -1112,9 +1115,9 @@ namespace HeavenStudio
}
}
while (beat + 0.25 > Math.Max(Conductor.instance.songPositionInBeatsAsDouble, 0))
while (beat + 0.25 > Math.Max(conductor.songPositionInBeatsAsDouble, 0))
{
if (!Conductor.instance.isPlaying)
if (!conductor.isPlaying)
{
HeavenStudio.StaticCamera.instance.ToggleCanvasVisibility(true);
SetAmbientGlowToCurrentMinigameColor();
@ -1141,7 +1144,7 @@ namespace HeavenStudio
this.minigame = minigame;
minigame.minigameName = game;
minigame.gameManager = this;
minigame.conductor = Conductor.instance;
minigame.conductor = conductor;
}
Vector3 originalScale = minigameObj.transform.localScale;
minigameObj.transform.parent = eventCaller.GamesHolder.transform;
@ -1300,8 +1303,8 @@ namespace HeavenStudio
private bool SongPosLessThanClipLength(float t)
{
if (Conductor.instance.musicSource.clip != null)
return Conductor.instance.GetSongPosFromBeat(t) < Conductor.instance.musicSource.clip.length;
if (conductor.musicSource.clip != null)
return conductor.GetSongPosFromBeat(t) < conductor.musicSource.clip.length;
else
return true;
}

View file

@ -7,6 +7,7 @@ using HeavenStudio.Common;
using HeavenStudio.InputSystem;
using System;
using System.Linq;
using BurstLinq;
using Jukebox;
namespace HeavenStudio.Games

View file

@ -1,7 +1,4 @@
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using HeavenStudio.InputSystem;

View file

@ -15,6 +15,7 @@ using HeavenStudio.StudioDance;
using Jukebox;
using UnityEditor;
using System.Linq;
using BurstLinq;
namespace HeavenStudio.Editor
{

View file

@ -9,6 +9,7 @@ using TMPro;
using Jukebox;
using Newtonsoft.Json;
using System.Linq;
using BurstLinq;
using HeavenStudio.Util;

View file

@ -5,6 +5,7 @@ using UnityEngine.Pool;
using Jukebox;
using System.Linq;
using BurstLinq;
namespace HeavenStudio.Editor.Track
{

View file

@ -16,6 +16,7 @@ using SatorImaging.UnitySourceGenerator;
using System;
using System.IO;
using System.Linq;
using BurstLinq;
using UnityEngine.Assertions.Must;
using Newtonsoft.Json.Linq;

View file

@ -8,6 +8,7 @@ using HeavenStudio.Common;
using HeavenStudio.InputSystem;
using System.Linq;
using BurstLinq;
using SFB;
using Jukebox;

View file

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BurstLinq;
using UnityEngine;
using Cysharp.Threading.Tasks;

View file

@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BurstLinq;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using UnityEngine;

View file

@ -1,5 +1,6 @@
{
"dependencies": {
"com.annulusgames.burst-linq": "https://github.com/AnnulusGames/BurstLinq.git?path=/Assets/BurstLinq",
"com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git",
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
"com.nobi.roundedcorners": "https://github.com/kirevdokimov/Unity-UI-Rounded-Corners.git",
@ -10,7 +11,8 @@
"com.tayx.graphy": "https://github.com/Tayx94/graphy.git",
"com.unity.2d.sprite": "1.0.0",
"com.unity.assetbundlebrowser": "https://github.com/Unity-Technologies/AssetBundles-Browser.git",
"com.unity.collab-proxy": "2.0.1",
"com.unity.burst": "1.6.6",
"com.unity.collections": "1.2.4",
"com.unity.ide.rider": "3.0.18",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.nuget.newtonsoft-json": "3.0.2",

View file

@ -1,5 +1,12 @@
{
"dependencies": {
"com.annulusgames.burst-linq": {
"version": "https://github.com/AnnulusGames/BurstLinq.git?path=/Assets/BurstLinq",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "fc354905c8e40b1491ea8a750ee722ee07adf484"
},
"com.coffee.softmask-for-ugui": {
"version": "https://github.com/mob-sakai/SoftMaskForUGUI.git",
"depth": 0,
@ -74,11 +81,23 @@
"dependencies": {},
"hash": "b7c279278d1a343c6957c9f15b45173d3211f01c"
},
"com.unity.collab-proxy": {
"version": "2.0.1",
"com.unity.burst": {
"version": "1.6.6",
"depth": 0,
"source": "registry",
"dependencies": {},
"dependencies": {
"com.unity.mathematics": "1.2.1"
},
"url": "https://packages.unity.com"
},
"com.unity.collections": {
"version": "1.2.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.6.6",
"com.unity.test-framework": "1.1.31"
},
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
@ -106,6 +125,13 @@
},
"url": "https://packages.unity.com"
},
"com.unity.mathematics": {
"version": "1.2.6",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.2.1",
"depth": 1,

View file

@ -0,0 +1,17 @@
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"UsePlatformSDKLinker": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX32": 6,
"CpuTargetsX64": 72,
"OptimizeFor": 0
}
}

View file

@ -0,0 +1,6 @@
{
"MonoBehaviour": {
"Version": 4,
"DisabledWarnings": ""
}
}

View file

@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.0.9
bundleVersion: 1.0.10
preloadedAssets:
- {fileID: 102900000, guid: 5348c08b82446e0478cee8bda6c02cfc, type: 3}
metroInputSource: 0
@ -158,11 +158,11 @@ PlayerSettings:
applicationIdentifier:
Standalone: com.RHeavenStudio.Heaven-Studio
buildNumber:
Standalone: 100009
Standalone: 100010
iPhone: 0
tvOS: 0
overrideDefaultApplicationIdentifier: 0
AndroidBundleVersionCode: 100009
AndroidBundleVersionCode: 100010
AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1

View file

@ -16,6 +16,31 @@ MonoBehaviour:
AutoEmitDisabledPaths: []
DenseViewWidthThreshold: 512
_disableAutoReloadInBackground: 0
ImportedScriptPaths: []
ImportedScriptPaths:
- Assets/Scripts/Games/GleeClub/GleeClub.cs
- Assets/Scripts/Minigames.cs
- Assets/Scripts/LevelEditor/Editor.cs
- Assets/Scripts/Games/FreezeFrame/Car.cs
- Assets/Scripts/Games/Fillbots/Fillbots.cs
- Assets/Scripts/Games/Fillbots/FullBody.cs
- Assets/Scripts/Games/CatchOfTheDay/CatchOfTheDay.cs
- Assets/Scripts/Util/ParticleSystemHelpers.cs
- Assets/Scripts/Games/Fillbots/NtrFillbot.cs
- Assets/Scripts/USG.g/LoadMinigames.Minigames.MinigameLoaderGenerator.g.cs
- Assets/Scripts/Games/FreezeFrame/FreezeFrame.cs
- Assets/Scripts/Games/CatchOfTheDay/LakeScene.cs
- Assets/Scripts/Conductor.cs
- Assets/Scripts/GameManager.cs
- Assets/Scripts/LevelEditor/Timeline/TimelineBlockManager.cs
- Assets/Scripts/TitleManager.cs
- Assets/Scripts/Util/MultiSound.cs
- Assets/Scripts/LevelEditor/Timeline/Timeline.cs
- Assets/Scripts/EventCaller.cs
- Assets/Scripts/Games/Minigame.cs
- Assets/Scripts/InputSystem/PlayerInput.cs
- Assets/Scripts/GameCamera.cs
- Assets/Scripts/Util/SoundByte.cs
- Assets/Scripts/GameInitializer.cs
- Assets/Scripts/AppInfo.cs
PathsToSkipImportEvent: []
PathsToIgnoreOverwriteSettingOnAttribute: []