Changed sound code to use SDL

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@44 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
dajt 2005-05-04 11:12:07 +00:00
parent 7cb109935a
commit 1f39b147ef
11 changed files with 155 additions and 30 deletions

View File

@ -160,7 +160,7 @@ Your fair use and other rights are in no way affected by the above.
} }
else else
{ {
glEnable(GL_LINE_SMOOTH); //glEnable(GL_LINE_SMOOTH);
glLineWidth(line_size); glLineWidth(line_size);
glBegin(GL_LINES); glBegin(GL_LINES);
} }

View File

@ -1,14 +1,14 @@
include $(GNUSTEP_MAKEFILES)/common.make include $(GNUSTEP_MAKEFILES)/common.make
CP = cp CP = cp
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_USER_ROOT) GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_USER_ROOT)
ADDITIONAL_GUI_LIBS = -lGLU -lGL -lasound ADDITIONAL_GUI_LIBS = -lGLU -lGL -lasound -lSDL -lpthread -lSDL_mixer
ADDITIONAL_CFLAGS = -DLINUX ADDITIONAL_CFLAGS = -DLINUX -I/home/dtaylor/include/SDL -D_REENTRANT
ADDITIONAL_OBJCFLAGS = -DLINUX -DHAVE_SOUND -Wno-import ADDITIONAL_OBJCFLAGS = -DLINUX -DHAVE_SOUND -Wno-import -I/home/dtaylor/include/SDL -D_REENTRANT
APP_NAME = oolite APP_NAME = oolite
oolite_LIB_DIRS += -L/usr/X11R6/lib/ oolite_LIB_DIRS += -L/usr/X11R6/lib/
oolite_C_FILES = vector.c legacy_random.c oolite_C_FILES = vector.c legacy_random.c
oolite_OBJC_FILES = Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntity_Additions.m PlayerEntity_contracts.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntity_AI.m ShipEntity.m SkyEntity.m StationEntity.m TextureStore.m Universe.m OOSound.m oolite_OBJC_FILES = Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntity_Additions.m PlayerEntity_contracts.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntity_AI.m ShipEntity.m SkyEntity.m StationEntity.m TextureStore.m Universe.m OOSound.m OOMusic.m
include $(GNUSTEP_MAKEFILES)/application.make include $(GNUSTEP_MAKEFILES)/application.make
include GNUmakefile.postamble include GNUmakefile.postamble

View File

@ -342,6 +342,22 @@ static int _compareModes(id arg1, id arg2, void *context)
- (void) applicationDidFinishLaunching: (NSNotification*) notification - (void) applicationDidFinishLaunching: (NSNotification*) notification
{ {
#ifdef GNUSTEP
NSLog(@"initialising SDL");
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
NSLog(@"Unable to init SDL: %s\n", SDL_GetError());
}
else if (Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 2048) < 0)
{
NSLog(@"Mix_OpenAudio: %s\n", Mix_GetError());
}
Mix_AllocateChannels(16);
//Mix_ChannelFinished(channelDone);
//Mix_HookMusicFinished(musicFinished);
#endif
// //
// ensure the gameView is drawn to, so OpenGL is initialised and so textures can initialse. // ensure the gameView is drawn to, so OpenGL is initialised and so textures can initialse.
// //
@ -405,7 +421,7 @@ static int _compareModes(id arg1, id arg2, void *context)
// dajt: force the OpenGL context to be initialised again as X windows // dajt: force the OpenGL context to be initialised again as X windows
// should have caught up by now // should have caught up by now
// TODO: get rid of hardcoded window size // TODO: get rid of hardcoded window size
[gameView initialiseGLWithSize: NSMakeSize(640, 480)]; [gameView initialiseGLWithSize: NSMakeSize(DISPLAY_MIN_WIDTH, DISPLAY_MIN_HEIGHT)];
#endif #endif
[universe setGameView:gameView]; [universe setGameView:gameView];

11
OOMusic.h Normal file
View File

@ -0,0 +1,11 @@
// OOMusic.h: Selects the appropriate music class source file
// depending on the operating system defined.
//
// Add new OS imports here. The -DOS_NAME flag in the GNUmakefile
// will select which one gets compiled.
//
// David Taylor, 2005-05-04
#ifdef LINUX
#import "SDLMusic.h"
#endif

11
OOMusic.m Normal file
View File

@ -0,0 +1,11 @@
// OOMusic.m: Selects the appropriate music class source file
// depending on the operating system defined.
//
// Add new OS imports here. The -DOS_NAME flag in the GNUmakefile
// will select which one gets compiled.
//
// David Taylor, 2005-05-04
#ifdef LINUX
#import "SDLMusic.m"
#endif

