[Fix] Changing volume level actually works now.
This commit is contained in:
parent
4884c04541
commit
3e97d1eea7
25
src/conf.c
25
src/conf.c
@ -195,9 +195,19 @@ int conf_loadConfig(const char* file) {
|
|||||||
conf_loadBool("nosound", i);
|
conf_loadBool("nosound", i);
|
||||||
nosound = i; i = 0;
|
nosound = i; i = 0;
|
||||||
conf_loadFloat("sound", d);
|
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);
|
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. */
|
/* Joystick. */
|
||||||
lua_getglobal(L, "joystick");
|
lua_getglobal(L, "joystick");
|
||||||
@ -327,6 +337,7 @@ void conf_parseCLI(int argc, char** argv) {
|
|||||||
};
|
};
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
double d;
|
||||||
|
|
||||||
while((c = getopt_long(argc, argv,
|
while((c = getopt_long(argc, argv,
|
||||||
"fF:Vd:j:J:W:H:MSm:s:Ghv",
|
"fF:Vd:j:J:W:H:MSm:s:Ghv",
|
||||||
@ -365,10 +376,16 @@ void conf_parseCLI(int argc, char** argv) {
|
|||||||
nosound = 0;
|
nosound = 0;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
music_volume(atof(optarg));
|
d = atof(optarg);
|
||||||
|
music_defVolume = MAX(MIN(d, 1.), 0.);
|
||||||
|
if(d == 0.)
|
||||||
|
music_disabled = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
/*sound_volume(atof(optarg));*/
|
d = atof(optarg);
|
||||||
|
sound_defVolume = MAX(MIN(d, 1.), 0.);
|
||||||
|
if(d == 0.)
|
||||||
|
sound_disabled = 1;
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
nebu_forceGenerate();
|
nebu_forceGenerate();
|
||||||
|
@ -123,7 +123,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
/* Print the version. */
|
/* Print the version. */
|
||||||
snprintf(version, VERSION_LEN, "%d.%d.%d", VMAJOR, VMINOR, VREV);
|
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. */
|
/* Initialize SDL for possible warnings. */
|
||||||
SDL_Init(0);
|
SDL_Init(0);
|
||||||
|
21
src/music.c
21
src/music.c
@ -22,6 +22,7 @@
|
|||||||
#define MUSIC_LUA_PATH "../snd/music.lua" /**< Lua music control file. */
|
#define MUSIC_LUA_PATH "../snd/music.lua" /**< Lua music control file. */
|
||||||
|
|
||||||
int music_disabled = 0; /**< Whether or not music is disabled. */
|
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
|
/* Handle if music should run Lua script. Must be locked to ensure same
|
||||||
* behaviour always!
|
* behaviour always!
|
||||||
@ -70,6 +71,8 @@ static void music_luaQuit(void);
|
|||||||
void music_update(void) {
|
void music_update(void) {
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
/* Lock music and see if it needs to update. */
|
/* Lock music and see if it needs to update. */
|
||||||
SDL_mutexP(music_lock);
|
SDL_mutexP(music_lock);
|
||||||
if(music_runchoose == 0) {
|
if(music_runchoose == 0) {
|
||||||
@ -90,6 +93,7 @@ void music_update(void) {
|
|||||||
* @return 0 on success.
|
* @return 0 on success.
|
||||||
*/
|
*/
|
||||||
static int music_runLua(char* situation) {
|
static int music_runLua(char* situation) {
|
||||||
|
if(music_disabled) return 0;
|
||||||
/* Run the choose function in Lua. */
|
/* Run the choose function in Lua. */
|
||||||
lua_getglobal(music_lua, "choose");
|
lua_getglobal(music_lua, "choose");
|
||||||
lua_pushstring(music_lua, situation);
|
lua_pushstring(music_lua, situation);
|
||||||
@ -110,7 +114,7 @@ int music_init(void) {
|
|||||||
|
|
||||||
if(music_find() < 0) return -1;
|
if(music_find() < 0) return -1;
|
||||||
if(music_luaInit() < 0) return -1;
|
if(music_luaInit() < 0) return -1;
|
||||||
music_volume(0.8);
|
music_volume(music_defVolume);
|
||||||
|
|
||||||
/* Create the lock. */
|
/* Create the lock. */
|
||||||
music_lock = SDL_CreateMutex();
|
music_lock = SDL_CreateMutex();
|
||||||
@ -238,6 +242,8 @@ void music_load(const char* name) {
|
|||||||
* @brief Play the loaded music.
|
* @brief Play the loaded music.
|
||||||
*/
|
*/
|
||||||
void music_play(void) {
|
void music_play(void) {
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
if(music_music == NULL) return;
|
if(music_music == NULL) return;
|
||||||
|
|
||||||
if(Mix_FadeInMusic(music_music, 0, 500) < 0)
|
if(Mix_FadeInMusic(music_music, 0, 500) < 0)
|
||||||
@ -250,6 +256,8 @@ void music_play(void) {
|
|||||||
* @brief Stop the loaded music.
|
* @brief Stop the loaded music.
|
||||||
*/
|
*/
|
||||||
void music_stop(void) {
|
void music_stop(void) {
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
if(music_music == NULL) return;
|
if(music_music == NULL) return;
|
||||||
|
|
||||||
if(Mix_FadeOutMusic(500) < 0)
|
if(Mix_FadeOutMusic(500) < 0)
|
||||||
@ -260,6 +268,8 @@ void music_stop(void) {
|
|||||||
* @brief Pauses the music.
|
* @brief Pauses the music.
|
||||||
*/
|
*/
|
||||||
void music_pause(void) {
|
void music_pause(void) {
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
if(music_music == NULL) return;
|
if(music_music == NULL) return;
|
||||||
|
|
||||||
Mix_PauseMusic();
|
Mix_PauseMusic();
|
||||||
@ -269,6 +279,8 @@ void music_pause(void) {
|
|||||||
* @brief Resumes the music.
|
* @brief Resumes the music.
|
||||||
*/
|
*/
|
||||||
void music_resume(void) {
|
void music_resume(void) {
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
if(music_music == NULL) return;
|
if(music_music == NULL) return;
|
||||||
|
|
||||||
Mix_ResumeMusic();
|
Mix_ResumeMusic();
|
||||||
@ -279,6 +291,7 @@ void music_resume(void) {
|
|||||||
* @param sec Position to go to in seconds.
|
* @param sec Position to go to in seconds.
|
||||||
*/
|
*/
|
||||||
void music_setPos(double sec) {
|
void music_setPos(double sec) {
|
||||||
|
if(music_disabled) return;
|
||||||
if(music_music == NULL) return;
|
if(music_music == NULL) return;
|
||||||
|
|
||||||
Mix_FadeInMusicPos(music_music, 1, 1000, sec);
|
Mix_FadeInMusicPos(music_music, 1, 1000, sec);
|
||||||
@ -296,6 +309,8 @@ static int music_luaInit(void) {
|
|||||||
char* buf;
|
char* buf;
|
||||||
uint32_t bufsize;
|
uint32_t bufsize;
|
||||||
|
|
||||||
|
if(music_disabled) return 0;
|
||||||
|
|
||||||
if(music_lua != NULL)
|
if(music_lua != NULL)
|
||||||
music_luaQuit();
|
music_luaQuit();
|
||||||
|
|
||||||
@ -329,6 +344,8 @@ static int music_luaInit(void) {
|
|||||||
* @brief Quit the music Lua control system.
|
* @brief Quit the music Lua control system.
|
||||||
*/
|
*/
|
||||||
static void music_luaQuit(void) {
|
static void music_luaQuit(void) {
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
if(music_lua == NULL)
|
if(music_lua == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -373,6 +390,8 @@ int music_choose(char* situation) {
|
|||||||
* ARGH! DO NOT CALL MIX_* FUNCTIONS FROM WITHIN THE CALLBACKS!
|
* ARGH! DO NOT CALL MIX_* FUNCTIONS FROM WITHIN THE CALLBACKS!
|
||||||
*/
|
*/
|
||||||
static void music_rechoose(void) {
|
static void music_rechoose(void) {
|
||||||
|
if(music_disabled) return;
|
||||||
|
|
||||||
/* Lock so it doesn't run in between an update. */
|
/* Lock so it doesn't run in between an update. */
|
||||||
SDL_mutexP(music_lock);
|
SDL_mutexP(music_lock);
|
||||||
music_runchoose = 1;
|
music_runchoose = 1;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
extern int music_disabled;
|
extern int music_disabled;
|
||||||
|
extern double music_defVolume;
|
||||||
|
|
||||||
/* Updating. */
|
/* Updating. */
|
||||||
void music_update(void);
|
void music_update(void);
|
||||||
|
13
src/sound.c
13
src/sound.c
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
/* Global sound properties. */
|
/* Global sound properties. */
|
||||||
int sound_disabled = 0; /**< Whether sound is disabled. */
|
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 int sound_reserved = 0; /**< Amount of reserved channels. */
|
||||||
static double sound_pos[3]; /**< Position of listener. */
|
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. */
|
static int sound_nlist = 0; /**< Number of available sounds. */
|
||||||
|
|
||||||
/* Voice linked list. */
|
/* Voice linked list. */
|
||||||
static SDL_mutex* voice_lock = NULL;
|
|
||||||
static alVoice* voice_active = NULL; /**< Active voices. */
|
static alVoice* voice_active = NULL; /**< Active voices. */
|
||||||
static alVoice* voice_pool = NULL; /**< Pool of free voices. */
|
static alVoice* voice_pool = NULL; /**< Pool of free voices. */
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ static alVoice* voice_get(int id);
|
|||||||
* @return 0 on success.
|
* @return 0 on success.
|
||||||
*/
|
*/
|
||||||
int sound_init(void) {
|
int sound_init(void) {
|
||||||
if(sound_disabled) return 0;
|
if(sound_disabled && music_disabled) return 0;
|
||||||
|
|
||||||
SDL_InitSubSystem(SDL_INIT_AUDIO);
|
SDL_InitSubSystem(SDL_INIT_AUDIO);
|
||||||
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) < 0) {
|
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) < 0) {
|
||||||
@ -111,19 +111,18 @@ int sound_init(void) {
|
|||||||
/* Debug magic. */
|
/* Debug magic. */
|
||||||
print_MixerVersion();
|
print_MixerVersion();
|
||||||
|
|
||||||
|
if(!sound_disabled) {
|
||||||
/* Load up all the sounds. */
|
/* Load up all the sounds. */
|
||||||
sound_makeList();
|
sound_makeList();
|
||||||
sound_volume(0.4);
|
sound_volume(sound_defVolume);
|
||||||
|
|
||||||
/* Finish function. */
|
/* Finish function. */
|
||||||
Mix_ChannelFinished(voice_markStopped);
|
Mix_ChannelFinished(voice_markStopped);
|
||||||
|
}
|
||||||
|
|
||||||
/* Init the music. */
|
/* Init the music. */
|
||||||
music_init();
|
music_init();
|
||||||
|
|
||||||
/* Create the voice lock. */
|
|
||||||
voice_lock = SDL_CreateMutex();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +172,6 @@ void sound_exit(void) {
|
|||||||
|
|
||||||
/* Close the audio. */
|
/* Close the audio. */
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
SDL_DestroyMutex(voice_lock);
|
|
||||||
|
|
||||||
/* Free the voices. */
|
/* Free the voices. */
|
||||||
while(voice_active != NULL) {
|
while(voice_active != NULL) {
|
||||||
@ -414,6 +412,7 @@ void sound_stop(int voice) {
|
|||||||
* @sa sound_playPos
|
* @sa sound_playPos
|
||||||
*/
|
*/
|
||||||
int sound_updateListener(double dir, double x, double y) {
|
int sound_updateListener(double dir, double x, double y) {
|
||||||
|
if(sound_disabled) return 0;
|
||||||
sound_pos[0] = x;
|
sound_pos[0] = x;
|
||||||
sound_pos[1] = y;
|
sound_pos[1] = y;
|
||||||
sound_pos[2] = dir/M_PI*180.;
|
sound_pos[2] = dir/M_PI*180.;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern int sound_disabled;
|
extern int sound_disabled;
|
||||||
|
extern double sound_defVolume;
|
||||||
|
|
||||||
/* Sound subsystem. */
|
/* Sound subsystem. */
|
||||||
int sound_init(void);
|
int sound_init(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user