From e0344e1d5432db4a40eed2d63f1e77985ed5421b Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Wed, 8 Apr 2009 22:36:37 +0000 Subject: [PATCH] Wormholes: * Enable by default in GNUmakefile * Adjust price to something more plausible * Fix discrepancy in save-files between loading & saving SDL Sound: * Commit in sound patch when no sound-card available (was committed into 1.72 ages ago) git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2124 127b21dd-08f5-0310-b4b7-95ae10353056 --- GNUmakefile | 3 +- Resources/Config/equipment.plist | 4 +- src/Core/Entities/WormholeEntity.m | 4 +- src/SDL/OOSDLSound.h | 2 + src/SDL/OOSDLSound.m | 15 +- src/SDL/SDLMusic.m | 461 +++++++++++++++-------------- 6 files changed, 251 insertions(+), 238 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 7e2f49ac..a8818977 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -3,7 +3,7 @@ CP = cp BUILD_WITH_DEBUG_FUNCTIONALITY = yes DOCKING_CLEARANCE = yes PROCEDURAL_PLANETS = yes -WORMHOLE_SCANNER = no +WORMHOLE_SCANNER = yes vpath %.m src/SDL:src/Core:src/Core/Entities:src/Core/Materials:src/Core/Scripting:src/Core/OXPVerifier:src/Core/Debug vpath %.h src/SDL:src/Core:src/Core/Entities:src/Core/Materials:src/Core/Scripting:src/Core/OXPVerifier:src/Core/Debug vpath %.c src/SDL:src/Core:src/BSDCompat:src/Core/Debug @@ -51,7 +51,6 @@ ifeq ($(WORMHOLE_SCANNER),yes) ADDITIONAL_OBJCFLAGS += -DWORMHOLE_SCANNER endif - OBJC_PROGRAM_NAME = oolite oolite_C_FILES = \ diff --git a/Resources/Config/equipment.plist b/Resources/Config/equipment.plist index e3e04e77..a551cd4a 100644 --- a/Resources/Config/equipment.plist +++ b/Resources/Config/equipment.plist @@ -328,10 +328,10 @@ 9 - 4950 + 13950 Wormhole Scanner EQ_WORMHOLE_SCANNER - The Mynerium-Krantz Works wormhole scanner integrates into your existing targetting system. It analyzes the residual energy of a wormhole and, in combination with your Galactic Map software, calculates the most likely target system. + The Mössbauer-Krantz Works wormhole scanner integrates into your existing targetting system. It analyzes the residual energy of a wormhole and, in combination with your Galactic Map software, calculates the most likely target system. available_to_all diff --git a/src/Core/Entities/WormholeEntity.m b/src/Core/Entities/WormholeEntity.m index 395ae83d..42fcde27 100644 --- a/src/Core/Entities/WormholeEntity.m +++ b/src/Core/Entities/WormholeEntity.m @@ -3,7 +3,7 @@ WormholeEntity.m Oolite -Copyright (C) 2004-2008 Giles C Williams and contributors +Copyright (C) 2004-2009 Giles C Williams and contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -511,7 +511,7 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s [shipArray addObject:myShipDict]; */ [shipArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithDouble:[currShipDict doubleForKey:@"time"]], @"arrival_time", + [NSNumber numberWithDouble:[currShipDict doubleForKey:@"time"]], @"time_delta", [[currShipDict objectForKey:@"ship"] shipInfoDictionary], @"ship", nil]]; } diff --git a/src/SDL/OOSDLSound.h b/src/SDL/OOSDLSound.h index fb1d3e5c..f6ec33b5 100644 --- a/src/SDL/OOSDLSound.h +++ b/src/SDL/OOSDLSound.h @@ -61,4 +61,6 @@ SOFTWARE. - (NSString *)name; ++ (BOOL) isSoundOK; + @end diff --git a/src/SDL/OOSDLSound.m b/src/SDL/OOSDLSound.m index 6af716fa..ce39b2eb 100644 --- a/src/SDL/OOSDLSound.m +++ b/src/SDL/OOSDLSound.m @@ -89,7 +89,8 @@ static int sEffectiveMasterVolume = MIX_MAX_VOLUME; + (void) setMasterVolume:(float) fraction { - if (!sIsSetUp) [self setUp]; + if (!sIsSetUp && ![self setUp]) + return; fraction = OOClamp_0_1_f(fraction); int volume = (float)MIX_MAX_VOLUME * fraction; @@ -108,7 +109,8 @@ static int sEffectiveMasterVolume = MIX_MAX_VOLUME; + (float) masterVolume { - if (!sIsSetUp) [self setUp]; + if (!sIsSetUp && ![self setUp] ) + return 0; return (float)sEffectiveMasterVolume / (float)MIX_MAX_VOLUME; } @@ -139,7 +141,14 @@ static int sEffectiveMasterVolume = MIX_MAX_VOLUME; + (void) update { - [[OOSoundMixer sharedMixer] update]; + OOSoundMixer * mixer = [OOSoundMixer sharedMixer]; + if( sIsSoundOK && mixer) + [mixer update]; +} + ++ (BOOL) isSoundOK +{ + return sIsSoundOK; } @end diff --git a/src/SDL/SDLMusic.m b/src/SDL/SDLMusic.m index e3138312..3e1153a1 100644 --- a/src/SDL/SDLMusic.m +++ b/src/SDL/SDLMusic.m @@ -1,233 +1,236 @@ -/* - -SDLSound.h - -SDLSound - SDL sound implementation for Oolite. -Copyright (C) 2005 David Taylor - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -MA 02110-1301, USA. - -*/ - -#include "SDLMusic.h" -#import "OOLogging.h" - -#define kOOLogUnconvertedNSLog @"unclassified.SDLMusic" - -/* - * This is used by instances of OOMusic to check if they are currently playing - * or not. - * - * Because SDL_mixer only plays one piece of music at a time (which is - * reasonable), the SDL implementation of OOMusic works on the basis that - * only one instance of it is "current" at any given time. - * - * If an instance is not the current instance, the only method that will - * work is play. Calling play on an instance that is not the current - * instance will make it the current instance, stopping any music that is - * already playing. - */ -OOMusic* current; - -/* - * This function is called by SDL_mixer whenever a piece of music finishes - * playing. - * - * This resets the pointer the currently playing OOMusic object to signify - * that no music is playing. - */ -void musicFinished() -{ - current = nil; -} - - -@interface OOMusic (Private) - -- (BOOL) playWithCount:(int)count; - -@end - - -@implementation OOMusic - -/* - * Initialise an OOMusic instance from the given file. - * - * The OOMusic instance is deallocated and nil is returned if the contents - * of the file cannot be loaded by SDL_mixer. - */ -- (id) initWithContentsOfFile:(NSString*) filepath -{ - [super init]; - - music = Mix_LoadMUS([filepath cString]); - if (!music) - { - NSLog(@"Mix_LoadMUS(\"%@\"): %s\n", filepath, Mix_GetError()); - [super dealloc]; - return nil; - } - - name = [[filepath lastPathComponent] copy]; - - return self; -} - -/* - * Deallocate resources used by this instance of OOMusic. - */ -- (void) dealloc -{ - if (current == self) - Mix_HaltMusic(); - - if (music) - Mix_FreeMusic(music); - - [name autorelease]; - - [super dealloc]; -} - -- (void) pause -{ - // Only pause the music if this instance is the one being played. - if (current == self) - { - Mix_PauseMusic(); - paused=YES; - } -} - -- (BOOL) isPaused -{ - return paused; -} - -/* - * Returns YES is this instance of OOMusic is currently playing. - */ -- (BOOL) isPlaying -{ - // If the "current OOMusic instance" pointer points to self, then this - // instance is playing. - if (current == self) - return YES; - - return NO; -} - -- (BOOL) playWithCount:(int)count -{ - int rc; - paused=NO; - - // Self is already playing, so do nothing. - if (current == self) - return YES; - - // Another instance is playing so stop it. - if (current != 0) - [current stop]; - - // There is a potential race condition here because the - // SDL_mixer "music stopped" callback sets current to NULL, and this - // method sets current to self. - // - // If the callback is executed from a thread created by SDL_mixer then - // that might not happen before the thread executing this code has - // already made self current. - // - // One way of avoiding this is to wait for current to be equal to - // NULL. When that happens we know the callback has been called. - while (current != 0) - ; - - rc = Mix_PlayMusic(music, count); - if (rc < 0) - { - NSLog(@"Mix_PlayMusic error: %s", Mix_GetError()); - return NO; - } - - // This is done on every call to play simply because there didn't seem to - // be another way to do it without having either a class init method or - // doing it outside this class altogether. Both of those solutions seems - // messy and this should not have a big performance hit. - Mix_HookMusicFinished(musicFinished); - current = self; - - return YES; -} - -/* - * Play the music represented by this OOMusic instance. This will replace any - * music currently playing. - * - * If this instance is already playing, there is no effect. - * - * Returns YES for success, or NO if there was a problem playing the music. +/* + +SDLSound.h + +SDLSound - SDL sound implementation for Oolite. +Copyright (C) 2005 David Taylor + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. + +*/ + +#include "SDLMusic.h" +#import "OOLogging.h" +#include "OOSDLSound.h" + +#define kOOLogUnconvertedNSLog @"unclassified.SDLMusic" + +/* + * This is used by instances of OOMusic to check if they are currently playing + * or not. + * + * Because SDL_mixer only plays one piece of music at a time (which is + * reasonable), the SDL implementation of OOMusic works on the basis that + * only one instance of it is "current" at any given time. + * + * If an instance is not the current instance, the only method that will + * work is play. Calling play on an instance that is not the current + * instance will make it the current instance, stopping any music that is + * already playing. + */ +OOMusic* current; + +/* + * This function is called by SDL_mixer whenever a piece of music finishes + * playing. + * + * This resets the pointer the currently playing OOMusic object to signify + * that no music is playing. + */ +void musicFinished() +{ + current = nil; +} + + +@interface OOMusic (Private) + +- (BOOL) playWithCount:(int)count; + +@end + + +@implementation OOMusic + +/* + * Initialise an OOMusic instance from the given file. + * + * The OOMusic instance is deallocated and nil is returned if the contents + * of the file cannot be loaded by SDL_mixer. + */ +- (id) initWithContentsOfFile:(NSString*) filepath +{ + if( ![OOSound isSoundOK] ) return nil; + + [super init]; + + music = Mix_LoadMUS([filepath cString]); + if (!music) + { + NSLog(@"Mix_LoadMUS(\"%@\"): %s\n", filepath, Mix_GetError()); + [super dealloc]; + return nil; + } + + name = [[filepath lastPathComponent] copy]; + + return self; +} + +/* + * Deallocate resources used by this instance of OOMusic. + */ +- (void) dealloc +{ + if (current == self) + Mix_HaltMusic(); + + if (music) + Mix_FreeMusic(music); + + [name autorelease]; + + [super dealloc]; +} + +- (void) pause +{ + // Only pause the music if this instance is the one being played. + if (current == self) + { + Mix_PauseMusic(); + paused=YES; + } +} + +- (BOOL) isPaused +{ + return paused; +} + +/* + * Returns YES is this instance of OOMusic is currently playing. + */ +- (BOOL) isPlaying +{ + // If the "current OOMusic instance" pointer points to self, then this + // instance is playing. + if (current == self) + return YES; + + return NO; +} + +- (BOOL) playWithCount:(int)count +{ + int rc; + paused=NO; + + // Self is already playing, so do nothing. + if (current == self) + return YES; + + // Another instance is playing so stop it. + if (current != 0) + [current stop]; + + // There is a potential race condition here because the + // SDL_mixer "music stopped" callback sets current to NULL, and this + // method sets current to self. + // + // If the callback is executed from a thread created by SDL_mixer then + // that might not happen before the thread executing this code has + // already made self current. + // + // One way of avoiding this is to wait for current to be equal to + // NULL. When that happens we know the callback has been called. + while (current != 0) + ; + + rc = Mix_PlayMusic(music, count); + if (rc < 0) + { + NSLog(@"Mix_PlayMusic error: %s", Mix_GetError()); + return NO; + } + + // This is done on every call to play simply because there didn't seem to + // be another way to do it without having either a class init method or + // doing it outside this class altogether. Both of those solutions seems + // messy and this should not have a big performance hit. + Mix_HookMusicFinished(musicFinished); + current = self; + + return YES; +} + +/* + * Play the music represented by this OOMusic instance. This will replace any + * music currently playing. + * + * If this instance is already playing, there is no effect. + * + * Returns YES for success, or NO if there was a problem playing the music. */ - (void) playLooped:(BOOL)loop { [self playWithCount:loop ? -1 : 1]; -} - -/* - * Stop playing this piece of music. - * - * Returns YES if this music was being played, or NO if this music was not - * being played. - */ -- (void) stop -{ - // Only stop the music if this instance is the one being played. - if (current == self) - { - Mix_HaltMusic(); - // Flag that there is no tune currently playing - current = 0; - } -} - -- (void) resume -{ - // Only resume playing the music if this instance is the one being played. - if (current == self) - { - Mix_ResumeMusic(); - paused=NO; - } -} - -/* - * Go back to the beginning of the music. - */ -- (void) goToBeginning -{ - // Only rewind the music if this instance is the one being played. - if (current == self) - Mix_RewindMusic(); -} - - -- (NSString *) name -{ - return name; -} - -@end +} + +/* + * Stop playing this piece of music. + * + * Returns YES if this music was being played, or NO if this music was not + * being played. + */ +- (void) stop +{ + // Only stop the music if this instance is the one being played. + if (current == self) + { + Mix_HaltMusic(); + // Flag that there is no tune currently playing + current = 0; + } +} + +- (void) resume +{ + // Only resume playing the music if this instance is the one being played. + if (current == self) + { + Mix_ResumeMusic(); + paused=NO; + } +} + +/* + * Go back to the beginning of the music. + */ +- (void) goToBeginning +{ + // Only rewind the music if this instance is the one being played. + if (current == self) + Mix_RewindMusic(); +} + + +- (NSString *) name +{ + return name; +} + +@end