2017-01-15 03:07:01 +00:00
|
|
|
#include "CScriptStreamedMusic.hpp"
|
|
|
|
#include "CStringExtras.hpp"
|
|
|
|
#include "TCastTo.hpp"
|
2017-01-16 08:40:33 +00:00
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "CWorld.hpp"
|
|
|
|
#include "CInGameTweakManagerBase.hpp"
|
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "Audio/CStreamAudioManager.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
bool CScriptStreamedMusic::IsDSPFile(std::string_view fileName)
|
2017-01-15 03:07:01 +00:00
|
|
|
{
|
|
|
|
if (!CStringExtras::CompareCaseInsensitive(fileName, "sw"))
|
|
|
|
return true;
|
2017-11-13 06:19:18 +00:00
|
|
|
return CStringExtras::IndexOfSubstring(fileName, ".dsp") != -1;
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:40:33 +00:00
|
|
|
void CScriptStreamedMusic::StopStream(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CStreamAudioManager::Stop(!x46_loop, x34_fileName);
|
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-01-16 08:40:33 +00:00
|
|
|
void CScriptStreamedMusic::StartStream(CStateManager& mgr)
|
2017-01-15 03:07:01 +00:00
|
|
|
{
|
2018-06-02 00:03:31 +00:00
|
|
|
CStreamAudioManager::Start(!x46_loop, x34_fileName, x50_volume / 127.f,
|
|
|
|
x47_music, x48_fadeIn, x4c_fadeOut);
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:40:33 +00:00
|
|
|
void CScriptStreamedMusic::TweakOverride(CStateManager& mgr)
|
2017-01-15 03:07:01 +00:00
|
|
|
{
|
2017-01-16 08:40:33 +00:00
|
|
|
const CWorld* wld = mgr.GetWorld();
|
|
|
|
const CGameArea* area = wld->GetAreaAlways(x4_areaId);
|
|
|
|
std::string twkName = hecl::Format("Area %8.8x MusicObject: %s",
|
2017-08-13 05:26:14 +00:00
|
|
|
u32(area->GetAreaAssetId().Value()), x10_name.c_str());
|
2017-01-16 08:40:33 +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-11-13 06:19:18 +00:00
|
|
|
CScriptStreamedMusic::CScriptStreamedMusic(TUniqueId id, const CEntityInfo& info, std::string_view name,
|
|
|
|
bool active, std::string_view fileName, bool noStopOnDeactivate,
|
2017-01-16 08:40:33 +00:00
|
|
|
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),
|
2018-02-28 01:46:14 +00:00
|
|
|
x48_fadeIn(fadeIn), x4c_fadeOut(fadeOut), x50_volume(volume)
|
|
|
|
{
|
2018-06-02 06:06:25 +00:00
|
|
|
size_t pos;
|
|
|
|
while ((pos = x34_fileName.find("audio/")) != std::string::npos)
|
|
|
|
x34_fileName.replace(pos, 6, "Audio/");
|
2018-02-28 01:46:14 +00:00
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-01-16 08:40:33 +00:00
|
|
|
void CScriptStreamedMusic::Stop(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (x45_fileIsDsp)
|
|
|
|
StopStream(mgr);
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:40:33 +00:00
|
|
|
void CScriptStreamedMusic::Play(CStateManager& mgr)
|
2017-01-15 03:07:01 +00:00
|
|
|
{
|
2017-01-16 08:40:33 +00:00
|
|
|
TweakOverride(mgr);
|
|
|
|
if (x45_fileIsDsp)
|
|
|
|
StartStream(mgr);
|
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2017-01-16 08:40:33 +00:00
|
|
|
void CScriptStreamedMusic::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptStreamedMusic::AcceptScriptMsg(EScriptObjectMessage msg,
|
|
|
|
TUniqueId objId, CStateManager& stateMgr)
|
|
|
|
{
|
2017-01-16 08:40:33 +00:00
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case EScriptObjectMessage::Play:
|
|
|
|
if (x30_24_active)
|
|
|
|
Play(stateMgr);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Stop:
|
|
|
|
if (x30_24_active)
|
|
|
|
Stop(stateMgr);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Increment:
|
|
|
|
if (x45_fileIsDsp)
|
|
|
|
CStreamAudioManager::FadeBackIn(!x46_loop, x48_fadeIn);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Decrement:
|
|
|
|
if (x45_fileIsDsp)
|
|
|
|
CStreamAudioManager::TemporaryFadeOut(!x46_loop, x4c_fadeOut);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2017-01-15 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|