2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptMidi.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CInGameTweakManagerBase.hpp"
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/MP1/CInGameGuiManager.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-02-27 05:25:14 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-02-27 05:25:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CScriptMidi::CScriptMidi(TUniqueId id, const CEntityInfo& info, std::string_view name, bool active, CAssetId csng,
|
|
|
|
float fadeIn, float fadeOut, s32 volume)
|
|
|
|
: CEntity(id, info, active, name), x40_fadeInTime(fadeIn), x44_fadeOutTime(fadeOut), x48_volume(volume) {
|
|
|
|
x34_song = g_SimplePool->GetObj(SObjectTag{FOURCC('CSNG'), csng});
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 17:18:12 +00:00
|
|
|
CScriptMidi::~CScriptMidi() {
|
|
|
|
StopInternal(0.f);
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMidi::StopInternal(float fadeTime) {
|
2020-05-07 17:04:19 +00:00
|
|
|
if (!x3c_handle) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-07 17:04:19 +00:00
|
|
|
|
|
|
|
CMidiManager::Stop(x3c_handle, fadeTime);
|
|
|
|
x3c_handle.reset();
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMidi::Stop(CStateManager& mgr, float fadeTime) {
|
|
|
|
const CWorld* wld = mgr.GetWorld();
|
|
|
|
const CGameArea* area = wld->GetAreaAlways(x4_areaId);
|
2020-05-07 17:04:19 +00:00
|
|
|
const std::string twkName =
|
2018-12-08 05:30:43 +00:00
|
|
|
CInGameTweakManagerBase::GetIdentifierForMidiEvent(wld->IGetWorldAssetId(), area->GetAreaAssetId(), x10_name);
|
|
|
|
if (g_TweakManager->HasTweakValue(twkName)) {
|
|
|
|
const CTweakValue::Audio& audio = g_TweakManager->GetTweakValue(twkName)->GetAudio();
|
|
|
|
fadeTime = audio.GetFadeOut();
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
StopInternal(fadeTime);
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMidi::Play(CStateManager& mgr, float fadeTime) {
|
|
|
|
u32 volume = x48_volume;
|
|
|
|
const CWorld* wld = mgr.GetWorld();
|
|
|
|
const CGameArea* area = wld->GetAreaAlways(x4_areaId);
|
2020-05-07 17:04:19 +00:00
|
|
|
const std::string twkName =
|
2018-12-08 05:30:43 +00:00
|
|
|
CInGameTweakManagerBase::GetIdentifierForMidiEvent(wld->IGetWorldAssetId(), area->GetAreaAssetId(), x10_name);
|
|
|
|
if (g_TweakManager->HasTweakValue(twkName)) {
|
|
|
|
const CTweakValue::Audio& audio = g_TweakManager->GetTweakValue(twkName)->GetAudio();
|
|
|
|
x34_song = g_SimplePool->GetObj(SObjectTag{FOURCC('CSNG'), audio.GetResId()});
|
|
|
|
fadeTime = audio.GetFadeIn();
|
|
|
|
volume = audio.GetVolume() * 127.f;
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x3c_handle = CMidiManager::Play(*x34_song, fadeTime, false, volume / 127.f);
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMidi::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-02-27 05:25:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMidi::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) {
|
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::Play:
|
2020-05-07 17:04:19 +00:00
|
|
|
if (GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Play(stateMgr, x40_fadeInTime);
|
2020-05-07 17:04:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Stop:
|
2020-05-07 17:04:19 +00:00
|
|
|
if (GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Stop(stateMgr, x44_fadeOutTime);
|
2020-05-07 17:04:19 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Deactivate:
|
|
|
|
StopInternal(0.f);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|