Skip to content

Commit

Permalink
Add the logic for getting --sfx-volume for later
Browse files Browse the repository at this point in the history
  • Loading branch information
lanodan committed Sep 22, 2018
1 parent 54b7126 commit 24b105f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/game/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class base : public mode {
struct oshu_sound_library library {};
struct oshu_clock clock {};
int autoplay {};
int sfx_volume {};
bool paused {};
/**
* Pointer to the next clickable hit.
Expand Down
17 changes: 15 additions & 2 deletions src/oshu/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum option_values {
OPT_PAUSE = 0x10001,
OPT_VERBOSE = 'v',
OPT_VERSION = 0x10002,
OPT_SFX_VOLUME = 0x10003,
};

static struct option options[] = {
Expand All @@ -42,6 +43,7 @@ static struct option options[] = {
{"pause", no_argument, 0, OPT_PAUSE},
{"verbose", no_argument, 0, OPT_VERBOSE},
{"version", no_argument, 0, OPT_VERSION},
{"sfx-volume", required_argument, 0, OPT_SFX_VOLUME},
{0, 0, 0, 0},
};

Expand Down Expand Up @@ -80,7 +82,7 @@ static void signal_handler(int signum)
w->close();
}

int run(const char *beatmap_path, int autoplay, int pause)
int run(const char *beatmap_path, int autoplay, int pause, int sfx_volume)
{
int rc = 0;

Expand All @@ -92,6 +94,7 @@ int run(const char *beatmap_path, int autoplay, int pause)
try {
osu_game game(beatmap_path);
game.autoplay = autoplay;
game.sfx_volume = sfx_volume;
if (pause)
game.pause();

Expand All @@ -113,6 +116,7 @@ int main(int argc, char **argv)
{
int autoplay = 0;
int pause = 0;
int sfx_volume = 100;

for (;;) {
int c = getopt_long(argc, argv, flags, options, NULL);
Expand All @@ -135,6 +139,15 @@ int main(int argc, char **argv)
case OPT_VERSION:
fputs(version, stdout);
return 0;
case OPT_SFX_VOLUME:
sfx_volume = atoi(optarg);
if(!( (0 <= sfx_volume) && (sfx_volume <= 100) )) {
/* TODO: Make a clearer error message? */
fputs("`--sfx-volume' argument isn't in [0..100] exiting!\n", stderr);
return 1;
} else {
break;
}
default:
fputs(usage, stderr);
return 2;
Expand Down Expand Up @@ -171,7 +184,7 @@ int main(int argc, char **argv)
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);

if (run(beatmap_file, autoplay, pause) < 0) {
if (run(beatmap_file, autoplay, pause, sfx_volume) < 0) {
if (!isatty(fileno(stdout)))
SDL_ShowSimpleMessageBox(
SDL_MESSAGEBOX_ERROR,
Expand Down

0 comments on commit 24b105f

Please sign in to comment.