metaforce/Runtime/Character/CAnimData.cpp

508 lines
14 KiB
C++
Raw Normal View History

#include "CAnimData.hpp"
#include "CCharacterInfo.hpp"
#include "CCharLayoutInfo.hpp"
#include "Graphics/CSkinnedModel.hpp"
#include "CCharacterFactory.hpp"
#include "CAnimationManager.hpp"
#include "CTransitionManager.hpp"
2016-04-16 03:24:25 +00:00
#include "CAdditiveAnimPlayback.hpp"
#include "CBoolPOINode.hpp"
#include "CInt32POINode.hpp"
#include "CParticlePOINode.hpp"
#include "CSoundPOINode.hpp"
#include "CParticleGenInfo.hpp"
2016-04-14 21:42:47 +00:00
#include "IAnimReader.hpp"
#include "CAnimTreeNode.hpp"
2016-08-21 00:04:50 +00:00
#include "CAnimPerSegmentData.hpp"
#include "CSegStatementSet.hpp"
2016-08-21 20:39:18 +00:00
#include "CStateManager.hpp"
namespace urde
{
rstl::reserved_vector<CBoolPOINode, 8>CAnimData::g_BoolPOINodes;
rstl::reserved_vector<CInt32POINode, 16> CAnimData::g_Int32POINodes;
rstl::reserved_vector<CParticlePOINode, 20> CAnimData::g_ParticlePOINodes;
rstl::reserved_vector<CSoundPOINode, 20> CAnimData::g_SoundPOINodes;
2016-04-14 03:32:27 +00:00
void CAnimData::FreeCache()
{
}
void CAnimData::InitializeCache()
{
}
2016-04-15 03:02:21 +00:00
CAnimData::CAnimData(ResId id,
const CCharacterInfo& character,
int defaultAnim, int charIdx, bool loop,
const TLockedToken<CCharLayoutInfo>& layout,
const TToken<CSkinnedModel>& model,
2016-04-29 10:08:46 +00:00
const rstl::optional_object<TToken<CMorphableSkinnedModel>>& iceModel,
const std::weak_ptr<CAnimSysContext>& ctx,
const std::shared_ptr<CAnimationManager>& animMgr,
const std::shared_ptr<CTransitionManager>& transMgr,
const TLockedToken<CCharacterFactory>& charFactory)
2016-05-21 03:02:09 +00:00
: x0_charFactory(charFactory),
xc_charInfo(character),
xcc_layoutData(layout),
xd8_modelData(model),
xfc_animCtx(ctx.lock()),
x100_animMgr(animMgr),
x1d8_selfId(id),
x1fc_transMgr(transMgr),
x204_charIdx(charIdx),
x208_defaultAnim(defaultAnim),
2016-08-21 00:04:50 +00:00
x220_25_loop(loop),
x224_pose(layout->GetSegIdList().GetList().size()),
x2fc_poseBuilder(layout)
{
2016-04-15 03:02:21 +00:00
if (iceModel)
xe4_iceModelData = *iceModel;
g_BoolPOINodes.resize(8);
g_Int32POINodes.resize(16);
g_ParticlePOINodes.resize(20);
g_SoundPOINodes.resize(20);
x108_aabb = xd8_modelData->GetModel()->GetAABB();
x120_particleDB.CacheParticleDesc(xc_charInfo.GetParticleResData());
}
2016-04-16 03:24:25 +00:00
ResId CAnimData::GetEventResourceIdForAnimResourceId(ResId id) const
2016-04-14 03:32:27 +00:00
{
2016-04-16 03:24:25 +00:00
return x0_charFactory->GetEventResourceIdForAnimResourceId(id);
2016-04-14 03:32:27 +00:00
}
void CAnimData::AddAdditiveSegData(const CSegIdList& list, CSegStatementSet& stSet)
{
2016-08-21 00:04:50 +00:00
for (std::pair<u32, CAdditiveAnimPlayback>& additive : x1048_additiveAnims)
if (additive.second.GetTargetWeight() > 0.00001f)
additive.second.AddToSegStatementSet(list, *xcc_layoutData.GetObj(), stSet);
}
static void AdvanceAnimationTree(std::weak_ptr<CAnimTreeNode>& anim, const CCharAnimTime& dt)
2016-04-14 03:32:27 +00:00
{
}
2016-08-21 20:39:18 +00:00
SAdvancementDeltas CAnimData::AdvanceAdditiveAnims(float dt)
2016-04-14 03:32:27 +00:00
{
CCharAnimTime time(dt);
2016-08-21 00:04:50 +00:00
for (std::pair<u32, CAdditiveAnimPlayback>& additive : x1048_additiveAnims)
{
if (additive.second.GetA())
{
while (time.GreaterThanZero() && std::fabs(time) >= 0.00001f)
{
//additive.second.GetAnim()->GetInt32POIList(time, );
}
}
else
{
}
}
2016-08-23 03:12:50 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
2016-08-21 20:39:18 +00:00
SAdvancementDeltas CAnimData::UpdateAdditiveAnims(float dt)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
return AdvanceAdditiveAnims(dt);
2016-04-14 03:32:27 +00:00
}
bool CAnimData::IsAdditiveAnimation(u32) const
{
2016-05-21 03:02:09 +00:00
return false;
2016-04-14 03:32:27 +00:00
}
std::shared_ptr<CAnimTreeNode> CAnimData::GetAdditiveAnimationTree(u32) const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
bool CAnimData::IsAdditiveAnimationActive(u32) const
{
2016-05-21 03:02:09 +00:00
return false;
2016-04-14 03:32:27 +00:00
}
void CAnimData::DelAdditiveAnimation(u32)
{
}
void CAnimData::AddAdditiveAnimation(u32, float, bool, bool)
{
}
std::shared_ptr<CAnimationManager> CAnimData::GetAnimationManager()
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
void CAnimData::SetPhase(float)
{
}
void CAnimData::Touch(const CSkinnedModel& model, int) const
{
}
2016-04-14 21:42:47 +00:00
SAdvancementDeltas CAnimData::GetAdvancementDeltas(const CCharAnimTime& a,
const CCharAnimTime& b) const
2016-04-14 03:32:27 +00:00
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
CCharAnimTime CAnimData::GetTimeOfUserEvent(EUserEventType, const CCharAnimTime& time) const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
void CAnimData::MultiplyPlaybackRate(float)
{
}
void CAnimData::SetPlaybackRate(float)
{
}
void CAnimData::SetRandomPlaybackRate(CRandom16&)
{
}
void CAnimData::CalcPlaybackAlignmentParms(const CAnimPlaybackParms& parms,
2016-05-21 03:02:09 +00:00
const std::weak_ptr<CAnimTreeNode>& node)
2016-04-14 03:32:27 +00:00
{
}
zeus::CTransform CAnimData::GetLocatorTransform(CSegId id, const CCharAnimTime* time) const
{
2016-09-03 03:47:57 +00:00
if (id == 0xFF)
return {};
zeus::CTransform ret;
if (!x220_31_poseCached)
2016-09-03 03:50:00 +00:00
{
2016-09-03 03:47:57 +00:00
const_cast<CAnimData*>(this)->RecalcPoseBuilder(time);
2016-09-03 03:50:00 +00:00
const_cast<CAnimData*>(this)->x220_31_poseCached = true;
}
2016-09-03 03:47:57 +00:00
x2fc_poseBuilder.BuildTransform(id, ret);
return ret;
2016-04-14 03:32:27 +00:00
}
zeus::CTransform CAnimData::GetLocatorTransform(const std::string& name, const CCharAnimTime* time) const
{
2016-09-03 03:47:57 +00:00
return GetLocatorTransform(xcc_layoutData->GetSegIdFromString(name), time);
2016-04-14 03:32:27 +00:00
}
bool CAnimData::IsAnimTimeRemaining(float, const std::string& name) const
{
2016-05-21 03:02:09 +00:00
return false;
2016-04-14 03:32:27 +00:00
}
float CAnimData::GetAnimTimeRemaining(const std::string& name) const
{
2016-05-21 03:02:09 +00:00
return 0.f;
2016-04-14 03:32:27 +00:00
}
float CAnimData::GetAnimationDuration(int) const
{
2016-05-21 03:02:09 +00:00
return 0.f;
2016-04-14 03:32:27 +00:00
}
std::shared_ptr<CAnimSysContext> CAnimData::GetAnimSysContext() const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
std::shared_ptr<CAnimationManager> CAnimData::GetAnimationManager() const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
2016-08-21 00:04:50 +00:00
void CAnimData::RecalcPoseBuilder(const CCharAnimTime* time)
2016-04-14 03:32:27 +00:00
{
2016-08-31 23:31:12 +00:00
if (!x1f8_animRoot)
return;
2016-08-21 00:04:50 +00:00
const CSegIdList& segIdList = GetCharLayoutInfo().GetSegIdList();
CSegStatementSet segSet;
if (time)
x1f8_animRoot->VGetSegStatementSet(segIdList, segSet, *time);
else
x1f8_animRoot->VGetSegStatementSet(segIdList, segSet);
AddAdditiveSegData(segIdList, segSet);
for (const CSegId& id : segIdList.GetList())
{
if (id == 3)
continue;
CAnimPerSegmentData& segData = segSet[id];
x2fc_poseBuilder.Insert(id, segData.x0_rotation, segData.x10_offset);
}
2016-04-14 03:32:27 +00:00
}
void CAnimData::RenderAuxiliary(const CFrustumPlanes& frustum) const
{
}
2016-08-21 20:39:18 +00:00
void CAnimData::Render(CSkinnedModel& model, const CModelFlags& drawFlags,
2016-04-29 10:08:46 +00:00
const rstl::optional_object<CVertexMorphEffect>& morphEffect,
2016-08-21 20:39:18 +00:00
const float* morphMagnitudes)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
SetupRender(model, drawFlags, morphEffect, morphMagnitudes);
DrawSkinnedModel(model, drawFlags);
2016-04-14 03:32:27 +00:00
}
2016-08-21 20:39:18 +00:00
void CAnimData::SetupRender(CSkinnedModel& model,
const CModelFlags& drawFlags,
2016-04-29 10:08:46 +00:00
const rstl::optional_object<CVertexMorphEffect>& morphEffect,
2016-08-21 20:39:18 +00:00
const float* morphMagnitudes)
{
if (!x220_30_poseBuilt)
{
x2fc_poseBuilder.BuildNoScale(x224_pose);
x220_30_poseBuilt = true;
}
PoseSkinnedModel(model, x224_pose, drawFlags, morphEffect, morphMagnitudes);
}
void CAnimData::DrawSkinnedModel(CSkinnedModel& model, const CModelFlags& flags)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
model.Draw(flags);
2016-04-14 03:32:27 +00:00
}
void CAnimData::PreRender()
{
2016-08-21 00:04:50 +00:00
if (!x220_31_poseCached)
{
RecalcPoseBuilder(nullptr);
x220_31_poseCached = true;
2016-08-21 20:39:18 +00:00
x220_30_poseBuilt = false;
2016-08-21 00:04:50 +00:00
}
2016-04-14 03:32:27 +00:00
}
void CAnimData::BuildPose()
{
}
void CAnimData::PrimitiveSetToTokenVector(const std::set<CPrimitive>& primSet, std::vector<CToken>& tokensOut)
{
}
void CAnimData::GetAnimationPrimitives(const CAnimPlaybackParms& parms, std::set<CPrimitive>& primsOut) const
{
}
void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool)
{
}
2016-09-02 17:50:03 +00:00
SAdvancementDeltas CAnimData::DoAdvance(float dt, bool& b1, CRandom16& random, bool advTree)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
b1 = false;
zeus::CVector3f offsetPre, offsetPost;
zeus::CQuaternion quatPre, quatPost;
ResetPOILists();
float scaleDt = dt * x200_speedScale;
if (x2fc_poseBuilder.HasRoot())
{
SAdvancementDeltas deltas = UpdateAdditiveAnims(scaleDt);
offsetPre = deltas.x0_posDelta;
quatPre = deltas.xc_rotDelta;
}
if (!x220_24_animating)
{
b1 = true;
return {};
}
if (x220_29_)
{
x220_29_ = false;
b1 = true;
}
2016-09-02 17:50:03 +00:00
if (advTree && x1f8_animRoot)
2016-08-21 20:39:18 +00:00
{
SetRandomPlaybackRate(random);
CCharAnimTime time(scaleDt);
if (x220_25_loop)
{
while (time.GreaterThanZero() && !time.EpsilonZero())
{
x210_passedIntCount += x1f8_animRoot->GetInt32POIList(time, g_Int32POINodes.data(), 16, x210_passedIntCount, 0);
x20c_passedBoolCount += x1f8_animRoot->GetBoolPOIList(time, g_BoolPOINodes.data(), 16, x20c_passedBoolCount, 0);
x214_passedParticleCount += x1f8_animRoot->GetParticlePOIList(time, g_ParticlePOINodes.data(), 16, x214_passedParticleCount, 0);
x218_passedSoundCount += x1f8_animRoot->GetSoundPOIList(time, g_SoundPOINodes.data(), 16, x218_passedSoundCount, 0);
AdvanceAnim(time, offsetPost, quatPost);
}
}
else
{
CCharAnimTime remTime = x1f8_animRoot->VGetTimeRemaining();
while (remTime.GreaterThanZero() && !remTime.EpsilonZero())
{
x210_passedIntCount += x1f8_animRoot->GetInt32POIList(time, g_Int32POINodes.data(), 16, x210_passedIntCount, 0);
x20c_passedBoolCount += x1f8_animRoot->GetBoolPOIList(time, g_BoolPOINodes.data(), 16, x20c_passedBoolCount, 0);
x214_passedParticleCount += x1f8_animRoot->GetParticlePOIList(time, g_ParticlePOINodes.data(), 16, x214_passedParticleCount, 0);
x218_passedSoundCount += x1f8_animRoot->GetSoundPOIList(time, g_SoundPOINodes.data(), 16, x218_passedSoundCount, 0);
AdvanceAnim(time, offsetPost, quatPost);
remTime = x1f8_animRoot->VGetTimeRemaining();
time = std::max(0.f, std::min(float(remTime), float(time)));
if (remTime.EpsilonZero())
{
x220_24_animating = false;
x1dc_ = zeus::CVector3f::skZero;
x220_28_ = false;
x220_26_ = false;
}
}
}
x220_31_poseCached = false;
x220_30_poseBuilt = false;
}
return {offsetPost + offsetPre, quatPost * quatPre};
2016-04-14 03:32:27 +00:00
}
2016-08-21 20:39:18 +00:00
SAdvancementDeltas CAnimData::Advance(float dt, const zeus::CVector3f& scale,
2016-09-02 17:50:03 +00:00
CStateManager& stateMgr, TAreaId aid, bool advTree)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
bool b2;
2016-09-02 17:50:03 +00:00
return DoAdvance(dt, b2, *stateMgr.GetActiveRandom(), advTree);
2016-08-21 20:39:18 +00:00
if (b2)
x120_particleDB.SuspendAllActiveEffects(stateMgr);
for (CParticlePOINode& node : g_ParticlePOINodes)
{
if (node.GetCharacterIndex() == -1 || node.GetCharacterIndex() == x204_charIdx)
2016-08-21 20:39:18 +00:00
{
x120_particleDB.StartEffect(node.GetName(), node.GetFlags(), node.GetParticleData(),
scale, stateMgr, aid, x21c_);
}
}
2016-04-14 03:32:27 +00:00
}
2016-09-02 17:50:03 +00:00
SAdvancementDeltas CAnimData::AdvanceIgnoreParticles(float dt, CRandom16& random, bool advTree)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
bool b2;
2016-09-02 17:50:03 +00:00
return DoAdvance(dt, b2, random, advTree);
2016-04-14 03:32:27 +00:00
}
2016-08-21 20:39:18 +00:00
void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus::CQuaternion& quat)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
SAdvancementResults results;
std::shared_ptr<IAnimReader> simplified;
if (x104_)
{
results = x1f8_animRoot->VAdvanceView(time);
simplified = x1f8_animRoot->VSimplified();
}
if (simplified)
{
if (simplified->IsCAnimTreeNode())
{
if (x1f8_animRoot != simplified)
x1f8_animRoot = std::move(simplified);
}
else
x1f8_animRoot.reset();
}
if ((x220_28_ || x220_27_) && x210_passedIntCount > 0)
{
for (CInt32POINode& node : g_Int32POINodes)
{
if (node.GetPoiType() == EPOIType::UserEvent)
{
switch (EUserEventType(node.GetValue()))
{
case EUserEventType::AlignTargetPosStart:
{
x220_26_ = true;
break;
}
case EUserEventType::AlignTargetPos:
{
x1dc_ = zeus::CVector3f::skZero;
x220_28_ = false;
x220_26_ = false;
break;
}
case EUserEventType::AlignTargetRot:
{
x1e8_ = zeus::CQuaternion::skNoRotation;
x220_27_ = false;
break;
}
default: break;
}
}
}
}
offset += results.x8_deltas.x0_posDelta;
if (x220_26_)
offset += x1dc_ * time;
zeus::CQuaternion rot = results.x8_deltas.xc_rotDelta * x1e8_;
quat = quat * rot;
x1dc_ = rot.transform(x1dc_);
time = results.x0_remTime;
2016-04-14 03:32:27 +00:00
}
void CAnimData::SetXRayModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules)
{
}
void CAnimData::SetInfraModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules)
{
}
2016-08-21 20:39:18 +00:00
void CAnimData::PoseSkinnedModel(CSkinnedModel& model, const CPoseAsTransforms& pose,
const CModelFlags& drawFlags,
2016-04-29 10:08:46 +00:00
const rstl::optional_object<CVertexMorphEffect>& morphEffect,
2016-08-21 20:39:18 +00:00
const float* morphMagnitudes)
2016-04-14 03:32:27 +00:00
{
2016-08-21 20:39:18 +00:00
model.Calculate(pose, drawFlags, morphEffect, morphMagnitudes);
2016-04-14 03:32:27 +00:00
}
void CAnimData::AdvanceParticles(const zeus::CTransform& xf, float,
const zeus::CVector3f&, CStateManager& stateMgr)
{
}
void CAnimData::GetAverageVelocity(int) const
{
}
void CAnimData::ResetPOILists()
{
}
CSegId CAnimData::GetLocatorSegId(const std::string& name) const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
zeus::CAABox CAnimData::GetBoundingBox(const zeus::CTransform& xf) const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
zeus::CAABox CAnimData::GetBoundingBox() const
{
2016-05-21 03:02:09 +00:00
return {};
2016-04-14 03:32:27 +00:00
}
}