diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index b24b55af..0806e0c2 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_PATCH 5 -#define VERSION_BUILD 11523 +#define VERSION_BUILD 11541 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/olcPGEX_MiniAudio.h b/Adventures in Lestoria/olcPGEX_MiniAudio.h index 9fe8cb95..9027894a 100644 --- a/Adventures in Lestoria/olcPGEX_MiniAudio.h +++ b/Adventures in Lestoria/olcPGEX_MiniAudio.h @@ -158,7 +158,15 @@ namespace olc // this is where the sounds are kept std::vector vecSounds; std::vector vecOneOffSounds; - std::vector>vecResourcePackBuffers; + struct ResourceData{ + ma_engine*engine; + ResourceBuffer data; + std::string pathName; + ~ResourceData(){ + if(ma_resource_manager_unregister_data(ma_engine_get_resource_manager(engine),pathName.data())!=MA_SUCCESS)ERR(std::format("WARNING! Could not clear resources for {}!",pathName)); + }; + }; + std::unordered_mapvecResourceData; }; /** @@ -324,21 +332,11 @@ namespace olc if(!foundSound)vecSounds.emplace_back(sound); if(soundType==BGM){ - ma_audio_buffer newBuffer{}; - ResourceBuffer rb{game->gamepack.GetFileBuffer(path)}; - short*decodedOggFile; - int numSamples{stb_vorbis_decode_memory((const unsigned char*)(rb.vMemory.data()),rb.vMemory.size(),(int*)(&device.playback.channels),(int*)(&device.sampleRate),&decodedOggFile)}; - if(numSamples==-1)ERR(std::format("Failed to decode Ogg Vorbis file! {}",path)); - LOG(std::format("Samples: {}, Channels: {}, Sample Rate: {}",numSamples,device.playback.channels,device.sampleRate)); - ma_audio_buffer_config config{ma_audio_buffer_config_init(device.playback.format,device.playback.channels,numSamples,decodedOggFile,nullptr)}; - if(ma_audio_buffer_init(&config,&newBuffer)!=MA_SUCCESS)ERR(std::format("WARNING! Failed to load audio buffer~! {}",path)); - if(ma_sound_init_from_data_source(&engine,&newBuffer,MA_SOUND_FLAG_DECODE|MA_SOUND_FLAG_ASYNC,nullptr,sound)!=MA_SUCCESS)ERR(std::format("Could not initialize sound! {}",path)); - vecResourcePackBuffers.emplace_back(std::pair{id,newBuffer}); - }else{ //Sound effects - // load it from the file and decode it - if(ma_sound_init_from_file(&engine, path.c_str(), MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_ASYNC, NULL, NULL, sound) != MA_SUCCESS) - throw MiniAudioSoundException(); + vecResourceData[id]={&engine,game->gamepack.GetFileBuffer(path),path}; + if(ma_resource_manager_register_encoded_data(ma_engine_get_resource_manager(&engine),path.data(),vecResourceData[id].data.vMemory.data(),vecResourceData[id].data.vMemory.size())!=MA_SUCCESS)ERR(std::format("WARNING! Could not load resources for {}!",path)); } + if(ma_sound_init_from_file(&engine, path.c_str(), MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_ASYNC, NULL, NULL, sound) != MA_SUCCESS) + throw MiniAudioSoundException(); return id; } @@ -348,7 +346,7 @@ namespace olc ma_sound_uninit(vecSounds.at(id)); delete vecSounds.at(id); vecSounds.at(id) = nullptr; - std::erase_if(vecResourcePackBuffers,[&id](const std::pair&bufferData){return id==bufferData.first;}); + if(vecResourceData.count(id))vecResourceData.erase(id); } void MiniAudio::Play(const int id, const bool loop) diff --git a/Adventures in Lestoria/olcPixelGameEngine.h b/Adventures in Lestoria/olcPixelGameEngine.h index 23dfadf3..c9697e69 100644 --- a/Adventures in Lestoria/olcPixelGameEngine.h +++ b/Adventures in Lestoria/olcPixelGameEngine.h @@ -713,6 +713,7 @@ namespace olc // O------------------------------------------------------------------------------O struct ResourceBuffer : public std::streambuf { + ResourceBuffer(); ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size); std::vector vMemory; }; @@ -1794,6 +1795,7 @@ namespace olc //============================================================= // Resource Packs - Allows you to store files in one large // scrambled file - Thanks MaGetzUb for debugging a null char in std::stringstream bug + ResourceBuffer::ResourceBuffer(){} ResourceBuffer::ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size) { vMemory.resize(size); diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index c9e40011..515f7a88 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