Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
damiencarol committed Mar 13, 2024
1 parent 9aaa8ac commit 4bcc86f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 84 deletions.
8 changes: 5 additions & 3 deletions src/engine/audio/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ void physfsReloadMusic_helper_reloadMusicArray(uint32_t numMusic, const char* fi
}*/

} else {
printlog("[PhysFS]: fail to load music file %s...", tempstr);
printlog("[OpenAL]: fail to load music file %s...", tempstr);
}
}
}
Expand Down Expand Up @@ -1850,11 +1850,13 @@ void physfsReloadMusic(bool &introMusicChanged, bool reloadAll) //TODO: This sho
physfsReloadMusic_helper_reloadMusicArray(NUMINTROMUSIC, "music/intro%02d.ogg", music, reloadAll);
}
introChanged = true;
/*if (fmod_result != FMOD_OK)
#ifdef USE_FMOD
if (fmod_result != FMOD_OK)
{
printlog("[PhysFS]: ERROR: Failed reloading music file \"%s\".");
break; //TODO: Handle the error?
}*/
}
#endif
}
}
}
Expand Down
83 changes: 2 additions & 81 deletions src/ui/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4469,18 +4469,16 @@ namespace MainMenu {

struct AudioDriver {
char name[64];
#if defined(USE_FMOD)
#ifdef USE_FMOD
FMOD_GUID guid;
int system_rate;
FMOD_SPEAKERMODE speaker_mode;
int speaker_mode_channels;
#endif
#if defined(USE_OPENAL)
#endif
};
static std::vector<AudioDriver> audio_drivers;

#if defined(USE_FMOD)
#ifdef USE_FMOD
static void settingsAudioDevice(Button& button) {
settingsOpenDropdown(button, "device", DropdownType::Wide, [](Frame::entry_t& entry){
soundActivate();
Expand Down Expand Up @@ -4529,35 +4527,6 @@ namespace MainMenu {
});
}
#endif
#ifdef USE_OPENAL
static void settingsAudioDevice(Button& button) {
settingsOpenDropdown(button, "device", DropdownType::Wide, [](Frame::entry_t& entry){
soundActivate();

// store driver
/*
unsigned int index; memcpy(&index, &entry.data, sizeof(index));
if (index < audio_drivers.size()) {
const auto& driver = audio_drivers[index];
uint32_t _1; memcpy(&_1, &driver.guid.Data1, sizeof(_1));
uint64_t _2; memcpy(&_2, &driver.guid.Data4, sizeof(_2));
char guid_string[25];
snprintf(guid_string, sizeof(guid_string), FMOD_AUDIO_GUID_FMT, _1, _2);
allSettings.audio_device = guid_string;
fmod_system->setDriver(index);
}
*/

auto settings = main_menu_frame->findFrame("settings"); assert(settings);
auto settings_subwindow = settings->findFrame("settings_subwindow"); assert(settings_subwindow);
auto button = settings_subwindow->findButton("setting_device_dropdown_button"); assert(button);
auto dropdown = settings_subwindow->findFrame("setting_device_dropdown"); assert(dropdown);
button->setText(entry.name.c_str());
dropdown->removeSelf();
button->select();
});
}
#endif

static void settingsMkbHotbarLayout(Button& button) {
// deprecated
Expand Down Expand Up @@ -6406,54 +6375,6 @@ namespace MainMenu {
y += settingsAddDropdown(*settings_subwindow, y, "speaker_mode", Language::get(6140), Language::get(6150),
true, modes_ptrs, modes_ptrs[allSettings.speaker_mode], settingsAudioSpeakerMode);
}
#elif defined USE_OPENAL
audio_drivers.clear();

if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) { // Enumeration Extension Found
printlog("OpenAL support ALC_ENUMERATION_EXT extention.\n");
const ALCchar *devices_raw = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
num_drivers = openalGetNumberOfDevices(devices_raw);
printlog("number of device detected: %d", num_drivers);

audio_drivers.reserve(num_drivers);

// this is good, taken from offical doc but not very "CPP" way
const ALCchar *device = devices_raw, *next = devices_raw + 1;
size_t len = 0;

while (device && *device != '\0' && next && *next != '\0') {
len = strlen(device);
printlog("device detected: %s", device);

AudioDriver d;
memcpy(d.name, device, len+1);
audio_drivers.push_back(d);

//fprintf(stdout, "%s\n", device);
device += (len + 1);
next += (len + 2);
}

std::vector<const char*> drivers_formatted_ptrs;
drivers_formatted_ptrs.reserve(num_drivers);
for (auto& d : audio_drivers) {
drivers_formatted_ptrs.push_back(d.name);
}

// debug
drivers_formatted_ptrs.push_back(alGetString(AL_VENDOR));
drivers_formatted_ptrs.push_back(alGetString(AL_RENDERER));
drivers_formatted_ptrs.push_back(alGetString(AL_VERSION));

// add section "output"
y += settingsAddSubHeader(*settings_subwindow, y, "output", Language::get(5182));
if ( num_drivers > 0 )
{
y += settingsAddDropdown(*settings_subwindow, y, "device", Language::get(5183), Language::get(5184),
true, drivers_formatted_ptrs, drivers_formatted_ptrs[0], //selected_device],
settingsAudioDevice);
}
}
#endif

y += settingsAddSubHeader(*settings_subwindow, y, "volume", Language::get(5185));
Expand Down

0 comments on commit 4bcc86f

Please sign in to comment.