Skip to content

Commit 3378809

Browse files
committed
Adding CLArgs --music_volume and --sfx_volume and improving help page formatting.
1 parent 20bee15 commit 3378809

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

Pilot_Episode/pilot_episode.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@
9393
class Game : public t8x::GameEngine<>
9494
{
9595
public:
96-
Game(int argc, char** argv, const t8x::GameEngineParams& params, bool use_audio)
96+
Game(int argc, char** argv, const t8x::GameEngineParams& params,
97+
bool use_audio, float music_volume, float sfx_volume)
9798
: GameEngine(argv[0], params)
9899
, enable_audio(use_audio)
99100
, audio(use_audio)
101+
, volume_music(music_volume)
102+
, volume_sfx(sfx_volume)
100103
{
101104
//#ifndef _WIN32
102105
GameEngine::set_real_fps(15);
@@ -194,6 +197,7 @@ class Game : public t8x::GameEngine<>
194197
if (enable_audio && chip_tune.load_tune(folder::join_path({ tune_path, "chiptune2.ct" })))
195198
{
196199
//chip_tune.play_tune();
200+
chip_tune.set_volume(volume_music);
197201
chip_tune.play_tune_async();
198202
chip_tune.wait_for_completion();
199203
}
@@ -206,8 +210,13 @@ class Game : public t8x::GameEngine<>
206210
if (enable_audio)
207211
{
208212
src_fx_0 = audio.create_source();
213+
src_fx_0->set_volume(volume_sfx);
214+
209215
src_fx_1 = audio.create_source();
216+
src_fx_1->set_volume(volume_sfx);
217+
210218
src_fx_2 = audio.create_source();
219+
src_fx_2->set_volume(volume_sfx);
211220
}
212221

213222
std::string font_data_path = t8x::get_path_to_font_data(get_exe_folder());
@@ -461,6 +470,8 @@ class Game : public t8x::GameEngine<>
461470
beat::AudioSource* src_fx_0 = nullptr;
462471
beat::AudioSource* src_fx_1 = nullptr;
463472
beat::AudioSource* src_fx_2 = nullptr;
473+
float volume_music = 0.5f;
474+
float volume_sfx = 0.5f;
464475

465476
std::vector<t8x::ColorScheme> color_schemes;
466477
t8x::FontDataColl font_data;
@@ -483,6 +494,8 @@ int main(int argc, char** argv)
483494

484495
bool use_audio = true;
485496
bool show_help = false;
497+
float music_volume = 0.5f;
498+
float sfx_volume = 0.5f;
486499

487500
for (int i = 1; i < argc; ++i)
488501
{
@@ -500,23 +513,41 @@ int main(int argc, char** argv)
500513
}
501514
else if (std::strcmp(argv[i], "--disable_audio") == 0)
502515
use_audio = false;
516+
else if (std::strcmp(argv[i], "--music_volume") == 0)
517+
music_volume = static_cast<float>(std::atof(argv[i + 1]));
518+
else if (std::strcmp(argv[i], "--sfx_volume") == 0)
519+
sfx_volume = static_cast<float>(std::atof(argv[i + 1]));
503520
else if (std::strcmp(argv[i], "--help") == 0)
504521
show_help = true;
505522
}
506523

507524
if (show_help)
508525
use_audio = false;
509526

510-
Game game(argc, argv, params, use_audio);
527+
Game game(argc, argv, params,
528+
use_audio, std::clamp(music_volume, 0.f, 1.f), std::clamp(sfx_volume, 0.f, 1.f));
511529

512530
if (show_help)
513531
{
514-
std::cout << "pilot_episode --help | [--log_mode (record | replay)] [--suppress_tty_output] [--suppress_tty_input] [--altitude_start_km <altitude_km>] [--disable_altitude_limiting] [--set_fps <fps>] [--set_sim_delay_us <delay_us>] [--disable_audio]" << std::endl;
532+
std::cout << "pilot_episode --help |" << std::endl;
533+
std::cout << " [--log_mode (record | replay)]" << std::endl;
534+
std::cout << " [--suppress_tty_output]" << std::endl;
535+
std::cout << " [--suppress_tty_input]" << std::endl;
536+
std::cout << " [--altitude_start_km <altitude_km>]" << std::endl;
537+
std::cout << " [--disable_altitude_limiting]" << std::endl;
538+
std::cout << " [--set_fps <fps>]" << std::endl;
539+
std::cout << " [--set_sim_delay_us <delay_us>]" << std::endl;
540+
std::cout << " [--disable_audio]" << std::endl;
541+
std::cout << " [--music_volume <music_vol>]" << std::endl;
542+
std::cout << " [--sfx_volume <sfx_vol>]" << std::endl;
543+
std::cout << std::endl;
515544
std::cout << " default values:" << std::endl;
516545
// Will unfortunately report the wrong default value for <altitude_km> if ordering the arguments like this "--altitude_start_km <altitude_km> --help".
517546
std::cout << " <altitude_km> : " << game.get_alt_km() << std::endl;
518547
std::cout << " <fps> : " << game.get_real_fps() << std::endl;
519548
std::cout << " <delay_us> : " << game.get_sim_delay_us() << std::endl;
549+
std::cout << " <music_vol> : " << music_volume << " (valid range: [0, 1])" <<std::endl;
550+
std::cout << " <sfx_vol> : " << sfx_volume << " (valid range: [0, 1])" <<std::endl;
520551
return EXIT_SUCCESS;
521552
}
522553

0 commit comments

Comments
 (0)