diff --git a/code/freespace2/freespace.cpp b/code/freespace2/freespace.cpp index 8ec43bb97e..47c9f4ecae 100644 --- a/code/freespace2/freespace.cpp +++ b/code/freespace2/freespace.cpp @@ -9,13 +9,17 @@ /* * $Logfile: /Freespace2/code/Freespace2/FreeSpace.cpp $ - * $Revision: 2.248 $ - * $Date: 2006-06-15 01:29:18 $ - * $Author: Goober5000 $ + * $Revision: 2.249 $ + * $Date: 2006-06-27 04:58:58 $ + * $Author: taylor $ * * FreeSpace main body * * $Log: not supported by cvs2svn $ + * Revision 2.248 2006/06/15 01:29:18 Goober5000 + * tweaked the version string + * --Goober5000 + * * Revision 2.247 2006/06/07 04:39:10 wmcoolmon * Limbo flag support * @@ -3532,11 +3536,13 @@ void game_init() int use_a3d = 0; int use_eax = 0; +#ifndef USE_OPENAL ptr = os_config_read_string(NULL, NOX("Soundcard"), NULL); mprintf(("soundcard = %s\n", ptr ? ptr : "")); if (ptr) { if (!stricmp(ptr, NOX("no sound"))) { Cmdline_freespace_no_sound = 1; + Cmdline_freespace_no_music = 1; } else if (!stricmp(ptr, NOX("Aureal A3D"))) { use_a3d = 1; @@ -3551,6 +3557,17 @@ void game_init() exit(0); } #endif +#else // USE_OPENAL + ptr = os_config_read_string(NULL, NOX("SoundDeviceOAL"), NULL); + if (ptr) { + if ( !stricmp(ptr, NOX("no sound")) ) { + mprintf(("Sound is disabled!\n")); + + Cmdline_freespace_no_sound = 1; + Cmdline_freespace_no_music = 1; + } + } +#endif // !USE_OPENAL if (!Is_standalone) { @@ -4950,7 +4967,7 @@ inline void render_environment(int i, matrix *new_orient, float new_zoom) void setup_environment_mapping(vec3d *eye_pos, matrix *eye_orient) { - matrix new_orient; + matrix new_orient = IDENTITY_MATRIX; float old_zoom = View_zoom, new_zoom = 0.925f; int i = 0; @@ -4958,6 +4975,15 @@ void setup_environment_mapping(vec3d *eye_pos, matrix *eye_orient) if (Cmdline_nohtl) return; + // prefer the mission specified envmap over the static-generated envmap, but + // the dynamic envmap should always get preference if in a subspace mission + if ( !Game_subspace_effect && strlen(The_mission.envmap_name) ) { + ENVMAP = bm_load(The_mission.envmap_name); + + if (ENVMAP >= 0) + return; + } + if ( (Game_subspace_effect && (gr_screen.dynamic_environment_map < 0)) || (!Game_subspace_effect && (gr_screen.static_environment_map < 0)) ) { if (ENVMAP > -1) return; @@ -5360,7 +5386,7 @@ void game_render_frame( vec3d *eye_pos, matrix *eye_orient ) // Do the sunspot game_sunspot_process(flFrametime); - bool draw_viewer_last; + bool draw_viewer_last = false; obj_render_all(obj_render, &draw_viewer_last); mflash_render_all(); // render all muzzle flashes diff --git a/code/sound/ds.cpp b/code/sound/ds.cpp index e44584ab68..bb0b6e76e6 100644 --- a/code/sound/ds.cpp +++ b/code/sound/ds.cpp @@ -9,13 +9,16 @@ /* * $Logfile: /Freespace2/code/Sound/ds.cpp $ - * $Revision: 2.46 $ - * $Date: 2006-06-01 07:33:00 $ + * $Revision: 2.47 $ + * $Date: 2006-06-27 04:58:58 $ * $Author: taylor $ * * C file for interface to DirectSound * * $Log: not supported by cvs2svn $ + * Revision 2.46 2006/06/01 07:33:00 taylor + * make sure to use software device rather than hardware since we don't currently handle source rotation/reuse properly between ds and audiostr code + * * Revision 2.45 2006/06/01 04:46:18 taylor * put back listener setup for each sound, doesn't make a difference under Linux but it may be hurting Windows for some reason * @@ -673,14 +676,22 @@ ALCcontext *ds_sound_context = NULL; // // Returns the human readable error string if there is an error or NULL if not // -const char* openal_error_string() +const char* openal_error_string(int get_alc) { int i; - i = alGetError(); + if (get_alc) { + i = alcGetError(NULL); - if ( i != AL_NO_ERROR ) - return (const char*)alGetString(i); + if ( i != ALC_NO_ERROR ) + return (const char*) alcGetString(NULL, i); + } + else { + i = alGetError(); + + if ( i != AL_NO_ERROR ) + return (const char*)alGetString(i); + } return NULL; } @@ -1420,12 +1431,14 @@ void ds_init_channels() Error(LOCATION, "Unable to allocate %d bytes for %d audio channels.", sizeof(channel) * MAX_CHANNELS, MAX_CHANNELS); } + memset( Channels, 0, sizeof(channel) * MAX_CHANNELS ); + // init the channels for ( i = 0; i < MAX_CHANNELS; i++ ) { OpenAL_ErrorPrint( alGenSources(1, &Channels[i].source_id) ); Channels[i].buf_id = -1; - Channels[i].vol = 0; - Channels[i].is_voice_msg = false; + Channels[i].sig = -1; + Channels[i].snd_id = -1; } #else int i; @@ -1701,8 +1714,6 @@ int ds_init(int use_a3d, int use_eax, unsigned int sample_rate, unsigned short s #ifdef USE_OPENAL // NOTE: A3D and EAX are unused in OpenAL int attr[] = { ALC_FREQUENCY, sample_rate, ALC_SYNC, AL_FALSE, 0 }; - char *extlist, *curext; - static const char *OAL_extensions; Ds_use_a3d = 0; Ds_use_eax = 0; @@ -1719,7 +1730,10 @@ int ds_init(int use_a3d, int use_eax, unsigned int sample_rate, unsigned short s // restrict to DirectSound rather than DirectSound3D (the default) here since we may have 'too many hardware sources' // type problems (FIXME for a later date since I don't like this with future code) - taylor #ifdef AL_VERSION_1_1 - ds_sound_device = alcOpenDevice( (const ALCchar *) NOX("Generic Software") ); + char *device_spec = os_config_read_string( NULL, "SoundDeviceOAL", "Generic Software" ); + mprintf((" Using '%s' as OpenAL sound device...\n", device_spec)); + + ds_sound_device = alcOpenDevice( (const ALCchar *) device_spec ); #else ds_sound_device = alcOpenDevice( (const ALubyte *) NOX("DirectSound") ); #endif // AL_VERSION_1_1 @@ -1741,45 +1755,22 @@ int ds_init(int use_a3d, int use_eax, unsigned int sample_rate, unsigned short s return -1; } - OpenAL_ErrorCheck( alcMakeContextCurrent( ds_sound_context ), return -1 ); + OpenAL_C_ErrorCheck( alcMakeContextCurrent( ds_sound_context ), return -1 ); mprintf(( " OpenAL Vendor : %s\n", alGetString( AL_VENDOR ) )); mprintf(( " OpenAL Renderer : %s\n", alGetString( AL_RENDERER ) )); mprintf(( " OpenAL Version : %s\n", alGetString( AL_VERSION ) )); - mprintf(( " OpenAL Extensions : \n" )); - - // print out OpenAL extensions - OAL_extensions=(const char*)alGetString( AL_EXTENSIONS ); - int ext_length = strlen(OAL_extensions) + 1; - - // we use the "+1" here to have an extra NULL char on the end (with the memset()) - // this is to fix memory errors when the last char in extlist is the same as the token - // we are looking for and ultra evil strtok() may still return non-NULL at EOS - extlist = (char*)vm_malloc( ext_length ); - memset( extlist, 0, ext_length); - - if (extlist != NULL) { - memcpy(extlist, OAL_extensions, ext_length - 1); - - curext = strtok(extlist, " "); - - while (curext) { - mprintf(( " %s\n", curext )); - curext = strtok(NULL, " "); - } - - vm_free(extlist); - extlist = NULL; - } + mprintf(( "\n" )); // make sure we can actually use AL_BYTE_LOKI (Mac OpenAL doesn't have it) -#ifndef _WIN32 #ifdef AL_VERSION_1_1 AL_play_position = alIsExtensionPresent( (const ALchar*)"AL_LOKI_play_position" ); #else AL_play_position = alIsExtensionPresent( (ALubyte*)"AL_LOKI_play_position" ); #endif // AL_VERSION_1_1 -#endif // !_WIN32 + + if (AL_play_position) + mprintf(( " Using extension \"AL_LOKI_play_position\".\n" )); // not a big deal here, but for consitancy sake if (Ds_use_ds3d && ds3d_init(0) != 0) @@ -2253,7 +2244,7 @@ void ds_close() Channels = NULL; #ifdef USE_OPENAL -// alcMakeContextCurrent(NULL); // hangs on me for some reason + alcMakeContextCurrent(NULL); // hangs on me for some reason if (ds_sound_context != NULL) alcDestroyContext(ds_sound_context); @@ -2328,17 +2319,20 @@ int ds_get_free_channel(int new_volume, int snd_id, int priority) // Look for a channel to use to play this sample for ( i = 0; i < MAX_CHANNELS; i++ ) { chp = &Channels[i]; + if ( chp->source_id == 0 ) { if ( first_free_channel == -1 ) first_free_channel = i; + continue; } - OpenAL_ErrorCheck( alGetSourcei(chp->source_id, AL_SOURCE_STATE, &status), return -1 ); + OpenAL_ErrorCheck( alGetSourcei(chp->source_id, AL_SOURCE_STATE, &status), continue ); if ( status != AL_PLAYING ) { if ( first_free_channel == -1 ) first_free_channel = i; + continue; } else { @@ -3025,7 +3019,7 @@ int ds_get_channel(int sig) int i; for ( i = 0; i < MAX_CHANNELS; i++ ) { - if ( Channels[i].source_id && Channels[i].sig == sig ) { + if ( Channels[i].source_id && (Channels[i].sig == sig) ) { if ( ds_is_channel_playing(i) == TRUE ) { return i; } diff --git a/code/sound/ds.h b/code/sound/ds.h index 31f658abad..77e3345117 100644 --- a/code/sound/ds.h +++ b/code/sound/ds.h @@ -9,13 +9,16 @@ /* * $Logfile: /Freespace2/code/Sound/ds.h $ - * $Revision: 2.18 $ - * $Date: 2006-05-14 05:22:43 $ + * $Revision: 2.19 $ + * $Date: 2006-06-27 04:58:58 $ * $Author: taylor $ * * Header file for interface to DirectSound * * $Log: not supported by cvs2svn $ + * Revision 2.18 2006/05/14 05:22:43 taylor + * forgot to remove STRICT define before commit, gets rid of a Windows compiler warning + * * Revision 2.17 2006/05/13 07:10:37 taylor * some Windows specific OpenAL changes * add MVE files to MSVC6 project @@ -241,16 +244,16 @@ typedef struct channel extern channel *Channels; -extern const char* openal_error_string(); +extern const char* openal_error_string(int get_alc = 0); // if an error occurs after executing 'x' then do 'y' #define OpenAL_ErrorCheck( x, y ) do { \ x; \ - const char *error_text = openal_error_string(); \ + const char *error_text = openal_error_string(0); \ if ( error_text != NULL ) { \ while ( error_text != NULL ) { \ nprintf(("Warning", "SOUND: %s:%d - OpenAL error = '%s'\n", __FILE__, __LINE__, error_text)); \ - error_text = openal_error_string(); \ + error_text = openal_error_string(0); \ } \ y; \ } \ @@ -259,15 +262,39 @@ extern const char* openal_error_string(); // like OpenAL_ErrorCheck() except that it gives the error message from x but does nothing about it #define OpenAL_ErrorPrint( x ) do { \ x; \ - const char *error_text = openal_error_string(); \ + const char *error_text = openal_error_string(0); \ if ( error_text != NULL ) { \ while ( error_text != NULL ) { \ nprintf(("Sound", "OpenAL ERROR: \"%s\" in %s, line %i\n", error_text, __FILE__, __LINE__)); \ - error_text = openal_error_string(); \ + error_text = openal_error_string(0); \ } \ } \ } while (0); +// same as the above two, but looks for ALC errors instead of standard AL errors +#define OpenAL_C_ErrorCheck( x, y ) do { \ + x; \ + const char *error_text = openal_error_string(1); \ + if ( error_text != NULL ) { \ + while ( error_text != NULL ) { \ + nprintf(("Warning", "SOUND: %s:%d - OpenAL error = '%s'\n", __FILE__, __LINE__, error_text)); \ + error_text = openal_error_string(1); \ + } \ + y; \ + } \ +} while (0); + +// like OpenAL_ErrorCheck() except that it gives the error message from x but does nothing about it +#define OpenAL_C_ErrorPrint( x ) do { \ + x; \ + const char *error_text = openal_error_string(1); \ + if ( error_text != NULL ) { \ + while ( error_text != NULL ) { \ + nprintf(("Sound", "OpenAL ERROR: \"%s\" in %s, line %i\n", error_text, __FILE__, __LINE__)); \ + error_text = openal_error_string(1); \ + } \ + } \ +} while (0); #else extern LPDIRECTSOUNDBUFFER pPrimaryBuffer;