optimize remix saving / loading

stream is now saved to a buffer so we don't have to convert every time we save, only once when loading a new audio file
- make a distinction between Load Remix and New Remix
This commit is contained in:
minenice55 2022-08-19 17:53:04 -04:00
parent 302bd6bbb5
commit 4aff0385ee
3 changed files with 40 additions and 18 deletions

View file

@ -19238,8 +19238,8 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1589389272}
m_HandleRect: {fileID: 1589389271}
m_Direction: 2
m_Value: 1
m_Size: 0.99952716
m_Value: 0
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -24820,7 +24820,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 0, y: 129.91016}
m_AnchoredPosition: {x: 0, y: 129.9111}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1154875944
@ -35580,9 +35580,9 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1423699437}
m_TargetAssemblyTypeName: RhythmHeavenMania.Editor.Editor, Assembly-CSharp
m_MethodName: LoadRemix
m_Mode: 5
m_TargetAssemblyTypeName: HeavenStudio.Editor.Editor, Assembly-CSharp
m_MethodName: NewRemix
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine

View file

@ -70,6 +70,8 @@ namespace HeavenStudio.Editor
public bool editingInputField = false;
public bool isCursorEnabled = true;
private byte[] MusicBytes;
public static Editor instance { get; private set; }
private void Start()
@ -158,7 +160,7 @@ namespace HeavenStudio.Editor
{
if (Input.GetKeyDown(KeyCode.N))
{
LoadRemix("");
NewRemix();
}
else if (Input.GetKeyDown(KeyCode.O))
{
@ -294,6 +296,22 @@ namespace HeavenStudio.Editor
}
}
try
{
if (clip != null)
MusicBytes = OggVorbis.VorbisPlugin.GetOggVorbis(Conductor.instance.musicSource.clip, 1);
else
{
MusicBytes = null;
Debug.LogWarning("Failed to load music file! The stream is currently empty.");
}
}
catch (System.Exception)
{
MusicBytes = null;
Debug.LogWarning("Failed to load music file! The stream is currently empty.");
}
return clip;
}
@ -343,15 +361,12 @@ namespace HeavenStudio.Editor
using (var zipStream = levelFile.Open())
zipStream.Write(Encoding.UTF8.GetBytes(GetJson()), 0, Encoding.UTF8.GetBytes(GetJson()).Length);
if (changedMusic || currentRemixPath != path)
if (MusicBytes != null)
{
// this gets rid of the music file for some reason, someone remind me to find a fix for this soon
}
byte[] bytes = OggVorbis.VorbisPlugin.GetOggVorbis(Conductor.instance.musicSource.clip, 1);
var musicFile = archive.CreateEntry("song.ogg", System.IO.Compression.CompressionLevel.NoCompression);
using (var zipStream = musicFile.Open())
zipStream.Write(bytes, 0, bytes.Length);
zipStream.Write(MusicBytes, 0, MusicBytes.Length);
}
}
currentRemixPath = path;
@ -359,6 +374,12 @@ namespace HeavenStudio.Editor
}
}
public void NewRemix()
{
MusicBytes = null;
LoadRemix("");
}
public void LoadRemix(string json = "")
{
GameManager.instance.LoadRemix(json);
@ -367,6 +388,8 @@ namespace HeavenStudio.Editor
Timeline.instance.VolumeInfo.UpdateStartingVolumeText();
Timeline.instance.TempoInfo.UpdateOffsetText();
Timeline.FitToSong();
currentRemixPath = string.Empty;
}
public void OpenRemix()
@ -408,12 +431,11 @@ namespace HeavenStudio.Editor
{
using (var stream = entry.Open())
{
byte[] bytes;
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
bytes = ms.ToArray();
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(bytes, "music");
MusicBytes = ms.ToArray();
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(MusicBytes, "music");
loadedMusic = true;
Timeline.FitToSong();
}

View file

@ -1,5 +1,5 @@
ManifestFileVersion: 0
CRC: 1477632056
CRC: 1516953164
AssetBundleManifest:
AssetBundleInfos:
Info_0: