Skip to content

Commit

Permalink
RpAnimBlend Plugin (#694)
Browse files Browse the repository at this point in the history
* Fix `ManageTasks`
* Flush all loggers in `unreachable`
* Flush loggers every 100ms
* Fix random nan bug + add more asserts to anim code
* Fix `CAnimBlendAssociation::UpdateTime`
* fix `CAnimBlendAssociation::UpdateBlend`
* CMatix: Add `bKeepPos` to `RotateX/Y/Z`
* Fix `CVehicle::SetComponentRotation`
* FxManager_c: Add note
* Refactor `CStreaming::AddEntity`
* Refactor `CCollision::CalculateTrianglePlanes`
* Refactor `CCollision::RemoveTrianglePlanes`
* Fix anim flag function names
* Proper fix of `RtAnimInterpolatorSetCurrentAnim` (UV anims need original interpolator code) (Fixes #602 #526)
* Add missing `case TASK_NONE` in `CTaskComplexEnterCar::CreateNextSubTask`
* Fix `CPathFind::SetLinksBridgeLights`
* Template wrapper instead of 1000+ lines of copy paste
* Verious smaller fixes
  • Loading branch information
Pirulax authored Feb 24, 2024
1 parent be7867e commit 79fbbb9
Show file tree
Hide file tree
Showing 94 changed files with 4,757 additions and 1,310 deletions.
3 changes: 3 additions & 0 deletions source/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ template<typename... Ts>

spdlog::error(mbMsg);
spdlog::dump_backtrace();
spdlog::apply_all([](std::shared_ptr<spdlog::logger> l) { // Flush all sinks immidiately
l->flush();
});

const auto result = MessageBox(
NULL,
Expand Down
4 changes: 4 additions & 0 deletions source/InjectHooksMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,15 @@ void InjectHooksMain() {
CLocalisation::InjectHooks();
CSimpleVariablesSaveStructure::InjectHooks();
CPedGeometryAnalyser::InjectHooks();

NodeNamePlugin::InjectHooks();
JPegPlugin::InjectHooks();
PipelinePlugin::InjectHooks();
RpAnimBlendPlugin::InjectHooks();
CCollisionPlugin::InjectHooks();
BreakablePlugin::InjectHooks();
RtAnim::InjectHooks();

CIplStore::InjectHooks();
cHandlingDataMgr::InjectHooks();
CLoadingScreen::InjectHooks();
Expand Down
4 changes: 3 additions & 1 deletion source/app/app_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ LONG WINAPI WindowsExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) {
}

notsa::Logging::Logging() {
using namespace std::chrono_literals;
#if 0
while (!IsDebuggerPresent()) {
Sleep(1);
Expand All @@ -213,7 +214,8 @@ notsa::Logging::Logging() {
m_sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());

spdlog::set_default_logger(Create("default"));

spdlog::flush_every(100ms);

AddVectoredExceptionHandler(1, WindowsExceptionHandler);
}

Expand Down
3 changes: 2 additions & 1 deletion source/extensions/FixedFloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class FixedFloat {

constexpr operator float() const { return static_cast<float>(value) / CompressValue; }

void Set(float v, bool round) { value = round ? static_cast<T>(v * CompressValue + 0.5f) : static_cast<T>(v * CompressValue); }
void Set(float v, bool round) { value = round ? static_cast<T>(v * CompressValue + 0.5f) : static_cast<T>(v * CompressValue); }
//float Get(bool round) const { return round ? (float)v * CompressValue + 0.5f; }

// I'm not ready for this
//friend FixedFloat operator+(const FixedFloat& a, const FixedFloat& b) { return a.value + b.value; }
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/FixedQuat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
template<typename T, float CompressValue>
struct FixedQuat {
constexpr FixedQuat() = default;
constexpr FixedQuat(CQuaternion q) : x(q.x), y(q.y), z(q.z) {}
constexpr FixedQuat(CQuaternion q) : x(q.x), y(q.y), z(q.z), w(q.w) {}
constexpr FixedQuat(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W) {}

constexpr operator CQuaternion() const { return CQuaternion{ x, y, z, w }; }
Expand Down
1,156 changes: 578 additions & 578 deletions source/game_sa/Animation/AnimAssocDescriptions.h

Large diffs are not rendered by default.

96 changes: 53 additions & 43 deletions source/game_sa/Animation/AnimBlendAssociation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ CAnimBlendAssociation::CAnimBlendAssociation(CAnimBlendAssociation& assoc) {
m_TimeStep = 0.0f;
m_nCallbackType = ANIM_BLEND_CALLBACK_NONE;
Init(assoc);
if ((m_Flags & ANIMATION_BLOCK_REFERENCED) == 0) {
if ((m_Flags & ANIMATION_REFERENCE_BLOCK) == 0) {
CAnimManager::AddAnimBlockRef(m_BlendHier->m_nAnimBlockId);
m_Flags |= ANIMATION_BLOCK_REFERENCED;
m_Flags |= ANIMATION_REFERENCE_BLOCK;
}
}

Expand All @@ -78,9 +78,9 @@ CAnimBlendAssociation::CAnimBlendAssociation(CAnimBlendStaticAssociation& assoc)
m_TimeStep = 0.0f;
m_nCallbackType = ANIM_BLEND_CALLBACK_NONE;
Init(assoc);
if ((m_Flags & ANIMATION_BLOCK_REFERENCED) == 0) {
if ((m_Flags & ANIMATION_REFERENCE_BLOCK) == 0) {
CAnimManager::AddAnimBlockRef(m_BlendHier->m_nAnimBlockId);
m_Flags |= ANIMATION_BLOCK_REFERENCED;
m_Flags |= ANIMATION_REFERENCE_BLOCK;
}
}

Expand All @@ -90,7 +90,7 @@ CAnimBlendAssociation::~CAnimBlendAssociation() {
CMemoryMgr::FreeAlign(m_BlendNodes);
}
m_Link.Remove();
if (m_Flags & ANIMATION_BLOCK_REFERENCED) {
if (m_Flags & ANIMATION_REFERENCE_BLOCK) {
CAnimManager::RemoveAnimBlockRef(m_BlendHier->m_nAnimBlockId);
}
}
Expand All @@ -101,8 +101,8 @@ float CAnimBlendAssociation::GetTimeProgress() const {

// 0x4CED50
void CAnimBlendAssociation::Init(RpClump* clump, CAnimBlendHierarchy* animHierarchy) {
CAnimBlendClumpData* animClumpData = RpClumpGetAnimBlendClumpData(clump);
m_NumBlendNodes = animClumpData->m_NumFrames;
CAnimBlendClumpData* animClumpData = RpAnimBlendClumpGetData(clump);
m_NumBlendNodes = animClumpData->m_NumFrameData;
AllocateAnimBlendNodeArray(m_NumBlendNodes);
for (auto i = 0; i < m_NumBlendNodes; i++) {
m_BlendNodes[i].m_BlendAssoc = this;
Expand All @@ -119,7 +119,7 @@ void CAnimBlendAssociation::Init(RpClump* clump, CAnimBlendHierarchy* animHierar
if (!frame) {
continue;
}
m_BlendNodes[frame - animClumpData->m_Frames].m_Seq = &seq;
m_BlendNodes[frame - animClumpData->m_FrameDatas].m_Seq = &seq;
}
}

Expand Down Expand Up @@ -153,7 +153,7 @@ void CAnimBlendAssociation::Init(CAnimBlendStaticAssociation& assoc) {

// 0x4CEB70
void CAnimBlendAssociation::Start(float currentTime) {
m_Flags |= ANIMATION_STARTED;
m_Flags |= ANIMATION_IS_PLAYING;
SetCurrentTime(currentTime);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ void CAnimBlendAssociation::SetBlendTo(float blendAmount, float blendDelta) {
// 0x4CEA80
void CAnimBlendAssociation::SetCurrentTime(float currentTime) {
for (m_CurrentTime = currentTime; m_CurrentTime >= m_BlendHier->m_fTotalTime; m_CurrentTime -= m_BlendHier->m_fTotalTime) {
if (!IsRepeating()) {
if (!IsLooped()) {
m_CurrentTime = m_BlendHier->m_fTotalTime;
break;
}
Expand Down Expand Up @@ -234,13 +234,14 @@ void CAnimBlendAssociation::SyncAnimation(CAnimBlendAssociation* syncWith) {
}

// 0x4D1490
bool CAnimBlendAssociation::UpdateBlend(float mult) {
m_BlendAmount += mult * m_BlendDelta;
if (m_BlendAmount <= 0.0f && m_BlendDelta < 0.0f) {
// We're faded out and are not fading in
bool CAnimBlendAssociation::UpdateBlend(float timeStep) {
m_BlendAmount += m_BlendDelta * timeStep;

if (m_BlendAmount <= 0.0f && m_BlendDelta < 0.0f) { // We're faded out and are not fading in
m_BlendAmount = 0.0f;
m_BlendDelta = std::max(0.0f, m_BlendDelta);
if (m_Flags & ANIMATION_FREEZE_LAST_FRAME) {
m_BlendDelta = std::max(0.0f, m_BlendDelta);

if (m_Flags & ANIMATION_IS_BLEND_AUTO_REMOVE) {
if (m_nCallbackType == ANIM_BLEND_CALLBACK_DELETE || m_nCallbackType == ANIM_BLEND_CALLBACK_FINISH) { // condition simplified
m_pCallbackFunc(this, m_pCallbackData);
SetFinishCallback(CDefaultAnimCallback::DefaultAnimCB, nullptr);
Expand All @@ -250,60 +251,70 @@ bool CAnimBlendAssociation::UpdateBlend(float mult) {
}
}

if (m_BlendAmount > 1.0f) {
// Maximally faded in, clamp values
if (m_BlendAmount > 1.0f) { // Maximally faded in, clamp values
m_BlendAmount = 1.0f;
m_BlendDelta = std::min(0.0f, m_BlendDelta);
m_BlendDelta = std::min(0.0f, m_BlendDelta);
}

return true;
}

// 0x4D13D0
bool CAnimBlendAssociation::UpdateTime(float a1, float a2) {
UNUSED(a1);
UNUSED(a2);
bool CAnimBlendAssociation::UpdateTime(float timeStep, float timeMult) {
UNUSED(timeStep);
UNUSED(timeMult);

if (!IsRunning())
if (!IsPlaying()) {
return true;
}

if (m_CurrentTime >= (double)m_BlendHier->m_fTotalTime) {
SetFlag(ANIMATION_STARTED, true);
// Finished yet?
if (m_CurrentTime >= (double)m_BlendHier->GetTotalTime()) {
SetFlag(ANIMATION_IS_PLAYING, false);
return true;
}

// Okay, so advance...
m_CurrentTime += m_TimeStep;
if (m_CurrentTime < m_BlendHier->m_fTotalTime) {

// Is it finished now?
if (m_CurrentTime < m_BlendHier->GetTotalTime()) {
return true;
}

if (IsRepeating()) {
m_CurrentTime -= m_BlendHier->m_fTotalTime;
// Should it be repeating? If so, jump to beginning
if (IsLooped()) {
m_CurrentTime -= m_BlendHier->GetTotalTime();
return true;
}

m_CurrentTime = m_BlendHier->m_fTotalTime;
if (m_Flags & ANIMATION_UNLOCK_LAST_FRAME) {
SetFlag(ANIMATION_FREEZE_LAST_FRAME, true);
// Anim has finished
m_CurrentTime = m_BlendHier->GetTotalTime();

// Maybe auto-remove
if (m_Flags & ANIMATION_IS_FINISH_AUTO_REMOVE) {
SetFlag(ANIMATION_IS_BLEND_AUTO_REMOVE, true);
m_BlendDelta = -4.0f;
}

// Call finish callback (if any)
if (m_nCallbackType == ANIM_BLEND_CALLBACK_FINISH) {
m_nCallbackType = ANIM_BLEND_CALLBACK_NONE;
m_pCallbackFunc(this, m_pCallbackData);
SetFinishCallback(CDefaultAnimCallback::DefaultAnimCB, nullptr);
}

// And we're done
return true;
}

// 0x4D13A0
void CAnimBlendAssociation::UpdateTimeStep(float speedMult, float timeMult) {
if (IsRunning()) {
if (IsMoving()) {
m_TimeStep = m_BlendHier->m_fTotalTime * timeMult * speedMult;
} else {
m_TimeStep = m_Speed * speedMult;
}
void CAnimBlendAssociation::UpdateTimeStep(float timeStep, float totalTimeRecp) {
if (IsPlaying()) {
m_TimeStep = IsSyncronised()
? m_BlendHier->m_fTotalTime * totalTimeRecp
: m_Speed;
m_TimeStep *= timeStep;
}
}

Expand All @@ -313,14 +324,13 @@ bool CAnimBlendAssociation::HasFinished() const {

// 0x4CEA50
void CAnimBlendAssociation::ReferenceAnimBlock() {
if (m_Flags & ANIMATION_BLOCK_REFERENCED) {
if (m_Flags & ANIMATION_REFERENCE_BLOCK) {
return;
}
CAnimManager::AddAnimBlockRef(m_BlendHier->m_nAnimBlockId);
SetFlag(ANIMATION_FREEZE_TRANSLATION, true);
SetFlag(ANIMATION_IGNORE_ROOT_TRANSLATION, true);
}

// 0x4CEB60
CAnimBlendNode* CAnimBlendAssociation::GetNode(int32 nodeIndex) {
return &m_BlendNodes[nodeIndex];
std::span<CAnimBlendNode> CAnimBlendAssociation::GetNodes() {
return std::span{ m_BlendNodes, m_NumBlendNodes };
}
Loading

0 comments on commit 79fbbb9

Please sign in to comment.