metaforce/Runtime/World/CScriptCameraHint.cpp

134 lines
4.9 KiB
C++
Raw Permalink Normal View History

#include "Runtime/World/CScriptCameraHint.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2016-04-28 04:44:41 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2016-04-28 04:44:41 +00:00
2017-11-13 06:19:18 +00:00
CScriptCameraHint::CScriptCameraHint(TUniqueId uid, std::string_view name, const CEntityInfo& info,
const zeus::CTransform& xf, bool active, s32 priority,
2017-10-16 05:26:50 +00:00
CBallCamera::EBallCameraBehaviour behaviour, u32 overrideFlags, float minDist,
float maxDist, float backwardsDist, const zeus::CVector3f& lookAtOffset,
const zeus::CVector3f& chaseLookAtOffset, const zeus::CVector3f& ballToCam,
float fov, float attitudeRange, float azimuthRange, float anglePerSecond,
2018-06-28 01:17:01 +00:00
float clampVelRange, float clampRotRange, float elevation, float interpolateTime,
2017-10-16 05:26:50 +00:00
float clampVelTime, float controlInterpDur)
2017-12-19 03:05:50 +00:00
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic),
2018-12-08 05:30:43 +00:00
CActorParameters::None(), kInvalidUniqueId)
, xe8_priority(priority)
, xec_hint(overrideFlags, behaviour, minDist, maxDist, backwardsDist, lookAtOffset, chaseLookAtOffset, ballToCam, fov,
attitudeRange, azimuthRange, anglePerSecond, clampVelRange, clampRotRange, elevation, interpolateTime,
clampVelTime, controlInterpDur)
, x168_origXf(xf) {}
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
void CScriptCameraHint::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-01-15 03:07:01 +00:00
2018-12-08 05:30:43 +00:00
void CScriptCameraHint::InitializeInArea(CStateManager& mgr) {
x164_delegatedCamera = kInvalidUniqueId;
for (CEntity* ent : mgr.GetAllObjectList()) {
for (const SConnection& conn : ent->GetConnectionList()) {
if (mgr.GetIdForScript(conn.x8_objId) != GetUniqueId()) {
2018-12-08 05:30:43 +00:00
continue;
}
if (conn.x4_msg != EScriptObjectMessage::Increment && conn.x4_msg != EScriptObjectMessage::Decrement) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-01-15 12:36:04 +00:00
for (auto it = ent->GetConnectionList().begin(); it != ent->GetConnectionList().end(); ++it) {
2018-12-08 05:30:43 +00:00
const SConnection& conn2 = *it;
if (conn2.x4_msg != EScriptObjectMessage::Increment && conn2.x4_msg != EScriptObjectMessage::Decrement) {
2018-12-08 05:30:43 +00:00
continue;
}
const TUniqueId id = mgr.GetIdForScript(conn2.x8_objId);
const auto* const obj = mgr.ObjectById(id);
if (TCastToConstPtr<CPathCamera>(obj) || TCastToConstPtr<CScriptSpindleCamera>(obj)) {
it = ent->GetConnectionList().erase(it);
if (x164_delegatedCamera != id) {
2018-12-08 05:30:43 +00:00
x164_delegatedCamera = id;
}
2018-12-08 05:30:43 +00:00
break;
}
2018-12-08 05:30:43 +00:00
}
break;
}
2018-12-08 05:30:43 +00:00
}
}
2018-12-08 05:30:43 +00:00
void CScriptCameraHint::AddHelper(TUniqueId id) {
const auto search =
std::find_if(x150_helpers.cbegin(), x150_helpers.cend(), [id](TUniqueId tid) { return tid == id; });
if (search != x150_helpers.end()) {
return;
}
x150_helpers.push_back(id);
}
2018-12-08 05:30:43 +00:00
void CScriptCameraHint::RemoveHelper(TUniqueId id) {
const auto search =
std::find_if(x150_helpers.cbegin(), x150_helpers.cend(), [id](TUniqueId tid) { return tid == id; });
if (search != x150_helpers.cend()) {
2018-12-08 05:30:43 +00:00
x150_helpers.erase(search);
} else {
2018-12-08 05:30:43 +00:00
x150_helpers.pop_front();
}
}
2018-12-08 05:30:43 +00:00
void CScriptCameraHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {
switch (msg) {
case EScriptObjectMessage::Deleted:
case EScriptObjectMessage::Deactivate:
mgr.GetCameraManager()->DeleteCameraHint(GetUniqueId(), mgr);
break;
case EScriptObjectMessage::InitializedInArea:
InitializeInArea(mgr);
break;
default:
break;
}
2018-12-08 05:30:43 +00:00
if (GetActive()) {
switch (msg) {
case EScriptObjectMessage::Increment:
AddHelper(sender);
mgr.GetCameraManager()->AddActiveCameraHint(GetUniqueId(), mgr);
x166_inactive = false;
break;
case EScriptObjectMessage::Decrement:
RemoveHelper(sender);
mgr.GetCameraManager()->AddInactiveCameraHint(GetUniqueId(), mgr);
break;
default:
break;
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
if (msg == EScriptObjectMessage::Follow) {
if (!GetActive()) {
if (const TCastToConstPtr<CActor> act = mgr.GetObjectById(sender)) {
2018-12-08 05:30:43 +00:00
zeus::CVector3f followerToThisFlat = x168_origXf.origin - act->GetTranslation();
followerToThisFlat.z() = 0.f;
if (followerToThisFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
followerToThisFlat.normalize();
} else {
2018-12-08 05:30:43 +00:00
followerToThisFlat = act->GetTransform().basis[1];
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f target = act->GetTranslation() + followerToThisFlat;
target.z() = x168_origXf.origin.z() + followerToThisFlat.z();
SetTransform(zeus::lookAt(act->GetTranslation(), target));
}
}
2018-12-08 05:30:43 +00:00
AddHelper(sender);
mgr.GetCameraManager()->AddActiveCameraHint(GetUniqueId(), mgr);
}
2018-12-08 05:30:43 +00:00
CActor::AcceptScriptMsg(msg, sender, mgr);
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce