diff --git a/include/game/game.h b/include/game/game.h index 2ffdb11..df784c5 100644 --- a/include/game/game.h +++ b/include/game/game.h @@ -50,6 +50,7 @@ struct oshu_game : public oshu::game::mode { struct oshu_clock clock {}; int stop {}; 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 73ca757..30702d4 100644 --- a/src/oshu/main.cc +++ b/src/oshu/main.cc @@ -33,6 +33,7 @@ enum option_values { OPT_PAUSE = 0x10001, OPT_VERBOSE = 'v', OPT_VERSION = 0x10002, + OPT_SFX_VOLUME = 0x10003, }; static struct option options[] = { @@ -41,6 +42,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}, }; @@ -79,7 +81,7 @@ static void signal_handler(int signum) oshu_stop_game(current_game.get()); } -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; @@ -90,7 +92,8 @@ int run(const char *beatmap_path, int autoplay, int pause) try { current_game = std::make_unique(beatmap_path); - current_game->autoplay = autoplay; + current_game->autoplay = autoplay; + current_game->sfx_volume = sfx_volume; if (pause) oshu_pause_game(current_game.get()); @@ -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,