From 3b763d00fd2e9f1523550ea871df211ee8e7bcee Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Fri, 5 Feb 2010 13:05:03 +1300 Subject: [PATCH] allow optional mixes again; fix openal so it can *tell* when it fails to allocate sources, rather than just copying 400 bytes of ununitialized garbage into our managed space --- OpenRa.FileFormats/Session.cs | 2 +- OpenRa.Game/Game.cs | 9 +++++++-- OpenRa.Game/Sound.cs | 18 ++++++++++-------- OpenRa.Game/Support/OpenAlInterop.cs | 8 +++++++- mods/ra/mod.yaml | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/OpenRa.FileFormats/Session.cs b/OpenRa.FileFormats/Session.cs index 1bf07f5417..1df5d7dc7c 100644 --- a/OpenRa.FileFormats/Session.cs +++ b/OpenRa.FileFormats/Session.cs @@ -31,7 +31,7 @@ namespace OpenRa.FileFormats { public string Map = "scm12ea.ini"; public string[] Packages = {}; // filename:sha1 pairs. - public string[] Mods = { "cnc" }; // mod names + public string[] Mods = { "ra" }; // mod names public int OrderLatency = 3; } } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 1a4b6d4b8a..0493ed03cf 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -44,8 +44,13 @@ namespace OpenRa FileSystem.MountTemporary(new Folder(dir)); foreach (var pkg in manifest.Packages) - FileSystem.MountTemporary(new Package(pkg)); - Timer.Time("mount tempory packages: {0}"); + if (pkg.StartsWith( "~")) // this package is optional. + try { FileSystem.MountTemporary(new Package(pkg.Substring(1))); } + catch { } + else + FileSystem.MountTemporary(new Package(pkg)); + + Timer.Time("mount temporary packages: {0}"); } public static void ChangeMap(string mapName) diff --git a/OpenRa.Game/Sound.cs b/OpenRa.Game/Sound.cs index 17a0a2abc4..c5ee0417bc 100644 --- a/OpenRa.Game/Sound.cs +++ b/OpenRa.Game/Sound.cs @@ -136,7 +136,7 @@ namespace OpenRa { float volume = 1f; Dictionary sourcePool = new Dictionary(); - const int POOL_SIZE = 100; + const int POOL_SIZE = 32; public OpenAlSoundEngine() { @@ -145,16 +145,18 @@ namespace OpenRa if (dev == IntPtr.Zero) throw new InvalidOperationException("Can't create OpenAL device"); var ctx = OpenAlInterop.alcCreateContext(dev, IntPtr.Zero); + if (ctx == IntPtr.Zero) + throw new InvalidOperationException("Can't create OpenAL context"); OpenAlInterop.alcMakeContextCurrent(ctx); - int[] sources = new int[POOL_SIZE]; - IntPtr pTemp = Marshal.AllocHGlobal(sizeof(int) * POOL_SIZE); - OpenAlInterop.alGenSources(POOL_SIZE, pTemp); - Marshal.Copy(pTemp, sources, 0, POOL_SIZE); - Marshal.FreeHGlobal(pTemp); - - foreach (int source in sources) + for (var i = 0; i < POOL_SIZE; i++) + { + var source = 0; + OpenAlInterop.alGenSources(1, out source); + if (0 != OpenAlInterop.alGetError()) + throw new InvalidOperationException("failed generating source {0}".F(i)); sourcePool.Add(source, false); + } } int GetSourceFromPool() diff --git a/OpenRa.Game/Support/OpenAlInterop.cs b/OpenRa.Game/Support/OpenAlInterop.cs index 85336d5e00..8edaabe5e1 100644 --- a/OpenRa.Game/Support/OpenAlInterop.cs +++ b/OpenRa.Game/Support/OpenAlInterop.cs @@ -51,8 +51,14 @@ namespace OpenRa.Support [DllImport("OpenAL32.dll")] public static extern void alBufferData(int buffer, int format, byte[] data, int size, int freq); + //[DllImport("OpenAL32.dll")] + //public static extern void alGenSources(int n, IntPtr sources); + [DllImport("OpenAL32.dll")] - public static extern void alGenSources(int n, IntPtr sources); + public static extern void alGenSources(int one, out int source); + + [DllImport("OpenAL32.dll")] + public static extern int alGetError(); [DllImport("OpenAL32.dll")] public static extern void alSourcef(int source, int param, float value); diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 96eead4ce1..9dd53097dd 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -4,7 +4,7 @@ Folders: ./ Packages: - main.mix + ~main.mix redalert.mix conquer.mix hires.mix