[Add] Set volume with command line, volume is a little flaky at the min. :s.
This commit is contained in:
parent
a296bd7aa0
commit
b165e7b263
42
src/conf.c
42
src/conf.c
@ -11,6 +11,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
#include "music.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
#define conf_loadInt(n,i) \
|
#define conf_loadInt(n,i) \
|
||||||
@ -20,6 +21,13 @@ if(lua_isnumber(L, -1)) { \
|
|||||||
lua_remove(L, -1); \
|
lua_remove(L, -1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define conf_loadFloat(n,f) \
|
||||||
|
lua_getglobal(L,n); \
|
||||||
|
if(lua_isnumber(L, -1)) { \
|
||||||
|
f = (double)lua_tonumber(L, -1); \
|
||||||
|
lua_remove(L,-1);\
|
||||||
|
}
|
||||||
|
|
||||||
#define conf_loadBool(n,b) \
|
#define conf_loadBool(n,b) \
|
||||||
lua_getglobal(L,n); \
|
lua_getglobal(L,n); \
|
||||||
if(lua_isnumber(L, -1)) \
|
if(lua_isnumber(L, -1)) \
|
||||||
@ -54,6 +62,8 @@ static void print_usage(char** argv) {
|
|||||||
LOG("\t-d s, --data s - Set the data file to be s");
|
LOG("\t-d s, --data s - Set the data file to be s");
|
||||||
LOG("\t-j n, --joystick n - Use joystick (n)");
|
LOG("\t-j n, --joystick n - Use joystick (n)");
|
||||||
LOG("\t-J s, --joystick s - Use joystick whose name contains (s)");
|
LOG("\t-J s, --joystick s - Use joystick whose name contains (s)");
|
||||||
|
LOG("\t-m f, --music f - Set the music volume to f");
|
||||||
|
LOG("\t-s f, --sound f - Set the sound volume to f");
|
||||||
LOG("\t-h --help - Display this message and exit.");
|
LOG("\t-h --help - Display this message and exit.");
|
||||||
LOG("\t-v - Print the version and exit");
|
LOG("\t-v - Print the version and exit");
|
||||||
}
|
}
|
||||||
@ -76,6 +86,7 @@ void conf_setDefaults(void) {
|
|||||||
// Ok.. Parse a config file plox.
|
// Ok.. Parse a config file plox.
|
||||||
int conf_loadConfig(const char* file) {
|
int conf_loadConfig(const char* file) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
double d = 0.;
|
||||||
|
|
||||||
lua_State* L = luaL_newstate();
|
lua_State* L = luaL_newstate();
|
||||||
if(luaL_dofile(L, file) == 0) {
|
if(luaL_dofile(L, file) == 0) {
|
||||||
@ -87,18 +98,29 @@ int conf_loadConfig(const char* file) {
|
|||||||
conf_loadInt("width", gl_screen.w);
|
conf_loadInt("width", gl_screen.w);
|
||||||
conf_loadInt("height", gl_screen.h);
|
conf_loadInt("height", gl_screen.h);
|
||||||
conf_loadBool("fullscreen", i);
|
conf_loadBool("fullscreen", i);
|
||||||
if(i)gl_screen.flags |= OPENGL_FULLSCREEN;
|
if(i) { gl_screen.flags |= OPENGL_FULLSCREEN; i = 0; }
|
||||||
conf_loadBool("aa", i);
|
conf_loadBool("aa", i);
|
||||||
if(i)gl_screen.flags |= OPENGL_AA_POINT | OPENGL_AA_LINE || OPENGL_AA_POLYGON;
|
if(i) {
|
||||||
|
gl_screen.flags |= OPENGL_AA_POINT | OPENGL_AA_LINE || OPENGL_AA_POLYGON;
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
conf_loadBool("aa_point", i);
|
conf_loadBool("aa_point", i);
|
||||||
if(i)gl_screen.flags |= OPENGL_AA_POINT;
|
if(i) { gl_screen.flags |= OPENGL_AA_POINT; i = 0; }
|
||||||
conf_loadBool("aa_line", i)
|
conf_loadBool("aa_line", i)
|
||||||
if(i)gl_screen.flags |= OPENGL_AA_LINE;
|
if(i) { gl_screen.flags |= OPENGL_AA_LINE; i = 0; }
|
||||||
conf_loadBool("aa_polygon", i);
|
conf_loadBool("aa_polygon", i);
|
||||||
if(i)gl_screen.flags |= OPENGL_AA_POLYGON;
|
if(i) { gl_screen.flags |= OPENGL_AA_POLYGON; i = 0; }
|
||||||
|
|
||||||
|
// FPS.
|
||||||
conf_loadBool("showfps", show_fps);
|
conf_loadBool("showfps", show_fps);
|
||||||
conf_loadInt("maxfps", max_fps);
|
conf_loadInt("maxfps", max_fps);
|
||||||
|
|
||||||
|
// Sound.
|
||||||
|
conf_loadFloat("sound", d);
|
||||||
|
if(d) { sound_volume(d); d = 0.; }
|
||||||
|
conf_loadFloat("music", d);
|
||||||
|
if(d) { music_volume(d); d = 0.; }
|
||||||
|
|
||||||
// Joystick.
|
// Joystick.
|
||||||
lua_getglobal(L, "joystick");
|
lua_getglobal(L, "joystick");
|
||||||
if(lua_isnumber(L, -1)) {
|
if(lua_isnumber(L, -1)) {
|
||||||
@ -177,6 +199,8 @@ void conf_parseCLI(int argc, char** argv) {
|
|||||||
{ "data", required_argument, 0, 'd' },
|
{ "data", required_argument, 0, 'd' },
|
||||||
{ "joystick", required_argument, 0, 'j' },
|
{ "joystick", required_argument, 0, 'j' },
|
||||||
{ "Joystick", required_argument, 0, 'J' },
|
{ "Joystick", required_argument, 0, 'J' },
|
||||||
|
{ "music", required_argument, 0, 'm' },
|
||||||
|
{ "sound", required_argument, 0, 's' },
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ "version", no_argument, 0, 'v' },
|
{ "version", no_argument, 0, 'v' },
|
||||||
{ NULL, 0, 0, 0 }
|
{ NULL, 0, 0, 0 }
|
||||||
@ -184,7 +208,7 @@ void conf_parseCLI(int argc, char** argv) {
|
|||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
while((c = getopt_long(argc, argv, "fF:d:J:j:hv", long_options, &option_index)) != -1) {
|
while((c = getopt_long(argc, argv, "fF:d:J:j:sm:V:hv", long_options, &option_index)) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'f':
|
case 'f':
|
||||||
gl_screen.flags |= OPENGL_FULLSCREEN;
|
gl_screen.flags |= OPENGL_FULLSCREEN;
|
||||||
@ -201,6 +225,12 @@ void conf_parseCLI(int argc, char** argv) {
|
|||||||
case 'J':
|
case 'J':
|
||||||
namjoystick = strdup(optarg);
|
namjoystick = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'm':
|
||||||
|
music_volume(atof(optarg));
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
sound_volume(atof(optarg));
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
LOG(APPNAME": version %d.%d.%d", VMAJOR, VMINOR, VREV);
|
LOG(APPNAME": version %d.%d.%d", VMAJOR, VMINOR, VREV);
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -104,7 +104,6 @@ void land(Planet* p) {
|
|||||||
|
|
||||||
// Change music.
|
// Change music.
|
||||||
music_load(MUSIC_LAND);
|
music_load(MUSIC_LAND);
|
||||||
music_play();
|
|
||||||
|
|
||||||
planet = p;
|
planet = p;
|
||||||
land_wid = window_create(p->name, -1, -1, LAND_WIDTH, LAND_HEIGHT);
|
land_wid = window_create(p->name, -1, -1, LAND_WIDTH, LAND_HEIGHT);
|
||||||
|
17
src/music.c
17
src/music.c
@ -42,6 +42,9 @@ static ALuint music_source = 0;
|
|||||||
static char** music_selection = NULL;
|
static char** music_selection = NULL;
|
||||||
static int nmusic_selection = 0;
|
static int nmusic_selection = 0;
|
||||||
|
|
||||||
|
// Volume
|
||||||
|
static ALfloat mvolume = 1.;
|
||||||
|
|
||||||
// Vorbis suff.
|
// Vorbis suff.
|
||||||
static size_t ovpack_read(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
static size_t ovpack_read(void* ptr, size_t size, size_t nmemb, void* datasource) {
|
||||||
return (ssize_t) pack_read(datasource, ptr, size*nmemb);
|
return (ssize_t) pack_read(datasource, ptr, size*nmemb);
|
||||||
@ -161,6 +164,7 @@ int music_init(void) {
|
|||||||
|
|
||||||
alGenBuffers(2, music_buffer);
|
alGenBuffers(2, music_buffer);
|
||||||
alGenSources(1, &music_source);
|
alGenSources(1, &music_source);
|
||||||
|
alSourcef(music_source, AL_GAIN, mvolume);
|
||||||
alSourcef(music_source, AL_ROLLOFF_FACTOR, 0.);
|
alSourcef(music_source, AL_ROLLOFF_FACTOR, 0.);
|
||||||
alSourcei(music_source, AL_SOURCE_RELATIVE, AL_TRUE);
|
alSourcei(music_source, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||||
|
|
||||||
@ -251,12 +255,19 @@ static void music_free(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void music_volume(const double vol) {
|
void music_volume(const double vol) {
|
||||||
|
// Sanity check!
|
||||||
|
ALfloat fvol = ABS(vol);
|
||||||
|
if(fvol > 1.) fvol = 1.;
|
||||||
|
|
||||||
|
mvolume = fvol;
|
||||||
|
|
||||||
|
// Only needed if playing!
|
||||||
|
if(music_set(MUSIC_PLAYING)) {
|
||||||
SDL_mutexP(sound_lock);
|
SDL_mutexP(sound_lock);
|
||||||
|
alSourcef(music_source, AL_GAIN, fvol);
|
||||||
alSourcef(music_source, AL_GAIN, (ALfloat)vol);
|
|
||||||
|
|
||||||
SDL_mutexV(sound_lock);
|
SDL_mutexV(sound_lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Music control functions.
|
// Music control functions.
|
||||||
void music_load(const char* name) {
|
void music_load(const char* name) {
|
||||||
|
21
src/sound.c
21
src/sound.c
@ -51,6 +51,9 @@ static alVoice** voice_stack = NULL;
|
|||||||
static int nvoice_stack = 0;
|
static int nvoice_stack = 0;
|
||||||
static int mvoice_stack = 0;
|
static int mvoice_stack = 0;
|
||||||
|
|
||||||
|
// Volume.
|
||||||
|
static ALfloat svolume = 0.5;
|
||||||
|
|
||||||
static int sound_makeList(void);
|
static int sound_makeList(void);
|
||||||
static int sound_load(ALuint* buffer, char* filename);
|
static int sound_load(ALuint* buffer, char* filename);
|
||||||
static void sound_free(alSound* snd);
|
static void sound_free(alSound* snd);
|
||||||
@ -86,7 +89,7 @@ int sound_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the master gain.
|
// Set the master gain.
|
||||||
alListenerf(AL_GAIN, .5);
|
alListenerf(AL_GAIN, .1);
|
||||||
|
|
||||||
// Set the distance model.
|
// Set the distance model.
|
||||||
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
||||||
@ -240,6 +243,20 @@ void sound_update(void) {
|
|||||||
SDL_mutexV(sound_lock);
|
SDL_mutexV(sound_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set all the sounds volume to vol.
|
||||||
|
void sound_volume(const double vol) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
svolume = (ALfloat) vol;
|
||||||
|
|
||||||
|
SDL_mutexP(sound_lock);
|
||||||
|
for(i = 0; i < nvoice_stack; i++)
|
||||||
|
if(voice_set(voice_stack[i], VOICE_PLAYING))
|
||||||
|
alSourcef(voice_stack[i]->source, AL_GAIN, svolume);
|
||||||
|
SDL_mutexV(sound_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to alloc a source for a voice.
|
||||||
static int voice_getSource(alVoice* voc) {
|
static int voice_getSource(alVoice* voc) {
|
||||||
int ret;
|
int ret;
|
||||||
ALenum err;
|
ALenum err;
|
||||||
@ -265,7 +282,7 @@ static int voice_getSource(alVoice* voc) {
|
|||||||
alSourcef(voc->source, AL_REFERENCE_DISTANCE, 50.);
|
alSourcef(voc->source, AL_REFERENCE_DISTANCE, 50.);
|
||||||
|
|
||||||
alSourcei(voc->source, AL_SOURCE_RELATIVE, AL_FALSE);
|
alSourcei(voc->source, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||||
alSourcef(voc->source, AL_GAIN, 0.5);
|
alSourcef(voc->source, AL_GAIN, svolume);
|
||||||
alSource3f(voc->source, AL_POSITION, voc->px, voc->py, 0.);
|
alSource3f(voc->source, AL_POSITION, voc->px, voc->py, 0.);
|
||||||
//alSource3f(voc->source, AL_VELOCITY, voc->vx, voc->vy, 0.);
|
//alSource3f(voc->source, AL_VELOCITY, voc->vx, voc->vy, 0.);
|
||||||
if(voice_is(voc, VOICE_LOOPING))
|
if(voice_is(voc, VOICE_LOOPING))
|
||||||
|
@ -26,6 +26,7 @@ void sound_update(void);
|
|||||||
|
|
||||||
// Sound manupulation functions.
|
// Sound manupulation functions.
|
||||||
ALuint sound_get(char* name);
|
ALuint sound_get(char* name);
|
||||||
|
void sound_volume(const double vol);
|
||||||
|
|
||||||
// Voice manipulation function.
|
// Voice manipulation function.
|
||||||
alVoice* sound_addVoice(int priority, double px, double py, double vx, double vy,
|
alVoice* sound_addVoice(int priority, double px, double py, double vx, double vy,
|
||||||
|
Loading…
Reference in New Issue
Block a user