Added magic_enum as a dependency. Tweaked ErrorHandling
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "lib/miniaudio"]
|
||||
path = lib/miniaudio
|
||||
url = https://github.com/mackron/miniaudio
|
||||
[submodule "lib/magic_enum"]
|
||||
path = lib/magic_enum
|
||||
url = https://github.com/Neargye/magic_enum
|
||||
|
||||
@@ -9,7 +9,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-subobject-linkage")
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
|
||||
endif()
|
||||
|
||||
add_subdirectory(lib/miniaudio)
|
||||
add_subdirectory(lib/magic_enum)
|
||||
|
||||
find_package(Corrade REQUIRED Main)
|
||||
find_package(Magnum REQUIRED)
|
||||
|
||||
1
lib/magic_enum
Submodule
1
lib/magic_enum
Submodule
Submodule lib/magic_enum added at ec5734e491
@@ -1,4 +1,6 @@
|
||||
#include "ChargeAudio.hpp"
|
||||
#include "magic_enum/include/magic_enum/magic_enum.hpp"
|
||||
#include <Corrade/Utility/Debug.h>
|
||||
#include <stdexcept>
|
||||
|
||||
void ChargeAudio::ThrowOnRuntimeError(std::string message,
|
||||
@@ -7,6 +9,7 @@ void ChargeAudio::ThrowOnRuntimeError(std::string message,
|
||||
return;
|
||||
}
|
||||
|
||||
Utility::Error{} << message << " (" << errorType << ")";
|
||||
throw new std::runtime_error(message + ". Check STDERR for more info.\n");
|
||||
Utility::Error{} << message.c_str()
|
||||
<< magic_enum::enum_name(errorType).data();
|
||||
throw new std::runtime_error(message + " Check STDERR for more info.\n");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ Sound::Sound(Engine *engine, std::function<void(Sound *)> setupFunction,
|
||||
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
|
||||
maConfig.endCallback = Sound::onSoundFinish;
|
||||
maConfig.pEndCallbackUserData = this;
|
||||
|
||||
setupFunction(this);
|
||||
|
||||
ma_result maResponse =
|
||||
ma_sound_init_ex(&baseEngine->maEngine, &maConfig, &maSound);
|
||||
ThrowOnRuntimeError("Failed to create a new sound. " + additionalErrorMessage,
|
||||
@@ -63,18 +65,20 @@ bool Sound::SetPlaybackTime(float time) {
|
||||
|
||||
// Controls
|
||||
void Sound::Play() {
|
||||
ma_sound_start(&maSound);
|
||||
ThrowOnRuntimeError("Failed to start the sound.", ma_sound_start(&maSound));
|
||||
state = Sound::SoundState::Playing;
|
||||
}
|
||||
|
||||
void Sound::Pause() {
|
||||
ma_sound_stop(&maSound);
|
||||
ThrowOnRuntimeError("Failed to pause the sound.", ma_sound_stop(&maSound));
|
||||
state = Sound::SoundState::Paused;
|
||||
}
|
||||
|
||||
void Sound::Reset() {
|
||||
if (type == SoundType::StreamedRawPCM) {
|
||||
ThrowOnRuntimeError("You cannot reset on Streamed RawPCM sounds!");
|
||||
ThrowOnRuntimeError(
|
||||
"You cannot reset on Streamed RawPCM sounds! Since the buffer is a "
|
||||
"ring buffer there isn't a \"start\" to return to.");
|
||||
}
|
||||
|
||||
ma_sound_seek_to_pcm_frame(&maSound, 0);
|
||||
|
||||
Reference in New Issue
Block a user