mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 03:47:43 +00:00
New code style refactor
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
#include "CStateManager.hpp"
|
||||
#include "TCastTo.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
namespace urde {
|
||||
|
||||
CScriptCameraHint::CScriptCameraHint(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
||||
const zeus::CTransform& xf, bool active, s32 priority,
|
||||
@@ -15,126 +14,103 @@ CScriptCameraHint::CScriptCameraHint(TUniqueId uid, std::string_view name, const
|
||||
float clampVelRange, float clampRotRange, float elevation, float interpolateTime,
|
||||
float clampVelTime, float controlInterpDur)
|
||||
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic),
|
||||
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)
|
||||
{
|
||||
}
|
||||
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) {}
|
||||
|
||||
void CScriptCameraHint::Accept(IVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(this);
|
||||
}
|
||||
void CScriptCameraHint::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
||||
|
||||
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())
|
||||
continue;
|
||||
if (conn.x4_msg != EScriptObjectMessage::Increment &&
|
||||
conn.x4_msg != EScriptObjectMessage::Decrement)
|
||||
continue;
|
||||
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())
|
||||
continue;
|
||||
if (conn.x4_msg != EScriptObjectMessage::Increment && conn.x4_msg != EScriptObjectMessage::Decrement)
|
||||
continue;
|
||||
|
||||
for (auto it = ent->GetConnectionList().begin() ; it != ent->GetConnectionList().cend() ; ++it)
|
||||
{
|
||||
const SConnection& conn2 = *it;
|
||||
if (conn2.x4_msg != EScriptObjectMessage::Increment &&
|
||||
conn2.x4_msg != EScriptObjectMessage::Decrement)
|
||||
continue;
|
||||
TUniqueId id = mgr.GetIdForScript(conn2.x8_objId);
|
||||
if (TCastToPtr<CPathCamera>(mgr.ObjectById(id)) ||
|
||||
TCastToPtr<CScriptSpindleCamera>(mgr.ObjectById((id))))
|
||||
{
|
||||
ent->ConnectionList().erase(it);
|
||||
if (x164_delegatedCamera != id)
|
||||
x164_delegatedCamera = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
for (auto it = ent->GetConnectionList().begin(); it != ent->GetConnectionList().cend(); ++it) {
|
||||
const SConnection& conn2 = *it;
|
||||
if (conn2.x4_msg != EScriptObjectMessage::Increment && conn2.x4_msg != EScriptObjectMessage::Decrement)
|
||||
continue;
|
||||
TUniqueId id = mgr.GetIdForScript(conn2.x8_objId);
|
||||
if (TCastToPtr<CPathCamera>(mgr.ObjectById(id)) || TCastToPtr<CScriptSpindleCamera>(mgr.ObjectById((id)))) {
|
||||
ent->ConnectionList().erase(it);
|
||||
if (x164_delegatedCamera != id)
|
||||
x164_delegatedCamera = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptCameraHint::AddHelper(TUniqueId id)
|
||||
{
|
||||
auto search = std::find_if(x150_helpers.begin(), x150_helpers.end(),
|
||||
[id](TUniqueId tid) { return tid == id; });
|
||||
if (search == x150_helpers.end())
|
||||
x150_helpers.push_back(id);
|
||||
void CScriptCameraHint::AddHelper(TUniqueId id) {
|
||||
auto search = std::find_if(x150_helpers.begin(), x150_helpers.end(), [id](TUniqueId tid) { return tid == id; });
|
||||
if (search == x150_helpers.end())
|
||||
x150_helpers.push_back(id);
|
||||
}
|
||||
|
||||
void CScriptCameraHint::RemoveHelper(TUniqueId id)
|
||||
{
|
||||
auto search = std::find_if(x150_helpers.begin(), x150_helpers.end(),
|
||||
[id](TUniqueId tid) { return tid == id; });
|
||||
if (search != x150_helpers.end())
|
||||
x150_helpers.erase(search);
|
||||
else
|
||||
x150_helpers.pop_front();
|
||||
void CScriptCameraHint::RemoveHelper(TUniqueId id) {
|
||||
auto search = std::find_if(x150_helpers.begin(), x150_helpers.end(), [id](TUniqueId tid) { return tid == id; });
|
||||
if (search != x150_helpers.end())
|
||||
x150_helpers.erase(search);
|
||||
else
|
||||
x150_helpers.pop_front();
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (msg == EScriptObjectMessage::Follow) {
|
||||
if (!GetActive()) {
|
||||
if (TCastToConstPtr<CActor> act = mgr.GetObjectById(sender)) {
|
||||
zeus::CVector3f followerToThisFlat = x168_origXf.origin - act->GetTranslation();
|
||||
followerToThisFlat.z() = 0.f;
|
||||
if (followerToThisFlat.canBeNormalized())
|
||||
followerToThisFlat.normalize();
|
||||
else
|
||||
followerToThisFlat = act->GetTransform().basis[1];
|
||||
zeus::CVector3f target = act->GetTranslation() + followerToThisFlat;
|
||||
target.z() = x168_origXf.origin.z() + followerToThisFlat.z();
|
||||
SetTransform(zeus::lookAt(act->GetTranslation(), target));
|
||||
}
|
||||
}
|
||||
AddHelper(sender);
|
||||
mgr.GetCameraManager()->AddActiveCameraHint(GetUniqueId(), mgr);
|
||||
}
|
||||
|
||||
if (msg == EScriptObjectMessage::Follow)
|
||||
{
|
||||
if (!GetActive())
|
||||
{
|
||||
if (TCastToConstPtr<CActor> act = mgr.GetObjectById(sender))
|
||||
{
|
||||
zeus::CVector3f followerToThisFlat = x168_origXf.origin - act->GetTranslation();
|
||||
followerToThisFlat.z() = 0.f;
|
||||
if (followerToThisFlat.canBeNormalized())
|
||||
followerToThisFlat.normalize();
|
||||
else
|
||||
followerToThisFlat = act->GetTransform().basis[1];
|
||||
zeus::CVector3f target = act->GetTranslation() + followerToThisFlat;
|
||||
target.z() = x168_origXf.origin.z() + followerToThisFlat.z();
|
||||
SetTransform(zeus::lookAt(act->GetTranslation(), target));
|
||||
}
|
||||
}
|
||||
AddHelper(sender);
|
||||
mgr.GetCameraManager()->AddActiveCameraHint(GetUniqueId(), mgr);
|
||||
}
|
||||
|
||||
CActor::AcceptScriptMsg(msg, sender, mgr);
|
||||
CActor::AcceptScriptMsg(msg, sender, mgr);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace urde
|
||||
|
||||
Reference in New Issue
Block a user