2016-04-10 04:49:02 +00:00
|
|
|
#include "CPASDatabase.hpp"
|
2016-08-21 05:47:47 +00:00
|
|
|
#include "CPASAnimParmData.hpp"
|
|
|
|
#include "CRandom16.hpp"
|
2016-04-10 04:49:02 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
void CPASDatabase::AddAnimState(CPASAnimState&& state)
|
|
|
|
{
|
|
|
|
auto it = std::lower_bound(x0_states.begin(), x0_states.end(), state,
|
2016-04-27 19:59:38 +00:00
|
|
|
[](const CPASAnimState& item, const CPASAnimState& test) -> bool {return item.GetStateId() < test.GetStateId();});
|
2016-04-10 04:49:02 +00:00
|
|
|
x0_states.insert(it, std::move(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
CPASDatabase::CPASDatabase(CInputStream& in)
|
|
|
|
{
|
|
|
|
in.readUint32Big();
|
|
|
|
u32 animStateCount = in.readUint32Big();
|
|
|
|
u32 defaultState = in.readUint32Big();
|
|
|
|
|
|
|
|
x0_states.reserve(animStateCount);
|
|
|
|
for (u32 i=0 ; i<animStateCount ; ++i)
|
|
|
|
{
|
|
|
|
CPASAnimState state(in);
|
|
|
|
AddAnimState(std::move(state));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animStateCount)
|
|
|
|
SetDefaultState(defaultState);
|
|
|
|
}
|
|
|
|
|
2017-07-06 21:06:56 +00:00
|
|
|
std::pair<float, s32> CPASDatabase::FindBestAnimation(const CPASAnimParmData& data, s32 ignoreAnim) const
|
2016-08-21 05:47:47 +00:00
|
|
|
{
|
|
|
|
CRandom16 rnd(4660);
|
2017-07-06 21:06:56 +00:00
|
|
|
return FindBestAnimation(data, rnd, ignoreAnim);
|
2016-08-21 05:47:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 21:06:56 +00:00
|
|
|
std::pair<float, s32> CPASDatabase::FindBestAnimation(const CPASAnimParmData& data, CRandom16& rand, s32 ignoreAnim) const
|
2016-08-21 05:47:47 +00:00
|
|
|
{
|
2017-07-11 07:17:03 +00:00
|
|
|
auto it = rstl::binary_find(x0_states.cbegin(), x0_states.cend(), data.GetStateId(),
|
|
|
|
[](const CPASAnimState& item) {return item.GetStateId();});
|
2016-08-21 05:47:47 +00:00
|
|
|
|
2017-07-11 07:17:03 +00:00
|
|
|
if (it == x0_states.cend())
|
2016-08-21 05:47:47 +00:00
|
|
|
return {0.f, -1};
|
|
|
|
|
2017-07-06 21:06:56 +00:00
|
|
|
return (*it).FindBestAnimation(data.GetAnimParmData(), rand, ignoreAnim);
|
2016-08-21 05:47:47 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 04:49:02 +00:00
|
|
|
}
|