Changing initing to be more standardised(needs to be refactored)

This commit is contained in:
2025-09-07 22:39:17 +03:00
parent 71e4ff9317
commit 146bd49b36
3 changed files with 27 additions and 14 deletions

View File

@@ -1,14 +1,31 @@
#include "ChargeAudio.hpp"
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector3.h>
#include <stdexcept>
using namespace ChargeAudio;
Sound::Sound(Engine *engine) : baseEngine(engine) {}
Sound::Sound(Engine *engine) : baseEngine(engine) {
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
maConfig.endCallback = Sound::onSoundFinish;
maConfig.pEndCallbackUserData = this;
}
Sound::~Sound() { ma_sound_uninit(&maSound); }
Sound::SoundState Sound::GetState() { return state; }
void Sound::init(std::string additionalErrorMessage) {
ma_result maResponse =
ma_sound_init_ex(&baseEngine->maEngine, &maConfig, &maSound);
if (maResponse != MA_SUCCESS) {
Utility::Error{} << "Failed to create a new sound" << " (" << maResponse
<< ")";
throw new std::runtime_error(
"Failed to create a new sound. Check STDERR for more info.\n" +
additionalErrorMessage);
}
}
// Controls
void Sound::Play() {
ma_sound_start(&maSound);