Skip to content

Commit

Permalink
保留bass引用
Browse files Browse the repository at this point in the history
  • Loading branch information
rinkako committed Jun 12, 2017
1 parent ca87a61 commit f463291
Show file tree
Hide file tree
Showing 10 changed files with 1,414 additions and 101 deletions.
Binary file modified Lyyneheym/TestItems/SampleProject/NAudio.dll
Binary file not shown.
Binary file added Lyyneheym/YuriPlatform/Bass.Net.dll
Binary file not shown.
1,104 changes: 1,104 additions & 0 deletions Lyyneheym/YuriPlatform/PlatformCore/Audio/MusicianBass.cs

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions Lyyneheym/YuriPlatform/PlatformCore/Director.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,14 @@ public static void ResumeFromSaveData(RuntimeManager rm)
UpdateRender render = Director.GetInstance().updateRender;
render.VsmReference = Director.RunMana.CallStack;
// 恢复背景音乐
Musician.GetInstance().RePerform(Director.RunMana.Musics);
//render.Bgm(Director.RunMana.Musics.PlayingBGM, GlobalConfigContext.GAME_SOUND_BGMVOL);
if (GlobalConfigContext.UseBassEngine)
{
MusicianBass.GetInstance().RePerform(Director.RunMana.Musics);
}
else
{
Musician.GetInstance().RePerform(Director.RunMana.Musics);
}
// 清空字符串缓冲
render.dialogPreStr = String.Empty;
render.pendingDialogQueue.Clear();
Expand Down Expand Up @@ -870,14 +876,20 @@ public static void CollapseWorld()
PersistContextDAO.Assign("___YURIRI@ACCDURATION___", Director.LastGameTimeAcc + (collaTimeStamp - Director.StartupTimeStamp));
PersistContextDAO.SaveToSteadyMemory();
LogUtils.LogLine("Save persistence context OK", "Director", LogLevel.Important);
MusicianRouterHandler.TerminalFlag = true;
Musician.GetInstance().Dispose();
if (GlobalConfigContext.UseBassEngine == false)
{
MusicianRouterHandler.TerminalFlag = true;
Musician.GetInstance().Dispose();
}
LogUtils.LogLine("Dispose resource OK, program will shutdown soon", "Director", LogLevel.Important);
var ct = DateTime.Now;
GC.Collect();
while ((DateTime.Now - ct).TotalSeconds < 2 && !MusicianRouterHandler.IsCollapsed)
if (GlobalConfigContext.UseBassEngine == false)
{
System.Threading.Thread.Sleep(10);
while ((DateTime.Now - ct).TotalSeconds < 2 && !MusicianRouterHandler.IsCollapsed)
{
System.Threading.Thread.Sleep(10);
}
}
Environment.Exit(0);
}
Expand Down Expand Up @@ -912,7 +924,10 @@ private Director()
Director.RunMana.SetScreenManager(ScreenManager.GetInstance());
Director.RunMana.ParallelHandler = this.ParallelUpdateContext;
Director.RunMana.PerformingChapter = "Prelogue";
MusicianRouterHandler.Init();
if (GlobalConfigContext.UseBassEngine == false)
{
MusicianRouterHandler.Init();
}
//Net.HttpServerRouterHandler.Init();
this.timer = new DispatcherTimer
{
Expand Down
5 changes: 5 additions & 0 deletions Lyyneheym/YuriPlatform/PlatformCore/GlobalConfigContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ internal static class GlobalConfigContext
/// 持久性上下文文件名
/// </summary>
public static readonly string QSaveFileName = "QSave";

/// <summary>
/// DEBUG:音频引擎控制
/// </summary>
public static bool UseBassEngine = false;
#endregion

#region 枚举类型
Expand Down
102 changes: 102 additions & 0 deletions Lyyneheym/YuriPlatform/PlatformCore/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Yuri.PlatformCore.Graphic;
using Yuri.PlatformCore.VM;
using Yuri.Utils;
Expand Down Expand Up @@ -96,6 +97,46 @@ public MemoryStream GetVocal(string sourceName)
return this.GetMusicMemoryStream(sourceName, ResourceType.VOCAL);
}

/// <summary>
/// 获得一个指定BGM音频资源的内存数组
/// </summary>
/// <param name="sourceName">资源名称</param>
/// <returns>一个键值对:该音频的内存托管句柄 - 内存长度</returns>
public KeyValuePair<GCHandle?, long> GetBGMGCHandle(string sourceName)
{
return this.GetMusicGCHandleLengthKVP(sourceName, ResourceType.BGM);
}

/// <summary>
/// 获得一个指定BGS音频资源的内存数组
/// </summary>
/// <param name="sourceName">资源名称</param>
/// <returns>一个键值对:该音频的内存托管句柄 - 内存长度</returns>
public KeyValuePair<GCHandle?, long> GetBGSGCHandle(string sourceName)
{
return this.GetMusicGCHandleLengthKVP(sourceName, ResourceType.BGS);
}