View File

@ -41,6 +41,8 @@ Your fair use and other rights are in no way affected by the above.
#ifndef GNUSTEP #ifndef GNUSTEP
#import <QuickTime/Movies.h> #import <QuickTime/Movies.h>
#else
#include "OOMusic.h"
#endif #endif
#import "ShipEntity.h" #import "ShipEntity.h"
@ -274,10 +276,14 @@ Your fair use and other rights are in no way affected by the above.
BOOL ecm_in_operation; BOOL ecm_in_operation;
double ecm_start_time; double ecm_start_time;
#ifndef GNUSTEP #ifndef GNUSTEP
NSMovie* themeMusic; NSMovie* themeMusic;
NSMovie* missionMusic; NSMovie* missionMusic;
NSMovie* dockingMusic; NSMovie* dockingMusic;
#else
OOMusic* themeMusic;
OOMusic* missionMusic;
OOMusic* dockingMusic;
#endif #endif
NSSound* beepSound; NSSound* beepSound;

View File

@ -924,11 +924,9 @@ static BOOL galactic_witchjump;
if (afterburner1Sound) [afterburner1Sound release]; if (afterburner1Sound) [afterburner1Sound release];
if (afterburner2Sound) [afterburner2Sound release]; if (afterburner2Sound) [afterburner2Sound release];
// //
#ifndef GNUSTEP
if (themeMusic) [themeMusic release]; if (themeMusic) [themeMusic release];
if (missionMusic) [missionMusic release]; if (missionMusic) [missionMusic release];
if (dockingMusic) [dockingMusic release]; if (dockingMusic) [dockingMusic release];
#endif
// //
// allocate sounds // allocate sounds
// //
@ -956,11 +954,9 @@ static BOOL galactic_witchjump;
// [afterburner2Sound setDelegate:self]; // [afterburner2Sound setDelegate:self];
// //
#ifndef GNUSTEP themeMusic = [[ResourceManager movieFromFilesNamed:@"OoliteTheme.mp3" inFolder:@"Music"] retain];
themeMusic = [[ResourceManager movieFromFilesNamed:@"OoliteTheme.mp3" inFolder:@"Music"] retain]; missionMusic = [[ResourceManager movieFromFilesNamed:@"OoliteTheme.mp3" inFolder:@"Music"] retain];
missionMusic = [[ResourceManager movieFromFilesNamed:@"OoliteTheme.mp3" inFolder:@"Music"] retain]; dockingMusic = [[ResourceManager movieFromFilesNamed:@"BlueDanube.mp3" inFolder:@"Music"] retain];
dockingMusic = [[ResourceManager movieFromFilesNamed:@"BlueDanube.mp3" inFolder:@"Music"] retain];
#endif
// //
collision_radius = 50.0; collision_radius = 50.0;
// //
@ -1210,11 +1206,9 @@ static BOOL galactic_witchjump;
if (warningSound) [warningSound release]; if (warningSound) [warningSound release];
if (afterburner1Sound) [afterburner1Sound release]; if (afterburner1Sound) [afterburner1Sound release];
if (afterburner2Sound) [afterburner2Sound release]; if (afterburner2Sound) [afterburner2Sound release];
#ifndef GNUSTEP
if (themeMusic) [themeMusic release]; if (themeMusic) [themeMusic release];
if (missionMusic) [missionMusic release]; if (missionMusic) [missionMusic release];
if (dockingMusic) [dockingMusic release]; if (dockingMusic) [dockingMusic release];
#endif
if (missionBackgroundImage) [missionBackgroundImage release]; if (missionBackgroundImage) [missionBackgroundImage release];
if (player_name) [player_name release]; if (player_name) [player_name release];
@ -2695,6 +2689,10 @@ static BOOL cloak_pressed;
if (IsMovieDone ([dockingMusic QTMovie])) if (IsMovieDone ([dockingMusic QTMovie]))
GoToBeginningOfMovie ([dockingMusic QTMovie]); GoToBeginningOfMovie ([dockingMusic QTMovie]);
StartMovie ([dockingMusic QTMovie]); StartMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
[dockingMusic goToBeginning];
[dockingMusic play];
#endif #endif
} }
} }
@ -2749,6 +2747,10 @@ static BOOL cloak_pressed;
if (IsMovieDone ([dockingMusic QTMovie])) if (IsMovieDone ([dockingMusic QTMovie]))
GoToBeginningOfMovie ([dockingMusic QTMovie]); GoToBeginningOfMovie ([dockingMusic QTMovie]);
StartMovie ([dockingMusic QTMovie]); StartMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
[dockingMusic goToBeginning];
[dockingMusic play];
#endif #endif
} }
} }
@ -4223,6 +4225,8 @@ static BOOL toggling_music;
{ {
#ifndef GNUSTEP #ifndef GNUSTEP
StopMovie ([dockingMusic QTMovie]); StopMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
#endif #endif
} }
} }
@ -4239,12 +4243,19 @@ static BOOL toggling_music;
if (IsMovieDone ([dockingMusic QTMovie])) if (IsMovieDone ([dockingMusic QTMovie]))
GoToBeginningOfMovie ([dockingMusic QTMovie]); GoToBeginningOfMovie ([dockingMusic QTMovie]);
StartMovie ([dockingMusic QTMovie]); StartMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
[dockingMusic goToBeginning];
[dockingMusic play];
#endif #endif
} }
else else
{ {
#ifndef GNUSTEP #ifndef GNUSTEP
StopMovie ([dockingMusic QTMovie]); StopMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
#endif #endif
} }
} }
@ -4256,7 +4267,7 @@ static BOOL toggling_music;
} }
// //
// keep music playing // keep music playing
if ((docking_music_on)&&(!ootunes_on)) if (autopilot_engaged && (docking_music_on)&&(!ootunes_on))
{ {
#ifndef GNUSTEP #ifndef GNUSTEP
if (IsMovieDone ([dockingMusic QTMovie])) if (IsMovieDone ([dockingMusic QTMovie]))
@ -4264,6 +4275,12 @@ static BOOL toggling_music;
GoToBeginningOfMovie ([dockingMusic QTMovie]); GoToBeginningOfMovie ([dockingMusic QTMovie]);
StartMovie ([dockingMusic QTMovie]); StartMovie ([dockingMusic QTMovie]);
} }
#else
if ([dockingMusic isPlaying] == NO)
{
[dockingMusic goToBeginning];
[dockingMusic play];
}
#endif #endif
} }
@ -4306,13 +4323,16 @@ static BOOL toggling_music;
{ {
if (([gameView isDown:121])||([gameView isDown:89])) // 'yY' if (([gameView isDown:121])||([gameView isDown:89])) // 'yY'
{ {
#ifndef GNUSTEP
if (themeMusic) if (themeMusic)
{ {
StopMovie ([themeMusic QTMovie]); #ifndef GNUSTEP
StopMovie ([themeMusic QTMovie]);
GoToBeginningOfMovie ([themeMusic QTMovie]); GoToBeginningOfMovie ([themeMusic QTMovie]);
#else
[themeMusic stop];
[themeMusic goToBeginning];
#endif
} }
#endif
disc_operation_in_progress = YES; disc_operation_in_progress = YES;
if ([[universe gameController] inFullScreenMode]) if ([[universe gameController] inFullScreenMode])
@ -4350,13 +4370,18 @@ static BOOL toggling_music;
[gui setBackgroundImage:nil]; [gui setBackgroundImage:nil];
[self setGuiToStatusScreen]; [self setGuiToStatusScreen];
[universe setDisplayText:YES]; [universe setDisplayText:YES];
#ifndef GNUSTEP
if (themeMusic) if (themeMusic)
{ {
StopMovie ([themeMusic QTMovie]); #ifndef GNUSTEP
StopMovie ([themeMusic QTMovie]);
GoToBeginningOfMovie ([themeMusic QTMovie]); GoToBeginningOfMovie ([themeMusic QTMovie]);
} #else
[themeMusic stop];
[themeMusic goToBeginning];
#endif #endif
}
} }
break; break;
@ -4478,6 +4503,8 @@ static BOOL toggling_music;
{ {
#ifndef GNUSTEP #ifndef GNUSTEP
StopMovie ([dockingMusic QTMovie]); StopMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
#endif #endif
} }
} }
@ -5087,6 +5114,14 @@ static BOOL toggling_music;
[universe setViewDirection:VIEW_AFT]; [universe setViewDirection:VIEW_AFT];
[self becomeLargeExplosion:4.0]; [self becomeLargeExplosion:4.0];
[self moveForward:100.0]; [self moveForward:100.0];
// todo some check for ootunes
if (dockingMusic)
{
if ([dockingMusic isPlaying])
[dockingMusic stop];
}
#ifdef HAVE_SOUND #ifdef HAVE_SOUND
[destructionSound play]; [destructionSound play];
#endif #endif
@ -5221,6 +5256,8 @@ static BOOL toggling_music;
{ {
#ifndef GNUSTEP #ifndef GNUSTEP
StopMovie ([dockingMusic QTMovie]); StopMovie ([dockingMusic QTMovie]);
#else
[dockingMusic stop];
#endif #endif
} }
} }
@ -6599,13 +6636,18 @@ static int last_outfitting_index;
if (gui) if (gui)
gui_screen = GUI_SCREEN_INTRO1; gui_screen = GUI_SCREEN_INTRO1;
#ifndef GNUSTEP
if (themeMusic) if (themeMusic)
{ {
GoToBeginningOfMovie ([themeMusic QTMovie]); #ifndef GNUSTEP
GoToBeginningOfMovie ([themeMusic QTMovie]);
StartMovie ([themeMusic QTMovie]); StartMovie ([themeMusic QTMovie]);
} #else
#endif [themeMusic stop];
[themeMusic goToBeginning];
[themeMusic play];
#endif
}
} }
- (void) setGuiToIntro2Screen - (void) setGuiToIntro2Screen

