[Fix] Allow for gameplay even if sound isn't working.
This commit is contained in:
parent
6a02e903a5
commit
f9c778358c
@ -266,6 +266,8 @@ static void music_free(void) {
|
||||
}
|
||||
|
||||
void music_volume(const double vol) {
|
||||
if(sound_lock == NULL) return;
|
||||
|
||||
// Sanity check!
|
||||
ALfloat fvol = ABS(vol);
|
||||
if(fvol > 1.) fvol = 1.;
|
||||
@ -282,6 +284,8 @@ void music_volume(const double vol) {
|
||||
|
||||
// Music control functions.
|
||||
void music_load(const char* name) {
|
||||
if(sound_lock == NULL) return;
|
||||
|
||||
int i;
|
||||
char tmp[64];
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "SDL_thread.h"
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "pack.h"
|
||||
@ -15,6 +17,9 @@
|
||||
#define OUTFIT_DATA "../dat/outfit.xml"
|
||||
#define OUTFIT_GFX "../gfx/outfit/"
|
||||
|
||||
extern SDL_mutex* sound_lock; // Sound.c
|
||||
|
||||
// The Stack.
|
||||
static Outfit* outfit_stack = NULL;
|
||||
static int outfits = 0;
|
||||
|
||||
@ -174,7 +179,7 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) {
|
||||
} while((node = node->next));
|
||||
#define MELEMENT(o,s) if(o) WARN("Outfit '%s' missing '"s"' element", tmp->name)
|
||||
MELEMENT(tmp->gfx_space == NULL, "gfx");
|
||||
MELEMENT(tmp->sound==0, "sound");
|
||||
MELEMENT((sound_lock != NULL) && (tmp->sound == 0), "sound");
|
||||
MELEMENT(tmp->thrust==0, "thrust");
|
||||
MELEMENT(tmp->turn==0, "turn");
|
||||
MELEMENT(tmp->speed==0, "speed");
|
||||
|
32
src/sound.c
32
src/sound.c
@ -33,7 +33,7 @@ typedef struct {
|
||||
#define voice_is(v,f) ((v)->flags & f)
|
||||
|
||||
// Global sound lock.
|
||||
SDL_mutex* sound_lock;
|
||||
SDL_mutex* sound_lock = NULL;
|
||||
|
||||
// Gobal device and context.
|
||||
static ALCcontext* al_context = NULL;
|
||||
@ -77,7 +77,7 @@ int sound_init(void) {
|
||||
|
||||
// Create the OpenAL context.
|
||||
al_context = alcCreateContext(al_device, NULL);
|
||||
if(al_context == NULL) {
|
||||
if(sound_lock == NULL) {
|
||||
WARN("Unable to create OpenAL context");
|
||||
ret = -2;
|
||||
goto snderr_ctx;
|
||||
@ -119,6 +119,7 @@ snderr_dev:
|
||||
al_device = NULL;
|
||||
SDL_mutexV(sound_lock);
|
||||
SDL_DestroyMutex(sound_lock);
|
||||
sound_lock = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -135,11 +136,14 @@ void sound_exit(void) {
|
||||
|
||||
// Must stop the music before killing it,
|
||||
// then thread should commit suicide.
|
||||
if(music_player) {
|
||||
music_stop();
|
||||
music_kill();
|
||||
SDL_WaitThread(music_player, NULL);
|
||||
music_exit();
|
||||
}
|
||||
|
||||
if(sound_lock) {
|
||||
SDL_mutexP(sound_lock);
|
||||
|
||||
if(al_context) {
|
||||
@ -151,9 +155,12 @@ void sound_exit(void) {
|
||||
SDL_mutexV(sound_lock);
|
||||
SDL_DestroyMutex(sound_lock);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the buffer to sound of [name].
|
||||
ALuint sound_get(char* name) {
|
||||
if(sound_lock == NULL) return 0;
|
||||
|
||||
int i;
|
||||
for(i = 0; i < nsound_list; i++)
|
||||
if(strcmp(name, sound_list[i].name)==0)
|
||||
@ -164,6 +171,8 @@ ALuint sound_get(char* name) {
|
||||
|
||||
// Make list of available sounds.
|
||||
static int sound_makeList(void) {
|
||||
if(sound_lock == NULL) return 0;
|
||||
|
||||
char** files;
|
||||
uint32_t nfiles, i;
|
||||
char tmp[64];
|
||||
@ -203,6 +212,8 @@ static int sound_makeList(void) {
|
||||
|
||||
// Loads a sound into the sound_list.
|
||||
static int sound_load(ALuint* buffer, char* filename) {
|
||||
if(sound_lock == NULL) return 0;
|
||||
|
||||
void* wavdata;
|
||||
unsigned int size;
|
||||
ALenum err;
|
||||
@ -230,6 +241,8 @@ static int sound_load(ALuint* buffer, char* filename) {
|
||||
}
|
||||
|
||||
static void sound_free(alSound* snd) {
|
||||
if(sound_lock) return;
|
||||
|
||||
SDL_mutexP(sound_lock);
|
||||
|
||||
if(snd->name) free(snd->name);
|
||||
@ -240,6 +253,7 @@ static void sound_free(alSound* snd) {
|
||||
|
||||
// Update the sounds and prioritize them.
|
||||
void sound_update(void) {
|
||||
if(sound_lock == NULL) return;
|
||||
int i;
|
||||
|
||||
// TODO: Prioritize the things.
|
||||
@ -261,6 +275,8 @@ void sound_update(void) {
|
||||
|
||||
// Set all the sounds volume to vol.
|
||||
void sound_volume(const double vol) {
|
||||
if(sound_lock == NULL) return;
|
||||
|
||||
int i;
|
||||
|
||||
svolume = (ALfloat) vol;
|
||||
@ -274,6 +290,7 @@ void sound_volume(const double vol) {
|
||||
|
||||
// Attempt to alloc a source for a voice.
|
||||
static int voice_getSource(alVoice* voc) {
|
||||
if(sound_lock == NULL) return -1;
|
||||
int ret;
|
||||
ALenum err;
|
||||
|
||||
@ -314,7 +331,7 @@ static int voice_getSource(alVoice* voc) {
|
||||
}
|
||||
SDL_mutexV(sound_lock);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
alVoice* sound_addVoice(int priority, double px, double py, double vx, double vy,
|
||||
@ -323,6 +340,8 @@ alVoice* sound_addVoice(int priority, double px, double py, double vx, double vy
|
||||
(void)vx;
|
||||
(void)vy;
|
||||
|
||||
if(sound_lock == NULL) return NULL;
|
||||
|
||||
alVoice* voc;
|
||||
|
||||
nvoice_stack++;
|
||||
@ -348,6 +367,7 @@ alVoice* sound_addVoice(int priority, double px, double py, double vx, double vy
|
||||
}
|
||||
|
||||
void sound_delVoice(alVoice* voice) {
|
||||
if(sound_lock == NULL) return;
|
||||
ALint stat;
|
||||
int i;
|
||||
|
||||
@ -381,6 +401,9 @@ void sound_delVoice(alVoice* voice) {
|
||||
void voice_update(alVoice* voice, double px, double py, double vx, double vy) {
|
||||
(void) vx;
|
||||
(void) vy;
|
||||
|
||||
if(sound_lock == NULL) return;
|
||||
|
||||
voice->px = px;
|
||||
voice->py = py;
|
||||
//voice->vx = vx;
|
||||
@ -390,6 +413,9 @@ void voice_update(alVoice* voice, double px, double py, double vx, double vy) {
|
||||
void sound_listener(double dir, double px, double py, double vx, double vy) {
|
||||
(void)vx;
|
||||
(void)vy;
|
||||
|
||||
if(sound_lock == NULL) return;
|
||||
|
||||
SDL_mutexP(sound_lock);
|
||||
|
||||
ALfloat ori[] = { 0., 0., 0., 0., 0., 1. };
|
||||
|
Loading…
Reference in New Issue
Block a user