/// <summary>
/// 获得一个指定SE音频资源的内存数组
/// </summary>
/// <param name="sourceName">资源名称</param>
/// <returns>一个键值对:该音频的内存托管句柄 - 内存长度</returns>
public KeyValuePair<GCHandle?, long> GetSEGCHandle(string sourceName)
{
return this.GetMusicGCHandleLengthKVP(sourceName, ResourceType.SE);
}

/// <summary>
/// 获得一个指定Vocal音频资源的内存数组
/// </summary>
/// <param name="sourceName">资源名称</param>
/// <returns>一个键值对:该音频的内存托管句柄 - 内存长度</returns>
public KeyValuePair<GCHandle?, long> GetVocalGCHandle(string sourceName)
{
return this.GetMusicGCHandleLengthKVP(sourceName, ResourceType.VOCAL);
}

/// <summary>
/// 获得指定名称的场景
/// </summary>
Expand Down Expand Up @@ -331,6 +372,67 @@ private MemoryStream GetMusicMemoryStream(string sourceName, ResourceType rtype)
}
}


/// <summary>
/// 从资源文件中获取声音资源并返回句柄
/// </summary>
/// <param name="sourceName">资源名称</param>
/// <param name="rtype">资源类型</param>
/// <returns>一个键值对:该音频的内存托管句柄 - 内存长度</returns>
private KeyValuePair<GCHandle?, long> GetMusicGCHandleLengthKVP(string sourceName, ResourceType rtype)
{
if (sourceName == String.Empty) { return new KeyValuePair<GCHandle?, long>(null, 0); }
string DevURI = null, PackURI = null;
// 处理路径
switch (rtype)
{
case ResourceType.BGM:
DevURI = GlobalConfigContext.DevURI_SO_BGM;
PackURI = GlobalConfigContext.PackURI_SO_BGM;
break;
case ResourceType.BGS:
DevURI = GlobalConfigContext.DevURI_SO_BGS;
PackURI = GlobalConfigContext.PackURI_SO_BGS;
break;
case ResourceType.SE:
DevURI = GlobalConfigContext.DevURI_SO_SE;
PackURI = GlobalConfigContext.PackURI_SO_SE;
break;
case ResourceType.VOCAL:
DevURI = GlobalConfigContext.DevURI_SO_VOCAL;
PackURI = GlobalConfigContext.PackURI_SO_VOCAL;
break;
default:
throw new Exception("调用了音乐获取方法,但却不是获取音乐资源");
}
// 总是先查看是否有为封包的数据
if (this.resourceTable.ContainsKey(DevURI) &&
this.resourceTable[DevURI].ContainsKey(sourceName))
{
var slot = this.resourceTable[DevURI][sourceName];
var sourceLocation = new KeyValuePair<long, long>(slot.Position, slot.Length);
GCHandle ptr = PackageUtils.GetObjectManagedHandle(IOUtils.ParseURItoURL(PackURI + GlobalConfigContext.PackPostfix),
sourceName, sourceLocation.Key, sourceLocation.Value);
return new KeyValuePair<GCHandle?, long>(ptr, sourceLocation.Value);
}
// 没有封包数据再搜索开发目录
else
{
string furi = IOUtils.JoinPath(GlobalConfigContext.DevURI_RT_SOUND, DevURI, sourceName);
if (File.Exists(IOUtils.ParseURItoURL(furi)))
{
byte[] bytes = File.ReadAllBytes(IOUtils.ParseURItoURL(furi));
return new KeyValuePair<GCHandle?, long>(GCHandle.Alloc(bytes, GCHandleType.Pinned), bytes.Length);
}
else
{
MessageBox.Show("[错误] 资源文件不存在:" + sourceName);
Director.GetInstance().GetMainRender().Shutdown();
throw new FileNotFoundException();
}
}
}

/// <summary>
/// 在根目录下搜索资源信息文件
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion Lyyneheym/YuriPlatform/PlatformCore/RollbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ public static void GotoSteadyState(RollbackableSnapshot ssp)
ViewManager.GetInstance().ReDraw();
// 恢复音效
UpdateRender render = Director.GetInstance().GetMainRender();
Musician.GetInstance().RePerform(Director.RunMana.Musics);
if (GlobalConfigContext.UseBassEngine)
{
MusicianBass.GetInstance().RePerform(Director.RunMana.Musics);
}
else
{
Musician.GetInstance().RePerform(Director.RunMana.Musics);
}
// 清空字符串缓冲
render.dialogPreStr = String.Empty;
render.pendingDialogQueue.Clear();
Expand Down
Loading

0 comments on commit f463291

Please sign in to comment.