The three initialize methods of this class are very, very, very similar. I’d like to see if there’s a way to chain the calls together, potentially into the method that requires both arguments. Thanks.
AudioHandler.h
class AudioHandler {
public:
static bool Initialize(const SoundLibrary& sl);
static bool Initialize(const Soundtrack& st);
static bool Initialize(const SoundLibrary& sl, const Soundtrack& st);
static void Release();
private:
static const SoundLibrary* _sl;
static const Soundtrack* _st;
};
AudioHandler.cpp
bool AudioHandler::Initialize(const SoundLibrary& sl) {
if(_sl != NULL || _st != NULL) return false;
unsigned long numVoices = 0;
//If allegro is unable to initialize the sound drivers then return false.
if((numVoices = detect_digi_driver(DIGI_AUTODETECT)) == 0) return false;
if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1) return false;
_sl = &sl;
return true;
}
bool AudioHandler::Initialize(const Soundtrack& st) {
if(_sl != NULL || _st != NULL) return false;
if(detect_midi_driver(MIDI_AUTODETECT) == 0) return false;
if(install_sound(DIGI_NONE, MIDI_AUTODETECT, NULL) == -1) return false;
_st = &st;
return true;
}
bool AudioHandler::Initialize(const SoundLibrary& sl, const Soundtrack& st) {
if(_sl != NULL || _st != NULL) return false;
unsigned long numVoices = 0;
if((numVoices = detect_digi_driver(DIGI_AUTODETECT)) == 0) return false;
if(detect_midi_driver(MIDI_AUTODETECT) == 0) return false;
if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) == -1) return false;
_sl = &sl;
_st = &st;
return true;
}
void AudioHandler::Release() {
_sl = NULL;
_st = NULL;
remove_sound();
}
NULLfor the arguments you don’t need.NULLbefore doing specific code.PS: in your current version, storing the address of a passed reference in the object is not a good idea.