From b958182073acb7c5a2082f5d596fe6ec1a78bdcb Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 19 Jan 2017 17:53:32 -1000 Subject: [PATCH] Work on CAudioSys, boo fixes --- Editor/ProjectResourceFactoryMP1.cpp | 2 + Runtime/Audio/CAudioGroupSet.hpp | 1 + Runtime/Audio/CAudioSys.cpp | 77 ++++++++++++++++++ Runtime/Audio/CAudioSys.hpp | 16 ++++ Runtime/Audio/CSfxManager.cpp | 26 +++++++ Runtime/Audio/CSfxManager.hpp | 1 + Runtime/Audio/CStreamAudioManager.cpp | 62 ++++++++------- Runtime/Audio/CStreamAudioManager.hpp | 2 +- Runtime/IMain.hpp | 2 +- Runtime/MP1/CPreFrontEnd.cpp | 23 +++++- Runtime/MP1/CPreFrontEnd.hpp | 1 + Runtime/MP1/MP1.cpp | 108 ++++++++++++++++++++++---- Runtime/MP1/MP1.hpp | 45 +++++++---- hecl | 2 +- 14 files changed, 301 insertions(+), 67 deletions(-) diff --git a/Editor/ProjectResourceFactoryMP1.cpp b/Editor/ProjectResourceFactoryMP1.cpp index 7133151b8..c1c6c35d3 100644 --- a/Editor/ProjectResourceFactoryMP1.cpp +++ b/Editor/ProjectResourceFactoryMP1.cpp @@ -20,6 +20,7 @@ #include "Runtime/CSaveWorld.hpp" #include "Runtime/AutoMapper/CMapWorld.hpp" #include "Audio/CAudioGroupSet.hpp" +#include "Audio/CSfxManager.hpp" #include "Runtime/CDependencyGroup.hpp" #include "DataSpec/DNACommon/TXTR.hpp" @@ -48,6 +49,7 @@ ProjectResourceFactoryMP1::ProjectResourceFactoryMP1(hecl::ClientProcess& client m_factoryMgr.AddFactory(FOURCC('DCLN'), FFactoryFunc(FCollidableOBBTreeGroupFactory)); m_factoryMgr.AddFactory(FOURCC('DGRP'), FFactoryFunc(FDependencyGroupFactory)); m_factoryMgr.AddFactory(FOURCC('AGSC'), FMemFactoryFunc(FAudioGroupSetDataFactory)); + m_factoryMgr.AddFactory(FOURCC('ATBL'), FFactoryFunc(FAudioTranslationTableFactory)); m_factoryMgr.AddFactory(FOURCC('STRG'), FFactoryFunc(FStringTableFactory)); m_factoryMgr.AddFactory(FOURCC('HINT'), FFactoryFunc(FHintFactory)); m_factoryMgr.AddFactory(FOURCC('SAVW'), FFactoryFunc(FSaveWorldFactory)); diff --git a/Runtime/Audio/CAudioGroupSet.hpp b/Runtime/Audio/CAudioGroupSet.hpp index cd4b2e95e..32615041a 100644 --- a/Runtime/Audio/CAudioGroupSet.hpp +++ b/Runtime/Audio/CAudioGroupSet.hpp @@ -21,6 +21,7 @@ class CAudioGroupSet public: CAudioGroupSet(std::unique_ptr&& in); const amuse::AudioGroupData& GetAudioGroupData() const {return m_data;} + const std::string& GetName() const { return x20_name; } }; CFactoryFnReturn FAudioGroupSetDataFactory(const urde::SObjectTag& tag, diff --git a/Runtime/Audio/CAudioSys.cpp b/Runtime/Audio/CAudioSys.cpp index 42a3ad071..0af737e10 100644 --- a/Runtime/Audio/CAudioSys.cpp +++ b/Runtime/Audio/CAudioSys.cpp @@ -1,8 +1,85 @@ #include "CAudioSys.hpp" +#include "CSimplePool.hpp" +#include "CAudioGroupSet.hpp" namespace urde { CAudioSys* CAudioSys::g_SharedSys = nullptr; +static std::unordered_map> mpGroupSetDB; +static std::unordered_map mpGroupSetResNameDB; +static const std::string mpDefaultInvalidString = "NULL"; + +TLockedToken CAudioSys::FindGroupSet(const std::string& name) +{ + auto search = mpGroupSetDB.find(name); + if (search == mpGroupSetDB.cend()) + return {}; + return search->second; +} + +const std::string& CAudioSys::SysGetGroupSetName(ResId id) +{ + auto search = mpGroupSetResNameDB.find(id); + if (search == mpGroupSetResNameDB.cend()) + return mpDefaultInvalidString; + return search->second; +} + +bool CAudioSys::SysLoadGroupSet(CSimplePool* pool, ResId id) +{ + if (!FindGroupSet(SysGetGroupSetName(id))) + { + TLockedToken set = pool->GetObj(SObjectTag{FOURCC('AGSC'), id}); + mpGroupSetDB.emplace(std::make_pair(set->GetName(), set)); + mpGroupSetResNameDB.emplace(std::make_pair(id, set->GetName())); + return false; + } + else + { + return true; + } +} + +bool CAudioSys::SysLoadGroupSet(const TLockedToken& set, const std::string& name, ResId id) +{ + if (!FindGroupSet(name)) + { + mpGroupSetDB.emplace(std::make_pair(set->GetName(), set)); + mpGroupSetResNameDB.emplace(std::make_pair(id, set->GetName())); + return false; + } + else + { + return true; + } +} + +void CAudioSys::SysUnloadAudioGroupSet(const std::string& name) +{ + auto set = FindGroupSet(name); + if (!set) + return; + + mpGroupSetResNameDB.erase(set.GetObjectTag()->id); + mpGroupSetDB.erase(name); +} + +bool CAudioSys::SysIsGroupSetLoaded(const std::string& name) +{ + return FindGroupSet(name).operator bool(); +} + +void CAudioSys::SysAddGroupIntoAmuse(const std::string& name) +{ + if (auto set = FindGroupSet(name)) + AddAudioGroup(set->GetAudioGroupData()); +} + +void CAudioSys::SysRemoveGroupFromAmuse(const std::string& name) +{ + if (auto set = FindGroupSet(name)) + RemoveAudioGroup(set->GetAudioGroupData()); +} } diff --git a/Runtime/Audio/CAudioSys.hpp b/Runtime/Audio/CAudioSys.hpp index 6b3d3150e..43014aba6 100644 --- a/Runtime/Audio/CAudioSys.hpp +++ b/Runtime/Audio/CAudioSys.hpp @@ -5,9 +5,17 @@ #include "zeus/CVector3f.hpp" #include "amuse/amuse.hpp" #include "boo/audiodev/IAudioVoiceEngine.hpp" +#include "RetroTypes.hpp" +#include "CToken.hpp" namespace urde { +class CSimplePool; +class CAudioGroupSet; + +CFactoryFnReturn FAudioTranslationTableFactory(const SObjectTag& tag, CInputStream& in, + const CVParamTransfer& vparms, + CObjectReference* selfRef); class CAudioSys { @@ -65,6 +73,14 @@ public: { } + static TLockedToken FindGroupSet(const std::string& name); + static const std::string& SysGetGroupSetName(ResId id); + static bool SysLoadGroupSet(CSimplePool* pool, ResId id); + static bool SysLoadGroupSet(const TLockedToken& set, const std::string& name, ResId id); + static void SysUnloadAudioGroupSet(const std::string& name); + static bool SysIsGroupSetLoaded(const std::string& name); + static void SysAddGroupIntoAmuse(const std::string& name); + static void SysRemoveGroupFromAmuse(const std::string& name); }; } diff --git a/Runtime/Audio/CSfxManager.cpp b/Runtime/Audio/CSfxManager.cpp index fb2c8de0a..dfef9f259 100644 --- a/Runtime/Audio/CSfxManager.cpp +++ b/Runtime/Audio/CSfxManager.cpp @@ -1,9 +1,24 @@ #include "CSfxManager.hpp" +#include "CSimplePool.hpp" namespace urde { +static TLockedToken> mpSfxTranslationTableTok; std::vector* CSfxManager::mpSfxTranslationTable = nullptr; +CFactoryFnReturn FAudioTranslationTableFactory(const SObjectTag& tag, CInputStream& in, + const CVParamTransfer& vparms, + CObjectReference* selfRef) +{ + std::unique_ptr> obj = std::make_unique>(); + u32 count = in.readUint32Big(); + obj->reserve(count); + for (u32 i=0 ; ipush_back(in.readUint16Big()); + CSimplePool* sp = vparms.GetOwnedObj(); + return TToken>::GetIObjObjectFor(std::move(obj)); +} + CSfxManager::CSfxChannel CSfxManager::m_channels[4]; rstl::reserved_vector, 128> CSfxManager::m_emitterWrapperPool; rstl::reserved_vector, 128> CSfxManager::m_wrapperPool; @@ -19,6 +34,17 @@ u16 CSfxManager::kMedPriority; u16 CSfxManager::kInternalInvalidSfxId; u32 CSfxManager::kAllAreas; +bool CSfxManager::LoadTranslationTable(CSimplePool* pool, const SObjectTag* tag) +{ + if (!tag) + return false; + mpSfxTranslationTableTok = pool->GetObj(*tag); + if (!mpSfxTranslationTableTok) + return false; + mpSfxTranslationTable = mpSfxTranslationTableTok.GetObj(); + return true; +} + bool CSfxManager::CSfxWrapper::IsPlaying() const { if (CBaseSfxWrapper::IsPlaying() && x1c_voiceHandle) diff --git a/Runtime/Audio/CSfxManager.hpp b/Runtime/Audio/CSfxManager.hpp index 7da8bad1d..a1bd1b82f 100644 --- a/Runtime/Audio/CSfxManager.hpp +++ b/Runtime/Audio/CSfxManager.hpp @@ -144,6 +144,7 @@ public: static u16 kInternalInvalidSfxId; static u32 kAllAreas; + static bool LoadTranslationTable(CSimplePool* pool, const SObjectTag* tag); static bool IsAuxProcessingEnabled() { return m_auxProcessingEnabled; } static void SetChannel(ESfxChannels) {} static void KillAll(ESfxChannels) {} diff --git a/Runtime/Audio/CStreamAudioManager.cpp b/Runtime/Audio/CStreamAudioManager.cpp index 57d48779d..342b5bd3c 100644 --- a/Runtime/Audio/CStreamAudioManager.cpp +++ b/Runtime/Audio/CStreamAudioManager.cpp @@ -58,8 +58,8 @@ struct SDSPStream : boo::IAudioVoiceCallback SDSPStream* x8_stereoLeft; SDSPStream* xc_companionRight; SDSPStreamInfo x10_info; - u8 x4c_vol; - u8 x4d_pan; + float x4c_vol; + float m_leftgain, m_rightgain; //DVDFileInfo x50_dvdHandle1; //DVDFileInfo x8c_dvdHandle2; //u32 xc8_streamId = -1; // MusyX stream handle @@ -311,19 +311,18 @@ struct SDSPStream : boo::IAudioVoiceCallback return -1; } - void UpdateStreamVolume(u8 vol) + void UpdateStreamVolume(float vol) { x4c_vol = vol; if (!x0_active || xe8_silent) return; float coefs[8] = {}; - float fvol = x4c_vol / 127.f; - coefs[int(boo::AudioChannel::FrontLeft)] = ((0x7f - x4d_pan) / 127.f) * fvol; - coefs[int(boo::AudioChannel::FrontRight)] = (x4d_pan / 127.f) * fvol; + coefs[int(boo::AudioChannel::FrontLeft)] = m_leftgain * vol; + coefs[int(boo::AudioChannel::FrontRight)] = m_rightgain * vol; m_booVoice->setMonoChannelLevels(nullptr, coefs, true); } - static void UpdateVolume(u32 id, u8 vol) + static void UpdateVolume(u32 id, float vol) { u32 idx = FindStreamIdx(id); if (idx == -1) @@ -388,20 +387,20 @@ struct SDSPStream : boo::IAudioVoiceCallback return !stream.x0_active; } - static u32 AllocateMono(const SDSPStreamInfo& info, u8 vol, u8 pan, bool oneshot) + static u32 AllocateMono(const SDSPStreamInfo& info, float vol, bool oneshot) { SDSPStream* stream; u32 id = PickFreeStream(stream, oneshot); if (id == -1) return -1; - stream->AllocateStream(info, vol, pan); + stream->AllocateStream(info, vol, 0.707f, 0.707f); return id; } static u32 AllocateStereo(const SDSPStreamInfo& linfo, const SDSPStreamInfo& rinfo, - u8 vol, bool oneshot) + float vol, bool oneshot) { SDSPStream* lstream; u32 lid = PickFreeStream(lstream, oneshot); @@ -415,12 +414,12 @@ struct SDSPStream : boo::IAudioVoiceCallback rstream->x8_stereoLeft = lstream; lstream->xc_companionRight = rstream; - lstream->AllocateStream(linfo, vol, 0); - rstream->AllocateStream(rinfo, vol, 0x7f); + lstream->AllocateStream(linfo, vol, 1.f, 0.f); + rstream->AllocateStream(rinfo, vol, 0.f, 1.f); return lid; } - void AllocateStream(const SDSPStreamInfo& info, u8 vol, u8 pan) + void AllocateStream(const SDSPStreamInfo& info, float vol, float left, float right) { x10_info = info; m_file.emplace(x10_info.x0_fileName); @@ -429,7 +428,8 @@ struct SDSPStream : boo::IAudioVoiceCallback m_readReqs[0].reset(); m_readReqs[1].reset(); x4c_vol = vol; - x4d_pan = pan; + m_leftgain = left; + m_rightgain = right; xe8_silent = false; xec_readState = 0; xe0_curBuffer = -1; @@ -477,7 +477,7 @@ private: }; s8 x71_companionRight = -1; s8 x72_companionLeft = -1; - u8 x73_volume = 0; + float x73_volume = 0.f; bool x74_oneshot; u32 x78_handleId = -1; // arg2 u32 x7c_streamId = -1; @@ -491,7 +491,7 @@ public: x70_24_unclaimed = true; } - CDSPStreamManager(const std::string& fileName, u32 handle, u8 volume, bool oneshot) + CDSPStreamManager(const std::string& fileName, u32 handle, float volume, bool oneshot) : x60_fileName(fileName), x73_volume(volume), x74_oneshot(oneshot), x78_handleId(handle) { if (!CDvdFile::FileExists(fileName.c_str())) @@ -626,7 +626,7 @@ public: { /* Mono */ if (!stream.x70_25_headerReadCancelled) - stream.x7c_streamId = SDSPStream::AllocateMono(info, stream.x73_volume, 0x40, stream.x74_oneshot); + stream.x7c_streamId = SDSPStream::AllocateMono(info, stream.x73_volume, stream.x74_oneshot); if (stream.x7c_streamId == -1) stream = CDSPStreamManager(); } @@ -759,7 +759,7 @@ public: m_dvdReq.reset(); } - static u32 StartStreaming(const std::string& fileName, u8 volume, bool oneshot) + static u32 StartStreaming(const std::string& fileName, float volume, bool oneshot) { auto pipePos = fileName.find('|'); if (pipePos == std::string::npos) @@ -852,7 +852,7 @@ public: stream = CDSPStreamManager(); } - static void UpdateVolume(u32 handle, u8 volume) + static void UpdateVolume(u32 handle, float volume) { u32 idx = FindClaimedStreamIdx(handle); if (idx == -1) @@ -921,7 +921,7 @@ struct SDSPPlayer { std::string x0_fileName; EPlayerState x10_playState = EPlayerState::Stopped; - u8 x14_volume = 0; + float x14_volume = 0.0; float x18_fadeIn = 0.f; float x1c_fadeOut = 0.f; u32 x20_internalHandle = -1; @@ -929,7 +929,7 @@ struct SDSPPlayer bool x28_music = true; SDSPPlayer() = default; - SDSPPlayer(EPlayerState playing, const std::string& fileName, u8 volume, + SDSPPlayer(EPlayerState playing, const std::string& fileName, float volume, float fadeIn, float fadeOut, u32 handle, bool music) : x0_fileName(fileName), x10_playState(playing), x14_volume(volume), x18_fadeIn(fadeIn), x1c_fadeOut(fadeOut), x20_internalHandle(handle), x28_music(music) {} @@ -937,17 +937,19 @@ struct SDSPPlayer static SDSPPlayer s_Players[2]; // looping, oneshot static SDSPPlayer s_QueuedPlayers[2]; // looping, oneshot -u8 CStreamAudioManager::GetTargetDSPVolume(u8 fileVol, bool music) +float CStreamAudioManager::GetTargetDSPVolume(float fileVol, bool music) { if (music) - return g_MusicUnmute ? (g_MusicVolume * fileVol / 0x7f) : 0; + return g_MusicUnmute ? (g_MusicVolume * fileVol / 127.f) : 0.f; else - return g_SfxUnmute ? (g_SfxVolume * fileVol / 0x7f) : 0; + return g_SfxUnmute ? (g_SfxVolume * fileVol / 127.f) : 0.f; } void CStreamAudioManager::Start(bool oneshot, const std::string& fileName, u8 volume, bool music, float fadeIn, float fadeOut) { + float fvol = volume / 127.f; + SDSPPlayer& p = s_Players[oneshot]; SDSPPlayer& qp = s_QueuedPlayers[oneshot]; @@ -955,7 +957,7 @@ void CStreamAudioManager::Start(bool oneshot, const std::string& fileName, CStringExtras::CompareCaseInsensitive(fileName, p.x0_fileName)) { /* Enque new stream */ - qp = SDSPPlayer(EPlayerState::FadeIn, fileName, volume, fadeIn, fadeOut, -1, music); + qp = SDSPPlayer(EPlayerState::FadeIn, fileName, fvol, fadeIn, fadeOut, -1, music); Stop(oneshot, p.x0_fileName); } else if (p.x10_playState != EPlayerState::Stopped) @@ -963,7 +965,7 @@ void CStreamAudioManager::Start(bool oneshot, const std::string& fileName, /* Fade existing stream back in */ p.x18_fadeIn = fadeIn; p.x1c_fadeOut = fadeOut; - p.x14_volume = volume; + p.x14_volume = fvol; if (p.x18_fadeIn <= FLT_EPSILON) { CDSPStreamManager::UpdateVolume(p.x20_internalHandle, @@ -980,21 +982,21 @@ void CStreamAudioManager::Start(bool oneshot, const std::string& fileName, { /* Start new stream */ EPlayerState state; - u8 vol; + float vol; if (fadeIn > 0.f) { state = EPlayerState::FadeIn; - vol = 0; + vol = 0.f; } else { state = EPlayerState::Playing; - vol = volume; + vol = fvol; } u32 handle = CDSPStreamManager::StartStreaming(fileName, GetTargetDSPVolume(vol, music), oneshot); if (handle != -1) - p = SDSPPlayer(state, fileName, volume, fadeIn, fadeOut, handle, music); + p = SDSPPlayer(state, fileName, fvol, fadeIn, fadeOut, handle, music); } } diff --git a/Runtime/Audio/CStreamAudioManager.hpp b/Runtime/Audio/CStreamAudioManager.hpp index 2d2625d7e..67ac0f5d3 100644 --- a/Runtime/Audio/CStreamAudioManager.hpp +++ b/Runtime/Audio/CStreamAudioManager.hpp @@ -13,7 +13,7 @@ class CStreamAudioManager static bool g_MusicUnmute; static bool g_SfxUnmute; - static u8 GetTargetDSPVolume(u8 fileVol, bool music); + static float GetTargetDSPVolume(float fileVol, bool music); static void StopStreaming(bool oneshot); static void UpdateDSP(bool oneshot, float dt); static void UpdateDSPStreamers(float dt); diff --git a/Runtime/IMain.hpp b/Runtime/IMain.hpp index f70c5af3a..af982e332 100644 --- a/Runtime/IMain.hpp +++ b/Runtime/IMain.hpp @@ -48,7 +48,7 @@ public: virtual void DrawDebugMetrics(double, CStopWatch&) {} virtual void DoPreDrawMetrics(){} virtual void FillInAssetIDs()=0; - virtual void LoadAudio()=0; + virtual bool LoadAudio()=0; virtual void ShutdownSubsystems()=0; virtual EGameplayResult GetGameplayResult() const=0; virtual void SetGameplayResult(EGameplayResult wl)=0; diff --git a/Runtime/MP1/CPreFrontEnd.cpp b/Runtime/MP1/CPreFrontEnd.cpp index 10a5918eb..1f713620a 100644 --- a/Runtime/MP1/CPreFrontEnd.cpp +++ b/Runtime/MP1/CPreFrontEnd.cpp @@ -1,4 +1,7 @@ #include "CPreFrontEnd.hpp" +#include "CResLoader.hpp" +#include "GameGlobalObjects.hpp" +#include "MP1.hpp" namespace urde { @@ -11,9 +14,25 @@ CPreFrontEnd::CPreFrontEnd() } -CIOWin::EMessageReturn CPreFrontEnd::OnMessage(const CArchitectureMessage&, CArchitectureQueue&) +CIOWin::EMessageReturn CPreFrontEnd::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue&) { - return EMessageReturn::Exit; + if (msg.GetType() != EArchMsgType::TimerTick) + return EMessageReturn::Normal; + + CMain* m = static_cast(g_Main); + //if (CResLoader::AreAllPaksLoaded()) + // return EMessageReturn::Exit; + if (!x14_resourceTweaksRegistered) + { + m->RegisterResourceTweaks(); + x14_resourceTweaksRegistered = true; + } + m->MemoryCardInitializePump(); + if (!g_MemoryCardSys) + return EMessageReturn::Exit; + if (!m->LoadAudio()) + return EMessageReturn::Exit; + return EMessageReturn::RemoveIOWinAndExit; } } diff --git a/Runtime/MP1/CPreFrontEnd.hpp b/Runtime/MP1/CPreFrontEnd.hpp index 1b54e9795..3391bbc3c 100644 --- a/Runtime/MP1/CPreFrontEnd.hpp +++ b/Runtime/MP1/CPreFrontEnd.hpp @@ -10,6 +10,7 @@ namespace MP1 class CPreFrontEnd : public CIOWin { + bool x14_resourceTweaksRegistered = false; public: CPreFrontEnd(); EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&); diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 48536c235..ad5f9ca84 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -11,6 +11,7 @@ #include "Audio/CStreamAudioManager.hpp" #include "CGBASupport.hpp" #include "CBasics.hpp" +#include "Audio/CAudioGroupSet.hpp" namespace urde { @@ -55,20 +56,89 @@ CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoi x58_ioWinManager.AddIOWin(errWin, 10000, 100000); } -bool CGameArchitectureSupport::Update() +void CGameArchitectureSupport::UpdateTicks() { - if (!g_MemoryCardSys) - m_parent.x128_globalObjects.MemoryCardInitializePump(); - - bool finished = false; + x4_archQueue.Push(MakeMsg::CreateTimerTick(EArchMsgTarget::Game, 1.f / 60.f)); +} +void CGameArchitectureSupport::Update() +{ g_GameState->GetWorldTransitionManager()->TouchModels(); x4_archQueue.Push(MakeMsg::CreateFrameBegin(EArchMsgTarget::Game, x78_)); - x4_archQueue.Push(MakeMsg::CreateTimerTick(EArchMsgTarget::Game, 1.f / 60.f)); - x58_ioWinManager.PumpMessages(x4_archQueue); +} - return finished; +struct AudioGroupInfo +{ + const char* name; + u32 id; +}; + +static const AudioGroupInfo StaticAudioGroups[] = +{ + {"Misc_AGSC", 39}, + {"MiscSamus_AGSC", 41}, + {"UI_AGSC", 40}, + {"Weapons_AGSC", 43}, + {"ZZZ_AGSC", 65} +}; + +bool CGameArchitectureSupport::LoadAudio() +{ + if (x88_audioLoadStatus == EAudioLoadStatus::Loaded) + return true; + + for (int i=0 ; i<5 ; ++i) + { + TToken& tok = x8c_pendingAudioGroups[i]; + if (tok.IsLocked()) + { + if (tok.IsLoaded()) + { + CAudioGroupSet* set = tok.GetObj(); + if (!CAudioSys::SysIsGroupSetLoaded(set->GetName())) + { + CAudioSys::SysLoadGroupSet(tok, set->GetName(), tok.GetObjectTag()->id); + CAudioSys::SysAddGroupIntoAmuse(set->GetName()); + } + } + else + { + return false; + } + } + else + { + /* Lock next pending group */ + tok.Lock(); + return false; + } + } + + CSfxManager::LoadTranslationTable(g_SimplePool, g_ResFactory->GetResourceIdByName("sound_lookup")); + x8c_pendingAudioGroups = std::vector>(); + x88_audioLoadStatus = EAudioLoadStatus::Loaded; + + return true; +} + +void CGameArchitectureSupport::PreloadAudio() +{ + if (x88_audioLoadStatus != EAudioLoadStatus::Uninitialized) + return; + x8c_pendingAudioGroups.clear(); + x8c_pendingAudioGroups.reserve(5); + + for (int i=0 ; i<5 ; ++i) + { + const AudioGroupInfo& info = StaticAudioGroups[i]; + CToken grp = g_SimplePool->GetObj(info.name); + if (i == 0) /* Lock first group in sequence */ + grp.Lock(); + x8c_pendingAudioGroups.push_back(std::move(grp)); + } + + x88_audioLoadStatus = EAudioLoadStatus::Loading; } void CGameArchitectureSupport::Draw() @@ -130,8 +200,12 @@ void CMain::InitializeSubsystems(const hecl::Runtime::FileStoreManager& storeMgr void CMain::FillInAssetIDs() { } -void CMain::LoadAudio() + +bool CMain::LoadAudio() { + if (x164_archSupport) + return x164_archSupport->LoadAudio(); + return true; } void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx) @@ -152,23 +226,27 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, x128_globalObjects.PostInitialize(); x70_tweaks.RegisterTweaks(); x70_tweaks.RegisterResourceTweaks(); - m_archSupport.reset(new CGameArchitectureSupport(*this, voiceEngine, backend)); - g_archSupport = m_archSupport.get(); - //g_TweakManager->ReadFromMemoryCard("AudioTweaks"); FillInAssetIDs(); + x164_archSupport.reset(new CGameArchitectureSupport(*this, voiceEngine, backend)); + g_archSupport = x164_archSupport.get(); + x164_archSupport->PreloadAudio(); + //g_TweakManager->ReadFromMemoryCard("AudioTweaks"); + + CStreamAudioManager::Start(false, "Audio/rui_samusL.dsp|Audio/rui_samusR.dsp", 0x7f, true, 1.f, 1.f); } bool CMain::Proc() { CGBASupport::GlobalPoll(); - xe8_b24_finished = m_archSupport->Update(); + x164_archSupport->UpdateTicks(); + x164_archSupport->Update(); CStreamAudioManager::Update(1.f / 60.f); - return xe8_b24_finished; + return x160_24_finished; } void CMain::Draw() { - m_archSupport->Draw(); + x164_archSupport->Draw(); } void CMain::Shutdown() diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 8c09aa686..6a25c319c 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -92,17 +92,6 @@ public: m_renderer.reset(AllocateRenderer(xcc_simplePool, x4_resFactory)); } - void MemoryCardInitializePump() - { - if (!g_MemoryCardSys) - { - if (!x0_memoryCardSys) - x0_memoryCardSys.reset(new CMemoryCardSys()); - if (x0_memoryCardSys->InitializePump()) - g_MemoryCardSys = x0_memoryCardSys.get(); - } - } - void ResetGameState() { x134_gameState.reset(new CGameState()); @@ -123,6 +112,16 @@ class CGameArchitectureSupport CGuiSys x44_guiSys; CIOWinManager x58_ioWinManager; s32 x78_; + + enum class EAudioLoadStatus + { + Loading, + Loaded, + Uninitialized + }; + EAudioLoadStatus x88_audioLoadStatus = EAudioLoadStatus::Uninitialized; + std::vector> x8c_pendingAudioGroups; + boo::SWindowRect m_windowRect; bool m_rectIsDirty; @@ -159,7 +158,9 @@ public: CGameArchitectureSupport(CMain& parent, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend); void PreloadAudio(); - bool Update(); + bool LoadAudio(); + void UpdateTicks(); + void Update(); void Draw(); bool isRectDirty() { return m_rectIsDirty; } @@ -202,11 +203,9 @@ private: //CMemorySys x6c_memSys; CTweaks x70_tweaks; EGameplayResult xe4_gameplayResult; - bool xe8_b24_finished = false; /* urde addition: these are simply initialized along with everything else */ CGameGlobalObjects x128_globalObjects; - std::unique_ptr m_archSupport; EFlowState x12c_flowState = EFlowState::Five; @@ -216,7 +215,7 @@ private: { struct { - bool x160_24_ : 1; + bool x160_24_finished : 1; bool x160_25_ : 1; bool x160_26_ : 1; bool x160_27_ : 1; @@ -229,7 +228,7 @@ private: u16 _dummy = 0; }; - u32 x164_ = 0; + std::unique_ptr x164_archSupport; void InitializeSubsystems(const hecl::Runtime::FileStoreManager& storeMgr); @@ -251,12 +250,24 @@ public: void Draw(); void Shutdown(); + void MemoryCardInitializePump() + { + if (!g_MemoryCardSys) + { + std::unique_ptr& memSys = x128_globalObjects.x0_memoryCardSys; + if (!memSys) + memSys.reset(new CMemoryCardSys()); + if (memSys->InitializePump()) + g_MemoryCardSys = memSys.get(); + } + } + bool CheckReset() { return false; } bool CheckTerminate() { return false; } void DrawDebugMetrics(double, CStopWatch&) {} void DoPredrawMetrics() {} void FillInAssetIDs(); - void LoadAudio(); + bool LoadAudio(); void ShutdownSubsystems() {} EGameplayResult GetGameplayResult() const { return xe4_gameplayResult; } void SetGameplayResult(EGameplayResult wl) { xe4_gameplayResult = wl; } diff --git a/hecl b/hecl index 2f1644c6f..3ecbf32de 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 2f1644c6f04e1cb2e2c5cdf31a04ea65642c7398 +Subproject commit 3ecbf32de81e1b3c76ad9519ca728a8fc2debe0b