123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #include "AkInitBank.h"
- #include "Platforms/AkPlatformInfo.h"
- #include "Wwise/WwiseResourceLoader.h"
- #include "Wwise/Stats/AkAudio.h"
- #if WITH_EDITORONLY_DATA
- #include "Wwise/WwiseResourceCooker.h"
- #endif
- #if WITH_EDITORONLY_DATA
- void UAkInitBank::CookAdditionalFilesOverride(const TCHAR* PackageFilename, const ITargetPlatform* TargetPlatform,
- TFunctionRef<void(const TCHAR* Filename, void* Data, int64 Size)> WriteAdditionalFile)
- {
- auto* ResourceCooker = FWwiseResourceCooker::GetForPlatform(TargetPlatform);
- if (!ResourceCooker)
- {
- return;
- }
- ResourceCooker->SetSandboxRootPath(PackageFilename);
- ResourceCooker->CookInitBank(FWwiseObjectInfo::DefaultInitBank, WriteAdditionalFile);
- }
- void UAkInitBank::BeginCacheForCookedPlatformData(const ITargetPlatform* TargetPlatform)
- {
- auto PlatformID = UAkPlatformInfo::GetSharedPlatformInfo(TargetPlatform->IniPlatformName());
- FWwiseResourceCooker::CreateForPlatform(TargetPlatform, PlatformID, EWwiseExportDebugNameRule::Name);
- }
- #endif
- void UAkInitBank::Serialize(FArchive& Ar)
- {
- bAutoLoad = false;
- Super::Serialize(Ar);
- if (HasAnyFlags(RF_ClassDefaultObject))
- {
- return;
- }
- #if !UE_SERVER
- #if WITH_EDITORONLY_DATA
- if (Ar.IsCooking() && Ar.IsSaving() && !Ar.CookingTarget()->IsServerOnly())
- {
- FWwiseInitBankCookedData CookedDataToArchive;
- if (auto* ResourceCooker = FWwiseResourceCooker::GetForArchive(Ar))
- {
- ResourceCooker->PrepareCookedData(CookedDataToArchive, FWwiseObjectInfo::DefaultInitBank);
- }
- CookedDataToArchive.Serialize(Ar);
- }
- #else
- InitBankCookedData.Serialize(Ar);
- #endif
- #endif
- }
- void UAkInitBank::UnloadInitBank(bool bAsync)
- {
- if (LoadedInitBank)
- {
- auto* ResourceLoader = FWwiseResourceLoader::Get();
- if (UNLIKELY(!ResourceLoader))
- {
- return;
- }
- if (bAsync)
- {
- FWwiseLoadedInitBankPromise Promise;
- Promise.EmplaceValue(MoveTemp(LoadedInitBank));
- ResourceUnload = ResourceLoader->UnloadInitBankAsync(Promise.GetFuture());
- }
- else
- {
- ResourceLoader->UnloadInitBank(MoveTemp(LoadedInitBank));
- }
- LoadedInitBank = nullptr;
- }
- }
- #if WITH_EDITORONLY_DATA
- void UAkInitBank::PrepareCookedData()
- {
- if (IWwiseProjectDatabaseModule::IsInACookingCommandlet())
- {
- return;
- }
- auto* ResourceCooker = FWwiseResourceCooker::GetDefault();
- if (UNLIKELY(!ResourceCooker))
- {
- return;
- }
- if (UNLIKELY(!ResourceCooker->PrepareCookedData(InitBankCookedData, FWwiseObjectInfo::DefaultInitBank)))
- {
- return;
- }
- }
- #endif
- TArray<FWwiseLanguageCookedData> UAkInitBank::GetLanguages()
- {
- #if WITH_EDITORONLY_DATA
- PrepareCookedData();
- #endif
- return InitBankCookedData.Language;
- }
- void UAkInitBank::UnloadData(bool bAsync)
- {
- UnloadInitBank(bAsync);
- }
- void UAkInitBank::LoadInitBank()
- {
- SCOPED_AKAUDIO_EVENT_2(TEXT("LoadInitBank"));
- auto* ResourceLoader = FWwiseResourceLoader::Get();
- if (UNLIKELY(!ResourceLoader))
- {
- return;
- }
- if (LoadedInitBank)
- {
- UnloadInitBank(false);
- }
- #if WITH_EDITORONLY_DATA
- PrepareCookedData();
- #endif
- LoadedInitBank = ResourceLoader->LoadInitBank(InitBankCookedData);
- }
- #if WITH_EDITORONLY_DATA
- void UAkInitBank::MigrateWwiseObjectInfo()
- {
-
- }
- FWwiseObjectInfo* UAkInitBank::GetInfoMutable()
- {
- return new FWwiseObjectInfo(FWwiseObjectInfo::DefaultInitBank.WwiseGuid, FWwiseObjectInfo::DefaultInitBank.WwiseShortId, FWwiseObjectInfo::DefaultInitBank.WwiseName);
- }
- #endif
|