2016-09-14 05:45:46 +00:00
|
|
|
#include "CAnimTreeTimeScale.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-07-10 04:55:51 +00:00
|
|
|
CAnimTreeTimeScale::CAnimTreeTimeScale(const std::weak_ptr<CAnimTreeNode>& node, float scale,
|
2017-11-13 06:19:18 +00:00
|
|
|
std::string_view name)
|
2018-01-30 01:04:01 +00:00
|
|
|
: CAnimTreeSingleChild(node, name)
|
|
|
|
, x18_timeScale(new CConstantAnimationTimeScale(scale))
|
|
|
|
, x28_targetAccelTime(CCharAnimTime::Infinity())
|
2016-09-14 05:45:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-30 01:04:01 +00:00
|
|
|
CAnimTreeTimeScale::CAnimTreeTimeScale(const std::weak_ptr<CAnimTreeNode>& node,
|
|
|
|
std::unique_ptr<IVaryingAnimationTimeScale>&& timeScale,
|
|
|
|
const CCharAnimTime& time, std::string_view name)
|
|
|
|
: CAnimTreeSingleChild(node, name)
|
|
|
|
, x18_timeScale(std::move(timeScale))
|
|
|
|
, x28_targetAccelTime(time)
|
|
|
|
{
|
|
|
|
x30_initialTime = x14_child->VGetSteadyStateAnimInfo().GetDuration() - x14_child->VGetTimeRemaining();
|
|
|
|
}
|
|
|
|
|
2017-07-10 04:55:51 +00:00
|
|
|
std::string CAnimTreeTimeScale::CreatePrimitiveName(const std::weak_ptr<CAnimTreeNode>&, float,
|
|
|
|
const CCharAnimTime&, float)
|
2016-09-14 05:45:46 +00:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
CCharAnimTime CAnimTreeTimeScale::GetRealLifeTime(const CCharAnimTime& time) const
|
|
|
|
{
|
|
|
|
CCharAnimTime timeRem = x14_child->VGetTimeRemaining();
|
|
|
|
|
2018-01-30 01:04:01 +00:00
|
|
|
CCharAnimTime ret = std::min(timeRem, time);
|
|
|
|
if (x28_targetAccelTime > CCharAnimTime())
|
2016-09-14 05:45:46 +00:00
|
|
|
{
|
2018-01-30 01:04:01 +00:00
|
|
|
if (ret < CCharAnimTime(x28_targetAccelTime - x20_curAccelTime))
|
|
|
|
return x18_timeScale->VTimeScaleIntegral(x20_curAccelTime.GetSeconds(),
|
|
|
|
(x20_curAccelTime + ret).GetSeconds());
|
2016-09-14 05:45:46 +00:00
|
|
|
else
|
|
|
|
{
|
2017-07-10 04:55:51 +00:00
|
|
|
CCharAnimTime integral =
|
2018-01-30 01:04:01 +00:00
|
|
|
x18_timeScale->VTimeScaleIntegral(x20_curAccelTime.GetSeconds(), x28_targetAccelTime.GetSeconds());
|
2016-09-14 05:45:46 +00:00
|
|
|
|
2018-01-30 01:04:01 +00:00
|
|
|
if (integral > ret)
|
|
|
|
return x18_timeScale->VFindUpperLimit(x20_curAccelTime.GetSeconds(), ret.GetSeconds()) -
|
|
|
|
x20_curAccelTime.GetSeconds();
|
2016-09-14 05:45:46 +00:00
|
|
|
else
|
2018-01-30 01:04:01 +00:00
|
|
|
return integral + (ret - integral);
|
2016-09-14 05:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 01:04:01 +00:00
|
|
|
return ret;
|
2016-09-14 05:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CAnimTreeTimeScale::VSetPhase(float phase)
|
|
|
|
{
|
|
|
|
x14_child->VSetPhase(phase);
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:17:44 +00:00
|
|
|
std::experimental::optional<std::unique_ptr<IAnimReader>> CAnimTreeTimeScale::VSimplified()
|
2016-09-14 05:45:46 +00:00
|
|
|
{
|
2018-01-30 01:04:01 +00:00
|
|
|
if (auto simp = x14_child->Simplified())
|
|
|
|
{
|
|
|
|
CAnimTreeTimeScale* newNode = new CAnimTreeTimeScale(CAnimTreeNode::Cast(std::move(*simp)),
|
|
|
|
x18_timeScale->Clone(), x28_targetAccelTime, x4_name);
|
|
|
|
newNode->x20_curAccelTime = x20_curAccelTime;
|
|
|
|
newNode->x30_initialTime = x30_initialTime;
|
|
|
|
return {std::unique_ptr<IAnimReader>(newNode)};
|
|
|
|
}
|
|
|
|
else if (x20_curAccelTime == x28_targetAccelTime)
|
|
|
|
{
|
|
|
|
return {x14_child->Clone()};
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CAnimTreeTimeScale::VGetBoolPOIList(const CCharAnimTime& time, CBoolPOINode* listOut,
|
|
|
|
u32 capacity, u32 iterator, u32 unk) const
|
|
|
|
{
|
|
|
|
CCharAnimTime useTime = (time == CCharAnimTime::Infinity()) ?
|
|
|
|
x14_child->VGetTimeRemaining() : GetRealLifeTime(time);
|
|
|
|
u32 ret = x14_child->GetBoolPOIList(useTime, listOut, capacity, iterator, unk);
|
|
|
|
if (x28_targetAccelTime > CCharAnimTime())
|
|
|
|
for (int i=0 ; i<ret ; ++i)
|
|
|
|
listOut[iterator + i].SetTime(GetRealLifeTime(listOut[i].GetTime()));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CAnimTreeTimeScale::VGetInt32POIList(const CCharAnimTime& time, CInt32POINode* listOut,
|
|
|
|
u32 capacity, u32 iterator, u32 unk) const
|
|
|
|
{
|
|
|
|
CCharAnimTime useTime = (time == CCharAnimTime::Infinity()) ?
|
|
|
|
x14_child->VGetTimeRemaining() : GetRealLifeTime(time);
|
|
|
|
u32 ret = x14_child->GetInt32POIList(useTime, listOut, capacity, iterator, unk);
|
|
|
|
if (x28_targetAccelTime > CCharAnimTime())
|
|
|
|
for (int i=0 ; i<ret ; ++i)
|
|
|
|
listOut[iterator + i].SetTime(GetRealLifeTime(listOut[i].GetTime()));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CAnimTreeTimeScale::VGetParticlePOIList(const CCharAnimTime& time, CParticlePOINode* listOut,
|
|
|
|
u32 capacity, u32 iterator, u32 unk) const
|
|
|
|
{
|
|
|
|
CCharAnimTime useTime = (time == CCharAnimTime::Infinity()) ?
|
|
|
|
x14_child->VGetTimeRemaining() : GetRealLifeTime(time);
|
|
|
|
u32 ret = x14_child->GetParticlePOIList(useTime, listOut, capacity, iterator, unk);
|
|
|
|
if (x28_targetAccelTime > CCharAnimTime())
|
|
|
|
for (int i=0 ; i<ret ; ++i)
|
|
|
|
listOut[iterator + i].SetTime(GetRealLifeTime(listOut[i].GetTime()));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CAnimTreeTimeScale::VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut,
|
|
|
|
u32 capacity, u32 iterator, u32 unk) const
|
|
|
|
{
|
|
|
|
CCharAnimTime useTime = (time == CCharAnimTime::Infinity()) ?
|
|
|
|
x14_child->VGetTimeRemaining() : GetRealLifeTime(time);
|
|
|
|
u32 ret = x14_child->GetSoundPOIList(useTime, listOut, capacity, iterator, unk);
|
|
|
|
if (x28_targetAccelTime > CCharAnimTime())
|
|
|
|
for (int i=0 ; i<ret ; ++i)
|
|
|
|
listOut[iterator + i].SetTime(GetRealLifeTime(listOut[i].GetTime()));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAnimTreeTimeScale::VGetBoolPOIState(const char* name) const
|
|
|
|
{
|
|
|
|
return x14_child->VGetBoolPOIState(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 CAnimTreeTimeScale::VGetInt32POIState(const char* name) const
|
|
|
|
{
|
|
|
|
return x14_child->VGetInt32POIState(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
CParticleData::EParentedMode CAnimTreeTimeScale::VGetParticlePOIState(const char* name) const
|
|
|
|
{
|
|
|
|
return x14_child->VGetParticlePOIState(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
CAnimTreeEffectiveContribution CAnimTreeTimeScale::VGetContributionOfHighestInfluence() const
|
|
|
|
{
|
|
|
|
CAnimTreeEffectiveContribution c = x14_child->VGetContributionOfHighestInfluence();
|
|
|
|
return {c.GetContributionWeight(), c.GetPrimitiveName(), VGetSteadyStateAnimInfo(),
|
|
|
|
VGetTimeRemaining(), c.GetAnimDatabaseIndex()};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<IAnimReader> CAnimTreeTimeScale::VGetBestUnblendedChild() const
|
|
|
|
{
|
|
|
|
if (std::shared_ptr<IAnimReader> bestChild = x14_child->VGetBestUnblendedChild())
|
|
|
|
{
|
|
|
|
CAnimTreeTimeScale* newNode = new CAnimTreeTimeScale(CAnimTreeNode::Cast(bestChild->Clone()),
|
|
|
|
x18_timeScale->Clone(), x28_targetAccelTime, x4_name);
|
|
|
|
newNode->x20_curAccelTime = x20_curAccelTime;
|
|
|
|
newNode->x30_initialTime = x30_initialTime;
|
|
|
|
return {std::shared_ptr<IAnimReader>(newNode)};
|
|
|
|
}
|
2016-09-14 05:45:46 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-01-30 01:04:01 +00:00
|
|
|
std::unique_ptr<IAnimReader> CAnimTreeTimeScale::VClone() const
|
|
|
|
{
|
|
|
|
CAnimTreeTimeScale* newNode = new CAnimTreeTimeScale(CAnimTreeNode::Cast(x14_child->Clone()),
|
|
|
|
x18_timeScale->Clone(), x28_targetAccelTime, x4_name);
|
|
|
|
newNode->x20_curAccelTime = x20_curAccelTime;
|
|
|
|
newNode->x30_initialTime = x30_initialTime;
|
|
|
|
return {std::unique_ptr<IAnimReader>(newNode)};
|
|
|
|
}
|
|
|
|
|
|
|
|
CSteadyStateAnimInfo CAnimTreeTimeScale::VGetSteadyStateAnimInfo() const
|
|
|
|
{
|
|
|
|
CSteadyStateAnimInfo ssInfo = x14_child->VGetSteadyStateAnimInfo();
|
|
|
|
if (x28_targetAccelTime == CCharAnimTime::Infinity())
|
|
|
|
{
|
|
|
|
return {ssInfo.IsLooping(),
|
|
|
|
x18_timeScale->VFindUpperLimit(0.f, ssInfo.GetDuration().GetSeconds()), ssInfo.GetOffset()};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCharAnimTime time;
|
|
|
|
if (x20_curAccelTime.GreaterThanZero())
|
|
|
|
time = x18_timeScale->VTimeScaleIntegral(0.f, x20_curAccelTime.GetSeconds());
|
|
|
|
return {ssInfo.IsLooping(), x30_initialTime + time + VGetTimeRemaining(), ssInfo.GetOffset()};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCharAnimTime CAnimTreeTimeScale::VGetTimeRemaining() const
|
|
|
|
{
|
|
|
|
CCharAnimTime timeRem = x14_child->VGetTimeRemaining();
|
|
|
|
if (x28_targetAccelTime == CCharAnimTime::Infinity())
|
|
|
|
return CCharAnimTime(x18_timeScale->VFindUpperLimit(x20_curAccelTime.GetSeconds(),
|
|
|
|
timeRem.GetSeconds())) - x20_curAccelTime;
|
|
|
|
else
|
|
|
|
return GetRealLifeTime(timeRem);
|
|
|
|
}
|
|
|
|
|
|
|
|
SAdvancementResults CAnimTreeTimeScale::VAdvanceView(const CCharAnimTime& dt)
|
|
|
|
{
|
|
|
|
if (dt.EqualsZero() && dt > CCharAnimTime())
|
|
|
|
return x14_child->VAdvanceView(dt);
|
|
|
|
|
|
|
|
CCharAnimTime origAccelTime = x20_curAccelTime;
|
|
|
|
CCharAnimTime newTime = x20_curAccelTime + dt;
|
|
|
|
if (newTime < x28_targetAccelTime)
|
|
|
|
{
|
|
|
|
SAdvancementResults res = x14_child->VAdvanceView(
|
|
|
|
x18_timeScale->VTimeScaleIntegral(origAccelTime.GetSeconds(), newTime.GetSeconds()));
|
|
|
|
if (res.x0_remTime.EqualsZero())
|
|
|
|
{
|
|
|
|
x20_curAccelTime = newTime;
|
|
|
|
res.x0_remTime = CCharAnimTime();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x20_curAccelTime = x18_timeScale->VFindUpperLimit(origAccelTime.GetSeconds(),
|
|
|
|
(newTime - res.x0_remTime).GetSeconds());
|
|
|
|
res.x0_remTime = dt - (x20_curAccelTime - origAccelTime);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCharAnimTime newDt(x18_timeScale->VTimeScaleIntegral(origAccelTime.GetSeconds(),
|
|
|
|
x28_targetAccelTime.GetSeconds()));
|
|
|
|
SAdvancementResults res2;
|
|
|
|
if (newDt.GreaterThanZero())
|
|
|
|
res2 = x14_child->VAdvanceView(newDt);
|
|
|
|
res2.x0_remTime = res2.x0_remTime + (newTime - x28_targetAccelTime);
|
|
|
|
return res2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-14 05:45:46 +00:00
|
|
|
}
|