Merge pull request #10912 from pchote/soundloader-streams

Introduce ISoundFormat for parsing sound files.
This commit is contained in:
abcdefg30
2016-03-13 14:56:01 +01:00
7 changed files with 224 additions and 156 deletions

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System.IO;
using OpenRA.FileFormats;
using OpenRA.FileSystem;
@@ -35,19 +36,24 @@ namespace OpenRA.GameRules
Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext;
}
public void Load(IReadOnlyFileSystem filesystem)
public void Load(IReadOnlyFileSystem fileSystem)
{
if (!filesystem.Exists(Filename))
Stream stream;
if (!fileSystem.TryOpen(Filename, out stream))
return;
Exists = true;
using (var s = filesystem.Open(Filename))
ISoundFormat soundFormat;
foreach (var loader in Game.ModData.SoundLoaders)
{
if (Filename.ToLowerInvariant().EndsWith("wav"))
Length = (int)WavLoader.WaveLength(s);
else
Length = (int)AudLoader.SoundLength(s);
if (loader.TryParseSound(stream, out soundFormat))
{
Length = (int)soundFormat.LengthInSeconds;
break;
}
}
stream.Dispose();
}
}
}