2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptStreamedMusic.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CInGameTweakManagerBase.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/CStringExtras.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Audio/CStreamAudioManager.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CScriptStreamedMusic::IsDSPFile(std::string_view fileName) {
|
2019-09-14 15:14:51 +00:00
|
|
|
if (CStringExtras::CompareCaseInsensitive(fileName, "sw")) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2019-09-14 15:14:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return CStringExtras::IndexOfSubstring(fileName, ".dsp") != -1;
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::StopStream(CStateManager& mgr) { CStreamAudioManager::Stop(!x46_loop, x34_fileName); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::StartStream(CStateManager& mgr) {
|
|
|
|
CStreamAudioManager::Start(!x46_loop, x34_fileName, x50_volume / 127.f, x47_music, x48_fadeIn, x4c_fadeOut);
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::TweakOverride(CStateManager& mgr) {
|
|
|
|
const CWorld* wld = mgr.GetWorld();
|
|
|
|
const CGameArea* area = wld->GetAreaAlways(x4_areaId);
|
2020-04-11 22:51:39 +00:00
|
|
|
std::string twkName = fmt::format(FMT_STRING("Area {} MusicObject: {}"), area->GetAreaAssetId(), x10_name);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (g_TweakManager->HasTweakValue(twkName)) {
|
|
|
|
const CTweakValue::Audio& audio = g_TweakManager->GetTweakValue(twkName)->GetAudio();
|
|
|
|
x34_fileName = audio.GetFileName();
|
|
|
|
x45_fileIsDsp = IsDSPFile(x34_fileName);
|
|
|
|
x48_fadeIn = audio.GetFadeIn();
|
|
|
|
x4c_fadeOut = audio.GetFadeOut();
|
|
|
|
x50_volume = audio.GetVolume() * 127.f;
|
|
|
|
}
|
2017-01-16 08:40:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptStreamedMusic::CScriptStreamedMusic(TUniqueId id, const CEntityInfo& info, std::string_view name, bool active,
|
|
|
|
std::string_view fileName, bool noStopOnDeactivate, float fadeIn,
|
|
|
|
float fadeOut, u32 volume, bool loop, bool music)
|
|
|
|
: CEntity(id, info, active, name)
|
|
|
|
, x34_fileName(fileName)
|
|
|
|
, x44_noStopOnDeactivate(noStopOnDeactivate)
|
|
|
|
, x45_fileIsDsp(IsDSPFile(fileName))
|
|
|
|
, x46_loop(loop)
|
|
|
|
, x47_music(music)
|
|
|
|
, x48_fadeIn(fadeIn)
|
|
|
|
, x4c_fadeOut(fadeOut)
|
2019-03-09 08:58:27 +00:00
|
|
|
, x50_volume(volume) {}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::Stop(CStateManager& mgr) {
|
2020-05-07 15:49:31 +00:00
|
|
|
if (!x45_fileIsDsp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StopStream(mgr);
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::Play(CStateManager& mgr) {
|
|
|
|
TweakOverride(mgr);
|
2020-05-07 15:49:31 +00:00
|
|
|
if (x45_fileIsDsp) {
|
2018-12-08 05:30:43 +00:00
|
|
|
StartStream(mgr);
|
2020-05-07 15:49:31 +00:00
|
|
|
}
|
2017-01-16 08:40:33 +00:00
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptStreamedMusic::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) {
|
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::Play:
|
2020-05-07 15:49:31 +00:00
|
|
|
if (x30_24_active) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Play(stateMgr);
|
2020-05-07 15:49:31 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Stop:
|
2020-05-07 15:49:31 +00:00
|
|
|
if (x30_24_active) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Stop(stateMgr);
|
2020-05-07 15:49:31 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Increment:
|
2020-05-07 15:49:31 +00:00
|
|
|
if (x45_fileIsDsp) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CStreamAudioManager::FadeBackIn(!x46_loop, x48_fadeIn);
|
2020-05-07 15:49:31 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Decrement:
|
2020-05-07 15:49:31 +00:00
|
|
|
if (x45_fileIsDsp) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CStreamAudioManager::TemporaryFadeOut(!x46_loop, x4c_fadeOut);
|
2020-05-07 15:49:31 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|