2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptActorKeyframe.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CPatterned.hpp"
|
|
|
|
#include "Runtime/World/CScriptActor.hpp"
|
|
|
|
#include "Runtime/World/CScriptPlatform.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptActorKeyframe::CScriptActorKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 animId,
|
2018-11-11 03:27:54 +00:00
|
|
|
bool looping, float lifetime, bool isPassive, u32 fadeOut, bool active,
|
2018-05-17 00:04:07 +00:00
|
|
|
float totalPlayback)
|
2016-12-19 18:27:58 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
|
|
|
, x34_animationId(animId)
|
2018-05-14 21:44:09 +00:00
|
|
|
, x38_initialLifetime(lifetime)
|
|
|
|
, x3c_playbackRate(totalPlayback)
|
2020-04-11 05:50:10 +00:00
|
|
|
, x40_lifetime(lifetime)
|
|
|
|
, x44_24_looping(looping)
|
|
|
|
, x44_25_isPassive(isPassive)
|
|
|
|
, x44_26_fadeOut(fadeOut != 0u)
|
2020-04-20 04:57:50 +00:00
|
|
|
, x44_27_timedLoop(fadeOut != 0u) {}
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
if (msg == EScriptObjectMessage::Action) {
|
|
|
|
if (GetActive()) {
|
|
|
|
if (!x44_25_isPassive) {
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-05-07 12:14:39 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Play) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2020-05-07 12:14:39 +00:00
|
|
|
const auto search = mgr.GetIdListForScript(conn.x8_objId);
|
|
|
|
for (auto it = search.first; it != search.second; ++it) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateEntity(it->second, mgr);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x44_28_playing = true;
|
2022-11-11 02:25:28 +00:00
|
|
|
x40_lifetime = x38_initialLifetime;
|
2018-12-08 05:30:43 +00:00
|
|
|
SendScriptMsgs(EScriptObjectState::Play, mgr, EScriptObjectMessage::None);
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (msg == EScriptObjectMessage::InitializedInArea) {
|
|
|
|
if (x34_animationId == -1)
|
|
|
|
x34_animationId = 0;
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity::AcceptScriptMsg(msg, uid, mgr);
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::Think(float dt, CStateManager& mgr) {
|
|
|
|
if (x44_25_isPassive || !x44_24_looping || !x44_27_timedLoop || !x44_28_playing || x40_lifetime <= 0.f) {
|
|
|
|
CEntity::Think(dt, mgr);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x40_lifetime -= dt;
|
|
|
|
if (x40_lifetime > 0.f) {
|
|
|
|
CEntity::Think(dt, mgr);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x44_28_playing = false;
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-05-07 12:14:39 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Play) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* ent = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId));
|
2020-05-07 12:14:39 +00:00
|
|
|
if (const TCastToPtr<CScriptActor> act = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (act->HasModelData() && act->GetModelData()->HasAnimData()) {
|
2019-08-14 14:58:54 +00:00
|
|
|
CAnimData* animData = act->GetModelData()->GetAnimationData();
|
2020-05-07 12:14:39 +00:00
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
animData->DelAdditiveAnimation(x34_animationId);
|
2022-11-11 02:25:28 +00:00
|
|
|
} else if (animData->GetDefaultAnimation() == x34_animationId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
animData->EnableLooping(false);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-07 12:14:39 +00:00
|
|
|
} else if (const TCastToPtr<CPatterned> ai = ent) {
|
2019-08-14 14:58:54 +00:00
|
|
|
CAnimData* animData = ai->GetModelData()->GetAnimationData();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
|
|
|
animData->DelAdditiveAnimation(x34_animationId);
|
|
|
|
} else if (ai->GetBodyController()->GetCurrentStateId() == pas::EAnimationState::Scripted &&
|
|
|
|
animData->GetDefaultAnimation() == x34_animationId) {
|
2019-08-14 14:58:54 +00:00
|
|
|
ai->GetBodyController()->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity::Think(dt, mgr);
|
2016-11-20 21:53:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptActorKeyframe::UpdateEntity(TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CEntity* ent = mgr.ObjectById(uid);
|
|
|
|
CActor* act = nullptr;
|
2020-04-23 11:22:10 +00:00
|
|
|
if (const TCastToPtr<CScriptActor> actor = ent) {
|
|
|
|
act = actor.GetPtr();
|
|
|
|
} else if (const TCastToPtr<CScriptPlatform> platform = ent) {
|
|
|
|
act = platform.GetPtr();
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (act) {
|
2020-05-07 12:14:39 +00:00
|
|
|
if (!act->GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SendScriptMsg(act, GetUniqueId(), EScriptObjectMessage::Activate);
|
2020-05-07 12:14:39 +00:00
|
|
|
}
|
2019-02-24 07:15:54 +00:00
|
|
|
act->SetDrawFlags({0, 0, 3, zeus::skWhite});
|
2018-12-08 05:30:43 +00:00
|
|
|
if (act->HasModelData() && act->GetModelData()->HasAnimData()) {
|
2019-08-14 14:58:54 +00:00
|
|
|
CAnimData* animData = act->GetModelData()->GetAnimationData();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
|
|
|
animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_fadeOut);
|
|
|
|
} else {
|
|
|
|
animData->SetAnimation(CAnimPlaybackParms(x34_animationId, -1, 1.f, true), false);
|
2019-08-14 14:58:54 +00:00
|
|
|
act->GetModelData()->EnableLooping(x44_24_looping);
|
2018-12-08 05:30:43 +00:00
|
|
|
animData->MultiplyPlaybackRate(x3c_playbackRate);
|
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (TCastToPtr<CPatterned> ai = ent) {
|
2019-08-14 14:58:54 +00:00
|
|
|
CAnimData* animData = ai->GetModelData()->GetAnimationData();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (animData->IsAdditiveAnimation(x34_animationId)) {
|
|
|
|
animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_fadeOut);
|
|
|
|
} else {
|
2019-08-14 14:58:54 +00:00
|
|
|
ai->GetBodyController()->GetCommandMgr().DeliverCmd(
|
2018-12-08 05:30:43 +00:00
|
|
|
CBCScriptedCmd(x34_animationId, x44_24_looping, x44_27_timedLoop, x38_initialLifetime));
|
2018-05-17 00:04:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-05-14 21:44:09 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|