metaforce/Runtime/Character/CCharLayoutInfo.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

2016-04-09 23:19:17 +00:00
#include "CCharLayoutInfo.hpp"
#include "CToken.hpp"
namespace urde
{
2016-04-13 23:07:18 +00:00
zeus::CVector3f CCharLayoutInfo::GetFromParentUnrotated(const CSegId& id) const
{
2016-04-16 03:24:25 +00:00
const CCharLayoutNode::Bone& bone = x0_node->GetBoneMap()[id];
if (!x0_node->GetBoneMap().HasElement(bone.x0_parentId))
2016-04-13 23:07:18 +00:00
return bone.x4_origin;
else
{
2016-04-16 03:24:25 +00:00
const CCharLayoutNode::Bone& pBone = x0_node->GetBoneMap()[bone.x0_parentId];
2016-04-13 23:07:18 +00:00
return bone.x4_origin - pBone.x4_origin;
}
}
2016-09-06 05:52:51 +00:00
zeus::CVector3f CCharLayoutInfo::GetFromRootUnrotated(const CSegId& id) const
{
const CCharLayoutNode::Bone& bone = x0_node->GetBoneMap()[id];
return bone.x4_origin;
}
2017-11-13 06:19:18 +00:00
CSegId CCharLayoutInfo::GetSegIdFromString(std::string_view name) const
2016-09-03 03:47:57 +00:00
{
2017-11-13 06:19:18 +00:00
auto it = x18_segIdMap.find(name.data());
2016-09-03 03:47:57 +00:00
if (it == x18_segIdMap.end())
return {};
return (*it).second;
}
2016-04-09 23:19:17 +00:00
void CCharLayoutNode::Bone::read(CInputStream& in)
{
x0_parentId = CSegId(in);
x4_origin.readBig(in);
u32 chCount = in.readUint32Big();
x10_children.reserve(chCount);
for (u32 i=0 ; i<chCount ; ++i)
x10_children.emplace_back(in);
}
CCharLayoutNode::CCharLayoutNode(CInputStream& in)
2016-09-04 02:27:35 +00:00
: x0_boneMap(in.readUint32Big())
2016-04-09 23:19:17 +00:00
{
2016-09-04 02:27:35 +00:00
u32 cap = x0_boneMap.GetCapacity();
for (u32 i=0 ; i<cap ; ++i)
2016-04-09 23:19:17 +00:00
{
u32 thisId = in.readUint32Big();
2016-04-16 03:24:25 +00:00
Bone& bone = x0_boneMap[thisId];
2016-04-13 23:07:18 +00:00
bone.read(in);
2016-04-09 23:19:17 +00:00
}
}
CCharLayoutInfo::CCharLayoutInfo(CInputStream& in)
: x0_node(std::make_shared<CCharLayoutNode>(in)),
x8_segIdList(in)
{
atUint32 mapCount = in.readUint32Big();
2016-12-11 01:54:08 +00:00
for (atUint32 i=0 ; i<mapCount ; ++i)
2016-04-09 23:19:17 +00:00
{
std::string key = in.readString();
x18_segIdMap.emplace(key, in);
}
}
CFactoryFnReturn FCharLayoutInfo(const SObjectTag&, CInputStream& in, const CVParamTransfer&,
CObjectReference* selfRef)
2016-04-09 23:19:17 +00:00
{
return TToken<CCharLayoutInfo>::GetIObjObjectFor(std::make_unique<CCharLayoutInfo>(in));
}
}