View File

@ -43,6 +43,7 @@ Your fair use and other rights are in no way affected by the above.
#ifdef GNUSTEP #ifdef GNUSTEP
#import "Comparison.h" #import "Comparison.h"
#import "OOSound.h" #import "OOSound.h"
#import "OOMusic.h"
#endif #endif
@ -435,7 +436,42 @@ NSMutableDictionary* movie_cache;
#ifdef GNUSTEP #ifdef GNUSTEP
+ (id) movieFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername + (id) movieFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername
{ {
return nil; OOMusic *result = nil;
NSMutableArray *fpaths = [ResourceManager paths];
int i, r;
r = 0;
if (!filename)
return nil;
NSString* movie_key = [NSString stringWithFormat:@"%@:%@", foldername, filename];
if (!movie_cache)
movie_cache = [[NSMutableDictionary alloc] initWithCapacity:32];
if ([movie_cache objectForKey:movie_key])
return (id)[movie_cache objectForKey:movie_key]; // return the cached movie
for (i = 0; i < [fpaths count]; i++)
{
NSString *filepath = [(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:filename];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
result = [[OOMusic alloc] initWithContentsOfFile:filepath];
if (foldername)
{
filepath = [[(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:foldername] stringByAppendingPathComponent:filename];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
//NSLog(@"DEBUG ResourceManager found %@ at %@",filename,filepath);
if (result)
[result release];
result = [[OOMusic alloc] initWithContentsOfFile:filepath];
}
}
}
//NSLog(@"---> ResourceManager found %d file(s) with name '%@' (in folder '%@')", r, filename, foldername);
if (result)
[movie_cache setObject:result forKey:movie_key];
return [result autorelease];
} }
#else #else
+ (NSMovie *) movieFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername + (NSMovie *) movieFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername

View File

@ -59,7 +59,7 @@
<key>key_map_home</key> <key>key_map_home</key>
<integer>302</integer> <integer>302</integer>
<key>key_comms_log</key> <key>key_comms_log</key>
<integer>96</integer> <integer>126</integer>
<key>key_next_compass_mode</key> <key>key_next_compass_mode</key>
<integer>92</integer> <integer>92</integer>
</dict> </dict>

View File

@ -2695,7 +2695,7 @@ Your fair use and other rights are in no way affected by the above.
GLfloat cx_col0[4] = { 0.0, 1.0, 0.0, 0.25}; GLfloat cx_col0[4] = { 0.0, 1.0, 0.0, 0.25};
GLfloat cx_col1[4] = { 0.0, 1.0, 0.0, 0.50}; GLfloat cx_col1[4] = { 0.0, 1.0, 0.0, 0.50};
GLfloat cx_col2[4] = { 0.0, 1.0, 0.0, 0.75}; GLfloat cx_col2[4] = { 0.0, 1.0, 0.0, 0.75};
glEnable(GL_LINE_SMOOTH); // alpha blending //glEnable(GL_LINE_SMOOTH); // alpha blending
glLineWidth(2.0); glLineWidth(2.0);
switch (weapon) switch (weapon)

View File

@ -14,4 +14,7 @@
#include <GL/glext.h> #include <GL/glext.h>
#include <math.h> #include <math.h>
#include "SDL.h"
#include "SDL_mixer.h"
#endif /* OOLITE_LINUX */ #endif /* OOLITE_LINUX */