metaforce/Runtime/Character/IMetaAnim.cpp

54 lines
1.7 KiB
C++
Raw Normal View History

#include "Runtime/Character/IMetaAnim.hpp"
#include <array>
#include "Runtime/Character/CAnimTreeNode.hpp"
#include "Runtime/Character/CBoolPOINode.hpp"
#include "Runtime/Character/CCharAnimTime.hpp"
#include "Runtime/Character/IAnimReader.hpp"
2016-04-11 07:10:28 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2016-04-11 07:10:28 +00:00
2018-12-08 05:30:43 +00:00
std::shared_ptr<CAnimTreeNode> IMetaAnim::GetAnimationTree(const CAnimSysContext& animSys,
const CMetaAnimTreeBuildOrders& orders) const {
if (orders.x44_singleAdvance) {
std::shared_ptr<CAnimTreeNode> tree = VGetAnimationTree(animSys, CMetaAnimTreeBuildOrders::NoSpecialOrders());
if (orders.x44_singleAdvance->IsTime() || orders.x44_singleAdvance->IsString()) {
CCharAnimTime time = GetTime(*orders.x44_singleAdvance, *tree);
AdvanceAnim(*tree, time);
2016-08-27 21:16:44 +00:00
}
2018-12-08 05:30:43 +00:00
return tree;
}
return VGetAnimationTree(animSys, CMetaAnimTreeBuildOrders::NoSpecialOrders());
2016-04-11 07:10:28 +00:00
}
2018-12-08 05:30:43 +00:00
void IMetaAnim::AdvanceAnim(IAnimReader& anim, const CCharAnimTime& dt) {
CCharAnimTime remDt = dt;
while (remDt > CCharAnimTime()) {
SAdvancementResults res = anim.VAdvanceView(remDt);
remDt = res.x0_remTime;
}
2016-04-11 07:10:28 +00:00
}
2018-12-08 05:30:43 +00:00
CCharAnimTime IMetaAnim::GetTime(const CPreAdvanceIndicator& ind, const IAnimReader& anim) {
if (ind.IsTime()) {
2018-12-08 05:30:43 +00:00
return ind.GetTime();
}
2016-04-11 07:10:28 +00:00
std::array<CBoolPOINode, 64> nodes;
const CCharAnimTime rem = anim.VGetTimeRemaining();
const size_t count = anim.VGetBoolPOIList(rem, nodes.data(), nodes.size(), 0, 0);
2018-12-08 05:30:43 +00:00
const char* cmpStr = ind.GetString();
for (size_t i = 0; i < count; ++i) {
const CBoolPOINode& node = nodes[i];
if (node.GetString() != cmpStr || !node.GetValue()) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
return node.GetTime();
}
2016-04-11 07:10:28 +00:00
2018-12-08 05:30:43 +00:00
return {};
2016-04-11 07:10:28 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce