From 11c639a866619fcf20544eaac96b78bacccff43e Mon Sep 17 00:00:00 2001 From: AnotherCommander Date: Sat, 5 Nov 2016 22:12:07 +0100 Subject: [PATCH] Implemented -nosound command line option. --- src/Core/Entities/PlayerEntity.m | 2 +- src/Core/OOALSound.m | 2 ++ src/Core/OOOpenALController.m | 10 ++++++++++ src/SDL/MyOpenGLView.m | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index d1f8e227..42365dfd 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -8494,7 +8494,7 @@ static NSString *SliderString(NSInteger amountIn20ths) [gui setKey:GUI_KEY_OK forRow:GUI_ROW(GAME,AUTOSAVE)]; // volume control - if ([OOSound respondsToSelector:@selector(masterVolume)]) + if ([OOSound respondsToSelector:@selector(masterVolume)] && [OOSound isSoundOK]) { double volume = 100.0 * [OOSound masterVolume]; int vol = (volume / 5.0 + 0.5); // avoid rounding errors diff --git a/src/Core/OOALSound.m b/src/Core/OOALSound.m index ca7bf9d8..f4a48d16 100644 --- a/src/Core/OOALSound.m +++ b/src/Core/OOALSound.m @@ -96,6 +96,8 @@ static BOOL sIsSoundOK = NO; - (id) initWithContentsOfFile:(NSString *)path { + if (!sIsSoundOK) return nil; + [self release]; if (!sIsSetUp && ![OOSound setUp]) return nil; diff --git a/src/Core/OOOpenALController.m b/src/Core/OOOpenALController.m index 82f2c3ee..b22f7e95 100644 --- a/src/Core/OOOpenALController.m +++ b/src/Core/OOOpenALController.m @@ -47,6 +47,16 @@ static id sSingleton = nil; self = [super init]; if (self != nil) { + NSArray *arguments = nil; + NSEnumerator *argEnum = nil; + NSString *arg = nil; + + arguments = [[NSProcessInfo processInfo] arguments]; + for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); ) + { + if ([arg isEqual:@"-nosound"] || [arg isEqual:@"--nosound"]) return nil; + } + ALuint error; device = alcOpenDevice(NULL); // default device if (!device) diff --git a/src/SDL/MyOpenGLView.m b/src/SDL/MyOpenGLView.m index dba11a44..5cc61215 100644 --- a/src/SDL/MyOpenGLView.m +++ b/src/SDL/MyOpenGLView.m @@ -195,6 +195,7 @@ MA 02110-1301, USA. // end TODO [OOSound setUp]; + if (![OOSound isSoundOK]) OOLog(@"sound.init", @"Sound system disabled."); // Generate the window caption, containing the version number and the date the executable was compiled. static char windowCaption[128];