From 24b105f0b61172b80c23e43a93ca51d19ad84a81 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 22 Sep 2018 10:35:15 +0200 Subject: [PATCH] Add the logic for getting --sfx-volume for later --- include/game/base.h | 1 + src/oshu/main.cc | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/game/base.h b/include/game/base.h index d1fac63..e325d36 100644 --- a/include/game/base.h +++ b/include/game/base.h @@ -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. diff --git a/src/oshu/main.cc b/src/oshu/main.cc index 4ed2972..37d97e8 100644 --- a/src/oshu/main.cc +++ b/src/oshu/main.cc @@ -34,6 +34,7 @@ enum option_values { OPT_PAUSE = 0x10001, OPT_VERBOSE = 'v', OPT_VERSION = 0x10002, + OPT_SFX_VOLUME = 0x10003, }; static struct option options[] = { @@ -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}, }; @@ -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; @@ -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(); @@ -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); @@ -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; @@ -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,