Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: --sfx-volume option #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a [0, 1] float here, and set its default value to 1.

bool paused {};
/**
* Pointer to the next clickable hit.
Expand Down
4 changes: 4 additions & 0 deletions share/man/oshu.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Perform a perfect run on the beatmap without any user interaction.
\fB\-\-pause\fR
Start the game in a paused state. Might be useful when you're starting the game
from a terminal as you won't be holding your mouse when the game starts.
.TP
\fB\-\-sfx\-volume\fR
Sets the volume of the effects (i.e hitsounds), minimum(~mute) is 0, maximum
is 100
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit more work, but I think --sfx-volume 50% is much clearer with the explicit %.


.SH CONTROLS
.PP
Expand Down
18 changes: 16 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 All @@ -59,6 +61,7 @@ static const char *help =
" --version Output version information.\n"
" --autoplay Perform a perfect run.\n"
" --pause Start the game paused.\n"
" --sfx-volume Changes the sound effects volume.\n"
"\n"
"Check the man page oshu(1) for details.\n"
;
Expand All @@ -79,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 @@ -91,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 @@ -112,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 @@ -134,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 @@ -170,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