automatically play setting_off_piano.opus when no other music is playing
This commit is contained in:
parent
14728d17f5
commit
932d5f629d
1
libs/SDL_mixer/external/opusfile/package_version
vendored
Normal file
1
libs/SDL_mixer/external/opusfile/package_version
vendored
Normal file
@ -0,0 +1 @@
|
||||
PACKAGE_VERSION="0.12"
|
||||
87
src/main.cpp
87
src/main.cpp
@ -2,6 +2,7 @@
|
||||
#include <stdint.h>
|
||||
#include <bit>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
@ -51,6 +52,12 @@ static Sint32 msaa_texture_width;
|
||||
static Sint32 msaa_texture_height;
|
||||
static SDL_GPUTexture *msaa_texture;
|
||||
|
||||
static Mix_Music *music_setting_off_piano;
|
||||
|
||||
static float volume_master = 100.0f;
|
||||
static float volume_music = 100.0f;
|
||||
static float volume_sfx = 100.0f;
|
||||
|
||||
static bool Running = true;
|
||||
|
||||
static float camera_fovy_degrees = 31.0f;
|
||||
@ -86,6 +93,11 @@ static V3 time_tints[MAX_TINT_TIMES] = {
|
||||
V3_(0.314f, 0.369f, 0.455f),
|
||||
};
|
||||
|
||||
enum Settings_Category {
|
||||
SETTINGS_UNKNOWN,
|
||||
SETTINGS_AUDIO,
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
V3 pos;
|
||||
};
|
||||
@ -1385,11 +1397,16 @@ int main(int argc, char **argv) {
|
||||
SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "wayland,x11");
|
||||
#endif
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD)) {
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD)) {
|
||||
log_error("Failed to initialize SDL (%s). Exiting.", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Mix_Init(MIX_INIT_OPUS)) {
|
||||
log_error("Failed to init SDL_mixer. Exiting.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
device = SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_SPIRV, true, NULL);
|
||||
if (!device) {
|
||||
log_error("Failed to create gpu device (%s). Exiting.", SDL_GetError());
|
||||
@ -1487,6 +1504,21 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_AudioSpec audio_spec = {
|
||||
.format = SDL_AUDIO_F32,
|
||||
.channels = 2,
|
||||
.freq = 48000,
|
||||
};
|
||||
|
||||
if (!Mix_OpenAudio(0, &audio_spec)) {
|
||||
log_error("Failed to open default audio device. Ignoring.");
|
||||
}
|
||||
|
||||
music_setting_off_piano = Mix_LoadMUS(ASSETS_PATH "music/setting_off_piano.opus");
|
||||
if (!music_setting_off_piano) {
|
||||
log_error("Failed to load music setting_off_piano.opus. Ignoring.");
|
||||
}
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGuiContext *imgui_context = ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
@ -1522,14 +1554,14 @@ int main(int argc, char **argv) {
|
||||
};
|
||||
time_tints_settings_handler.ReadLineFn = [](ImGuiContext *context, ImGuiSettingsHandler *handler, void *entry, const char *line) {
|
||||
if (entry == (void *)-1) {
|
||||
sscanf(line, "num=%d", &num_used_tint_times);
|
||||
SDL_sscanf(line, "num=%d", &num_used_tint_times);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "time", 4) == 0) {
|
||||
sscanf(line, "time=%d %d %d", &time_tints_times[(size_t)entry - 1][0], &time_tints_times[(size_t)entry - 1][1], &time_tints_times[(size_t)entry - 1][2]);
|
||||
SDL_sscanf(line, "time=%d %d %d", &time_tints_times[(size_t)entry - 1][0], &time_tints_times[(size_t)entry - 1][1], &time_tints_times[(size_t)entry - 1][2]);
|
||||
} else if(strncmp(line, "color", 5) == 0) {
|
||||
sscanf(line, "color=%g %g %g", &time_tints[(size_t)entry - 1][0], &time_tints[(size_t)entry - 1][1], &time_tints[(size_t)entry - 1][2]);
|
||||
SDL_sscanf(line, "color=%g %g %g", &time_tints[(size_t)entry - 1][0], &time_tints[(size_t)entry - 1][1], &time_tints[(size_t)entry - 1][2]);
|
||||
}
|
||||
};
|
||||
time_tints_settings_handler.WriteAllFn = [](ImGuiContext *context, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buffer) {
|
||||
@ -1544,6 +1576,37 @@ int main(int argc, char **argv) {
|
||||
};
|
||||
ImGui::AddSettingsHandler(&time_tints_settings_handler);
|
||||
|
||||
ImGuiSettingsHandler settings_handler = {};
|
||||
settings_handler.TypeName = "Settings";
|
||||
settings_handler.TypeHash = ImHashStr("Settings");
|
||||
settings_handler.ReadOpenFn = [](ImGuiContext *context, ImGuiSettingsHandler *handler, const char *name) -> void * {
|
||||
if (strcmp(name, "Audio") == 0)
|
||||
return (void *)SETTINGS_AUDIO;
|
||||
|
||||
return (void *)SETTINGS_UNKNOWN;
|
||||
};
|
||||
settings_handler.ReadLineFn = [](ImGuiContext *context, ImGuiSettingsHandler *handler, void *entry, const char *line) {
|
||||
if (entry == (void *)SETTINGS_AUDIO) {
|
||||
if (SDL_sscanf(line, "Master=%f", &volume_master) == 1) {
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
Mix_VolumeMusic (MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
}
|
||||
if (SDL_sscanf(line, "Music=%f", &volume_music) == 1)
|
||||
Mix_VolumeMusic(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
if (SDL_sscanf(line, "SFX=%f", &volume_sfx) == 1)
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
return;
|
||||
}
|
||||
};
|
||||
settings_handler.WriteAllFn = [](ImGuiContext *context, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buffer) {
|
||||
buffer->append("[Settings][Audio]\n");
|
||||
buffer->appendf("Master=%.0f\n", volume_master);
|
||||
buffer->appendf("Music=%.0f\n", volume_music);
|
||||
buffer->appendf("SFX=%.0f\n", volume_sfx);
|
||||
buffer->append("\n");
|
||||
};
|
||||
ImGui::AddSettingsHandler(&settings_handler);
|
||||
|
||||
bool first_frame = true;
|
||||
bool show_demo_window = false;
|
||||
bool show_tile_picker = false;
|
||||
@ -1605,6 +1668,18 @@ int main(int argc, char **argv) {
|
||||
if (show_settings) {
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 0), ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin("Settings", &show_settings)) {
|
||||
if (ImGui::DragFloat("Master", &volume_master, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
Mix_VolumeMusic (MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
};
|
||||
if (ImGui::DragFloat("Music", &volume_music, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
Mix_VolumeMusic(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_music / 100.0f));
|
||||
}
|
||||
if (ImGui::DragFloat("SFX", &volume_sfx, 1.0f, 0.0f, 100.0f, "%.0f", ImGuiSliderFlags_AlwaysClamp)) {
|
||||
Mix_MasterVolume(MIX_MAX_VOLUME * (volume_master / 100.0f) * (volume_sfx / 100.0f));
|
||||
}
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::DragFloat("fovy", &camera_fovy_degrees);
|
||||
ImGui::DragFloat("camera_distance", &camera_distance, 0.25f, 1.0f, INFINITY);
|
||||
ImGui::DragFloat("camera_tilt", &camera_tilt, 0.25f, 0.0f, 89.0f);
|
||||
@ -1950,6 +2025,10 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!Mix_PlayingMusic()) {
|
||||
Mix_PlayMusic(music_setting_off_piano, -1);
|
||||
}
|
||||
|
||||
if (!swapchain_texture) {
|
||||
SDL_CancelGPUCommandBuffer(command_buffer);
|
||||
ImGui::Render();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user