[Fix] Changing volume level actually works now.

This commit is contained in:
Allanis 2014-03-16 20:02:46 +00:00
parent 4884c04541
commit 3e97d1eea7
6 changed files with 58 additions and 20 deletions

View File

@ -195,9 +195,19 @@ int conf_loadConfig(const char* file) {
conf_loadBool("nosound", i);
nosound = i; i = 0;
conf_loadFloat("sound", d);
if(d) { sound_volume(d); d = 0.; }
if(d) {
sound_defVolume = MAX(MIN(d, 1.), 0.);
if(d == 0.)
sound_disabled = 1;
d = 0.;
}
conf_loadFloat("music", d);
if(d) { music_volume(d); d = 0.; }
if(d) {
music_defVolume = MAX(MIN(d, 1.), 0.);
if(d == 0.)
music_disabled = 1;
d = 0.;
}
/* Joystick. */
lua_getglobal(L, "joystick");
@ -327,6 +337,7 @@ void conf_parseCLI(int argc, char** argv) {
};
int option_index = 0;
int c = 0;
double d;
while((c = getopt_long(argc, argv,
"fF:Vd:j:J:W:H:MSm:s:Ghv",
@ -365,10 +376,16 @@ void conf_parseCLI(int argc, char** argv) {
nosound = 0;
break;
case 'm':
music_volume(atof(optarg));
d = atof(optarg);
music_defVolume = MAX(MIN(d, 1.), 0.);
if(d == 0.)
music_disabled = 1;
break;
case 's':
/*sound_volume(atof(optarg));*/
d = atof(optarg);
sound_defVolume = MAX(MIN(d, 1.), 0.);
if(d == 0.)
sound_disabled = 1;
break;
case 'G':
nebu_forceGenerate();

View File

@ -123,7 +123,8 @@ int main(int argc, char** argv) {
/* Print the version. */
snprintf(version, VERSION_LEN, "%d.%d.%d", VMAJOR, VMINOR, VREV);
LOG(" "APPNAME" v%s", version);
LOG("\n "APPNAME" - Dark Tides v%s", version);
LOG(" ----------------------------\n");
/* Initialize SDL for possible warnings. */
SDL_Init(0);

View File

@ -22,6 +22,7 @@
#define MUSIC_LUA_PATH "../snd/music.lua" /**< Lua music control file. */
int music_disabled = 0; /**< Whether or not music is disabled. */
double music_defVolume = 0.8l; /**< Music default volume. */
/* Handle if music should run Lua script. Must be locked to ensure same
* behaviour always!
@ -70,6 +71,8 @@ static void music_luaQuit(void);
void music_update(void) {
char buf[PATH_MAX];
if(music_disabled) return;
/* Lock music and see if it needs to update. */
SDL_mutexP(music_lock);
if(music_runchoose == 0) {
@ -90,6 +93,7 @@ void music_update(void) {
* @return 0 on success.
*/
static int music_runLua(char* situation) {
if(music_disabled) return 0;
/* Run the choose function in Lua. */
lua_getglobal(music_lua, "choose");
lua_pushstring(music_lua, situation);
@ -110,7 +114,7 @@ int music_init(void) {
if(music_find() < 0) return -1;
if(music_luaInit() < 0) return -1;
music_volume(0.8);
music_volume(music_defVolume);
/* Create the lock. */
music_lock = SDL_CreateMutex();
@ -238,6 +242,8 @@ void music_load(const char* name) {
* @brief Play the loaded music.
*/
void music_play(void) {
if(music_disabled) return;
if(music_music == NULL) return;
if(Mix_FadeInMusic(music_music, 0, 500) < 0)
@ -250,6 +256,8 @@ void music_play(void) {
* @brief Stop the loaded music.
*/
void music_stop(void) {
if(music_disabled) return;
if(music_music == NULL) return;
if(Mix_FadeOutMusic(500) < 0)
@ -260,6 +268,8 @@ void music_stop(void) {
* @brief Pauses the music.
*/
void music_pause(void) {
if(music_disabled) return;
if(music_music == NULL) return;
Mix_PauseMusic();
@ -269,6 +279,8 @@ void music_pause(void) {
* @brief Resumes the music.
*/
void music_resume(void) {
if(music_disabled) return;
if(music_music == NULL) return;
Mix_ResumeMusic();
@ -279,6 +291,7 @@ void music_resume(void) {
* @param sec Position to go to in seconds.
*/
void music_setPos(double sec) {
if(music_disabled) return;
if(music_music == NULL) return;
Mix_FadeInMusicPos(music_music, 1, 1000, sec);
@ -296,6 +309,8 @@ static int music_luaInit(void) {
char* buf;
uint32_t bufsize;
if(music_disabled) return 0;
if(music_lua != NULL)
music_luaQuit();
@ -329,6 +344,8 @@ static int music_luaInit(void) {
* @brief Quit the music Lua control system.
*/
static void music_luaQuit(void) {
if(music_disabled) return;
if(music_lua == NULL)
return;
@ -373,6 +390,8 @@ int music_choose(char* situation) {
* ARGH! DO NOT CALL MIX_* FUNCTIONS FROM WITHIN THE CALLBACKS!
*/
static void music_rechoose(void) {
if(music_disabled) return;
/* Lock so it doesn't run in between an update. */
SDL_mutexP(music_lock);
music_runchoose = 1;

View File

@ -2,6 +2,7 @@
#include "lua.h"
extern int music_disabled;
extern double music_defVolume;
/* Updating. */
void music_update(void);

View File

@ -24,6 +24,7 @@
/* Global sound properties. */
int sound_disabled = 0; /**< Whether sound is disabled. */
double sound_defVolume = 0.4; /**< Sound default volume. */
static int sound_reserved = 0; /**< Amount of reserved channels. */
static double sound_pos[3]; /**< Position of listener. */
@ -73,7 +74,6 @@ static alSound* sound_list = NULL; /**< List of available sounds. */
static int sound_nlist = 0; /**< Number of available sounds. */
/* Voice linked list. */
static SDL_mutex* voice_lock = NULL;
static alVoice* voice_active = NULL; /**< Active voices. */
static alVoice* voice_pool = NULL; /**< Pool of free voices. */
@ -95,7 +95,7 @@ static alVoice* voice_get(int id);
* @return 0 on success.
*/
int sound_init(void) {
if(sound_disabled) return 0;
if(sound_disabled && music_disabled) return 0;
SDL_InitSubSystem(SDL_INIT_AUDIO);
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) < 0) {
@ -111,19 +111,18 @@ int sound_init(void) {
/* Debug magic. */
print_MixerVersion();
if(!sound_disabled) {
/* Load up all the sounds. */
sound_makeList();
sound_volume(0.4);
sound_volume(sound_defVolume);
/* Finish function. */
Mix_ChannelFinished(voice_markStopped);
}
/* Init the music. */
music_init();
/* Create the voice lock. */
voice_lock = SDL_CreateMutex();
return 0;
}
@ -173,7 +172,6 @@ void sound_exit(void) {
/* Close the audio. */
Mix_CloseAudio();
SDL_DestroyMutex(voice_lock);
/* Free the voices. */
while(voice_active != NULL) {
@ -414,6 +412,7 @@ void sound_stop(int voice) {
* @sa sound_playPos
*/
int sound_updateListener(double dir, double x, double y) {
if(sound_disabled) return 0;
sound_pos[0] = x;
sound_pos[1] = y;
sound_pos[2] = dir/M_PI*180.;

View File

@ -1,6 +1,7 @@
#pragma once
extern int sound_disabled;
extern double sound_defVolume;
/* Sound subsystem. */
int sound_init(void);