Skip to content

Commit acfbea9

Browse files
committed
refactor(Audio): update logging for missing studio paths in NAudioManager patches
- Replaced debug logging with warning logging for missing studio paths to enhance clarity and severity of logged messages. - Streamlined the logging method to improve performance and reduce unnecessary checks for existing paths. - Updated the logging format to provide more detailed information about the audio event context and state.
1 parent 3f336be commit acfbea9

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

Audio/Patches/NAudioManagerGuidMappedStudioEventsPatches.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,33 @@ namespace STS2RitsuLib.Audio.Patches
1616
/// </summary>
1717
public static class NAudioManagerGuidMappedStudioEventsPatches
1818
{
19-
private static readonly Lock MissingStudioPathDebugGate = new();
20-
private static readonly HashSet<string> MissingStudioPathDebugLoggedKeys = new(StringComparer.Ordinal);
19+
private static readonly Lock MissingStudioPathWarningGate = new();
20+
private static readonly HashSet<string> MissingStudioPathWarningLoggedKeys = new(StringComparer.Ordinal);
21+
22+
private static void LogMissingStudioPathOnce(string operation, string path)
23+
{
24+
if (!path.StartsWith("event:/", StringComparison.Ordinal))
25+
return;
26+
27+
var pathExistsInRuntime = FmodStudioServer.TryCheckEventPath(path);
28+
if (pathExistsInRuntime != false)
29+
return;
30+
31+
var key = operation + "\0" + path;
32+
lock (MissingStudioPathWarningGate)
33+
{
34+
if (!MissingStudioPathWarningLoggedKeys.Add(key))
35+
return;
36+
}
37+
38+
RitsuLibFramework.Logger.Warn(
39+
$"[Audio] FMOD event was not found in GUID mappings or loaded Studio events. " +
40+
$"operation={operation}; " +
41+
$"path={path}; guidMapEventCount={FmodStudioGuidPathTable.EventMappingCount}; " +
42+
$"loadedBankCount={FmodStudioServer.TryGetLoadedBankCount()}; " +
43+
$"loadedEventDescriptionCount={FmodStudioServer.TryGetLoadedEventDescriptionCount()}; " +
44+
$"banksStillLoading={FmodStudioServer.TryBanksStillLoading()?.ToString() ?? "?"}");
45+
}
2146

2247
/// <summary>
2348
/// Intercepts mapped <see cref="NAudioManager.PlayOneShot(string, Dictionary{string, float}, float)" /> calls.
@@ -78,30 +103,6 @@ public static bool Prefix(NAudioManager __instance, string path, Dictionary<stri
78103
}
79104
}
80105

81-
private static void LogMissingStudioPathOnce(string operation, string path)
82-
{
83-
if (!path.StartsWith("event:/", StringComparison.Ordinal))
84-
return;
85-
86-
var pathExistsInRuntime = FmodStudioServer.TryCheckEventPath(path);
87-
if (pathExistsInRuntime != false)
88-
return;
89-
90-
var key = operation + "\0" + path;
91-
lock (MissingStudioPathDebugGate)
92-
{
93-
if (!MissingStudioPathDebugLoggedKeys.Add(key))
94-
return;
95-
}
96-
97-
RitsuLibFramework.Logger.Debug(
98-
$"[Audio] {operation} event path was not found in GUID mappings or loaded FMOD Studio paths. " +
99-
$"path={path}; guidMapEventCount={FmodStudioGuidPathTable.EventMappingCount}; " +
100-
$"loadedBankCount={FmodStudioServer.TryGetLoadedBankCount()}; " +
101-
$"loadedEventDescriptionCount={FmodStudioServer.TryGetLoadedEventDescriptionCount()}; " +
102-
$"banksStillLoading={FmodStudioServer.TryBanksStillLoading()?.ToString() ?? "?"}");
103-
}
104-
105106
/// <summary>
106107
/// Intercepts mapped <see cref="NAudioManager.PlayLoop(string, bool)" /> calls.
107108
/// 拦截已映射的 <see cref="NAudioManager.PlayLoop(string, bool)" /> 调用。

0 commit comments

Comments
 (0)