Volume setting

This commit is contained in:
Mark Suckerberg
2025-12-30 13:15:50 -06:00
parent b5568d5493
commit c30a9e3520
6 changed files with 22 additions and 1 deletions

View File

@@ -8,5 +8,6 @@ namespace game
{
public:
MeasurementSystem measurementSystem{MeasurementSystem::METRIC};
int volume{100};
};
}

View File

@@ -12,6 +12,12 @@ namespace game::resource
return mixer;
}
void Audio::set_gain(float gain)
{
auto mixer = mixer_get();
MIX_SetMasterGain(mixer, gain);
}
void Audio::retain()
{
if (refCount) ++(*refCount);

View File

@@ -10,7 +10,7 @@ namespace game::resource
MIX_Audio* internal{nullptr};
MIX_Track* track{nullptr};
int* refCount{nullptr};
MIX_Mixer* mixer_get();
static MIX_Mixer* mixer_get();
void unload();
void retain();
void release();
@@ -27,5 +27,6 @@ namespace game::resource
void play(bool isLoop = false);
void stop();
bool is_playing() const;
static void set_gain(float vol);
};
}

View File

@@ -21,4 +21,8 @@ namespace game
}
void Resources::sound_play(audio::Type type) { audio[type].play(); }
void Resources::set_audio_gain(float vol) {
Audio::set_gain(vol);
}
}

View File

@@ -124,5 +124,6 @@ namespace game
Resources();
void sound_play(audio::Type);
void set_audio_gain(float vol);
};
}

View File

@@ -6,6 +6,7 @@ namespace game::window
ImVec2 pos)
{
MeasurementSystem& measurementSystem = gameData.measurementSystem;
int& volume = gameData.volume;
ImGui::SetNextWindowSize(size);
ImGui::SetNextWindowPos(pos);
@@ -48,6 +49,13 @@ namespace game::window
ImGui::RadioButton("Metric", (int*)&measurementSystem, MeasurementSystem::METRIC);
ImGui::SameLine();
ImGui::RadioButton("Imperial", (int*)&measurementSystem, MeasurementSystem::IMPERIAL);
ImGui::SeparatorText("Sound");
if (ImGui::SliderInt("Volume", (int*)&volume, 0, 100))
{
resources.set_audio_gain((float)volume / 100);
}
ImGui::EndTabItem();
}