2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Character/CMetaAnimRandom.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/Character/CAnimSysContext.hpp"
|
|
|
|
#include "Runtime/Character/CMetaAnimFactory.hpp"
|
2016-04-10 21:22:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
|
|
|
|
|
|
|
CMetaAnimRandom::RandomData CMetaAnimRandom::CreateRandomData(CInputStream& in) {
|
|
|
|
CMetaAnimRandom::RandomData ret;
|
|
|
|
u32 randCount = in.readUint32Big();
|
|
|
|
ret.reserve(randCount);
|
2016-04-10 21:22:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (u32 i = 0; i < randCount; ++i) {
|
|
|
|
std::shared_ptr<IMetaAnim> metaAnim = CMetaAnimFactory::CreateMetaAnim(in);
|
|
|
|
ret.emplace_back(std::move(metaAnim), in.readUint32Big());
|
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return ret;
|
2016-04-10 21:22:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CMetaAnimRandom::CMetaAnimRandom(CInputStream& in) : x4_randomData(CreateRandomData(in)) {}
|
|
|
|
|
|
|
|
void CMetaAnimRandom::GetUniquePrimitives(std::set<CPrimitive>& primsOut) const {
|
|
|
|
for (const auto& pair : x4_randomData)
|
|
|
|
pair.first->GetUniquePrimitives(primsOut);
|
2016-04-10 21:22:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::shared_ptr<CAnimTreeNode> CMetaAnimRandom::VGetAnimationTree(const CAnimSysContext& animSys,
|
|
|
|
const CMetaAnimTreeBuildOrders& orders) const {
|
2020-05-13 00:25:30 +00:00
|
|
|
const u32 r = animSys.x8_random->Range(1, 100);
|
2018-12-08 05:30:43 +00:00
|
|
|
const std::pair<std::shared_ptr<IMetaAnim>, u32>* useRd = nullptr;
|
2020-05-13 00:25:30 +00:00
|
|
|
for (const auto& rd : x4_randomData) {
|
2018-12-08 05:30:43 +00:00
|
|
|
useRd = &rd;
|
2020-05-13 00:25:30 +00:00
|
|
|
if (r <= rd.second) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-05-13 00:25:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return useRd->first->GetAnimationTree(animSys, orders);
|
2016-04-10 21:22:59 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
} // namespace urde
|