/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/EnginePlugins/FmodPlugin/Resources/FmodSoundEventResourceLoader.cpp
105 строк
3 KB
Jan Krassnigg
GAL improvements (#1422)
05 ноя 2024, 22:46
Не верифицирован
05 ноя 2024, 22:46
0e9f0e4
Код
Авторство
О чём код?
#include <FmodPlugin/FmodPluginPCH.h> #include <FmodPlugin/FmodIncludes.h> #include <FmodPlugin/FmodSingleton.h> #include <FmodPlugin/Resources/FmodSoundBankResource.h> #include <FmodPlugin/Resources/FmodSoundEventResource.h> #include <Foundation/IO/FileSystem/FileSystem.h> ezResourceLoadData ezFmodSoundEventResourceLoader::OpenDataStream(const ezResource* pResource) { EZ_LOG_BLOCK("ezFmodSoundEventResourceLoader::OpenDataStream", pResource->GetResourceID()); LoadedData* pData = EZ_DEFAULT_NEW(LoadedData); ezResourceLoadData res; if (ezFmod::GetSingleton()->GetStudioSystem() == nullptr) { ezLog::Warning("FMOD not initialized, ignoring sound event."); return res; } ezStringBuilder sResID; ezFileSystem::ResolveAssetRedirection(pResource->GetResourceID(), sResID); const char* szSeperator = sResID.FindSubString("|"); if (szSeperator == nullptr) { ezLog::Error("FMOD event resource ID is invalid or could not be resolved: '{0}'", sResID); return res; } ezStringBuilder sBankPath, sSubPath; sBankPath.SetSubString_FromTo(sResID, szSeperator); sSubPath = szSeperator + 1; pData->m_hSoundBank = ezResourceManager::LoadResource<ezFmodSoundBankResource>(sBankPath); // make sure the sound bank is fully loaded before trying to get the event descriptor (even though we go through the FMOD 'system' the // bank resource must be loaded first) { ezResourceLock<ezFmodSoundBankResource> pBank(pData->m_hSoundBank, ezResourceAcquireMode::BlockTillLoaded); if (ezConversionUtils::IsStringUuid(sSubPath)) { const ezUuid guid = ezConversionUtils::ConvertStringToUuid(sSubPath); const FMOD_GUID* fmodGuid = reinterpret_cast<const FMOD_GUID*>(&guid); if (ezFmod::GetSingleton()->GetStudioSystem()->getEventByID(fmodGuid, &pData->m_pEventDescription) != FMOD_OK) { ezLog::Error("FMOD event could not be found. GUID: '{0}'", sSubPath); return res; } } else { if (ezFmod::GetSingleton()->GetStudioSystem()->getEvent(sSubPath.GetData(), &pData->m_pEventDescription) != FMOD_OK) { ezLog::Error("FMOD event could not be found. Path: '{0}'", sSubPath); return res; } } } // make sure to load the sample data (on this thread) if (pData->m_pEventDescription->loadSampleData() != FMOD_OK) { ezLog::Error("FMOD event sample data could not be loaded. Event: '{0}'", sSubPath); return res; } ezFmodSoundBankResourceHandle* pHandle = &pData->m_hSoundBank; ezMemoryStreamWriter w(&pData->m_Storage); w.WriteBytes(&pHandle, sizeof(ezFmodSoundBankResourceHandle*)).IgnoreResult(); w.WriteBytes(&pData->m_pEventDescription, sizeof(FMOD::Studio::EventDescription*)).IgnoreResult(); res.m_pDataStream = &pData->m_Reader; res.m_pCustomLoaderData = pData; return res; } void ezFmodSoundEventResourceLoader::CloseDataStream(const ezResource* pResource, const ezResourceLoadData& loaderData) { LoadedData* pData = (LoadedData*)loaderData.m_pCustomLoaderData; EZ_DEFAULT_DELETE(pData); } bool ezFmodSoundEventResourceLoader::IsResourceOutdated(const ezResource* pResource) const { #if EZ_ENABLED(EZ_COMPILE_FOR_DEVELOPMENT) // if the sound bank ever gets reloaded, the sound events may be invalid, so always reload all events /// \todo not sure whether this can be reduced to only reloading when the bank is outdated return true; #else return false; // we cannot reload these resources without overhead, so only allow this during development #endif }