From d35cc2ce1d6b3d38ca01e5dc83a3de47650becd1 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 9 Feb 2018 17:23:18 -0800 Subject: [PATCH] Fix CScriptActorRotate --- Runtime/World/CScriptActorRotate.cpp | 11 +- Runtime/World/CScriptActorRotate.hpp | 2 +- Runtime/World/CScriptColorModulate.cpp | 137 +++++++++++++++++++++++-- Runtime/World/CScriptColorModulate.hpp | 2 +- Runtime/World/CScriptGenerator.cpp | 1 + 5 files changed, 137 insertions(+), 16 deletions(-) diff --git a/Runtime/World/CScriptActorRotate.cpp b/Runtime/World/CScriptActorRotate.cpp index 332380bc7..8744218c8 100644 --- a/Runtime/World/CScriptActorRotate.cpp +++ b/Runtime/World/CScriptActorRotate.cpp @@ -57,10 +57,12 @@ void CScriptActorRotate::Think(float dt, CStateManager& mgr) if (TCastToPtr act = mgr.ObjectById(actorPair.first)) { zeus::CTransform xf = - zeus::CTransform::RotateX(zeus::degToRad(timeOffset * x34_rotation.x)) * + zeus::CTransform::RotateZ(zeus::degToRad(timeOffset * x34_rotation.z)) * zeus::CTransform::RotateY(zeus::degToRad(timeOffset * x34_rotation.y)) * - zeus::CTransform::RotateZ(zeus::degToRad(timeOffset * x34_rotation.z)); - act->SetTransform({xf.basis, act->GetTranslation()}); + zeus::CTransform::RotateX(zeus::degToRad(timeOffset * x34_rotation.x)); + zeus::CTransform localRot = actorPair.second * xf; + localRot.origin = act->GetTranslation(); + act->SetTransform(localRot); if (TCastToPtr plat = mgr.ObjectById(actorPair.first)) UpdatePlatformRiders(*plat.GetPtr(), xf, mgr); @@ -71,6 +73,7 @@ void CScriptActorRotate::Think(float dt, CStateManager& mgr) { if (!x58_25_skipSpiderBallWaypoints) UpdateSpiderBallWaypoints(mgr); + if (x58_26_updateActors) UpdateActors(false, mgr); } @@ -133,7 +136,7 @@ void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr) if (!x48_actors.empty()) { x58_24_updateRotation = true; - x44_currentTime = (next ? 0.f : x40_maxTime); + x44_currentTime = (next ? x40_maxTime : 0.f); } } diff --git a/Runtime/World/CScriptActorRotate.hpp b/Runtime/World/CScriptActorRotate.hpp index 6eb847d3e..9008363a3 100644 --- a/Runtime/World/CScriptActorRotate.hpp +++ b/Runtime/World/CScriptActorRotate.hpp @@ -12,7 +12,7 @@ class CScriptActorRotate : public CEntity { zeus::CVector3f x34_rotation; float x40_maxTime; - float x44_currentTime; + float x44_currentTime = 0.f; std::map x48_actors; union diff --git a/Runtime/World/CScriptColorModulate.cpp b/Runtime/World/CScriptColorModulate.cpp index ce2db990e..16dc9ee42 100644 --- a/Runtime/World/CScriptColorModulate.cpp +++ b/Runtime/World/CScriptColorModulate.cpp @@ -28,22 +28,139 @@ void CScriptColorModulate::Accept(IVisitor& visitor) visitor.Visit(this); } -void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr) +void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) { - CEntity::AcceptScriptMsg(msg, objId, stateMgr); + CEntity::AcceptScriptMsg(msg, objId, mgr); + return; + if (!GetActive()) + return; + + if (msg == EScriptObjectMessage::Decrement) + { + if (x54_29_) + { + x38_ = x38_ == 0; + x54_29_ = false; + return; + } + else if (x54_30_) + { + if (x38_ == 0) + x3c_ = 0.f; + else + x3c_ = -((x50_ * (x3c_ / x4c_)) - x50_); + } + else + SetTargetFlags(mgr, CalculateFlags(x44_)); + + x54_30_ = true; + x38_ = 0; + } + else if (msg == EScriptObjectMessage::Increment) + { + if (x54_29_) + { + x38_ = x38_ == 0; + x54_29_ = false; + return; + } + else if (x54_30_) + { + if (x38_ == 0) + x3c_ = 0.f; + else + x3c_ = -((x4c_ * (x3c_ / x50_)) - x4c_); + } + else + SetTargetFlags(mgr, CalculateFlags(x40_)); + + x54_30_ = true; + x38_ = 0; + } } -void CScriptColorModulate::Think(float, CStateManager &) +void CScriptColorModulate::Think(float dt, CStateManager& mgr) { + return; + if (!GetActive() || !x54_30_) + return; + + x3c_ += dt; + if (x38_ == 0) + { + float f2 = x4c_; + float f1 = f2 - dt; + if (std::fabs(f1) < 0.000001) + f1 = 1.f; + else + { + f1 = x3c_; + f1 /= f2; + if (f1 >= 1.f) + f1 = 1.f; + } + + zeus::CColor lerpedCol = zeus::CColor::lerp(x40_, x44_, f1); + CModelFlags flags = CalculateFlags(lerpedCol); + SetTargetFlags(mgr, flags); + + if (x3c_ <= x4c_) + return; + + End(mgr); + } + else if (x38_ == 1) + { + float f2 = x50_; + float f1 = f2 - dt; + if (std::fabs(f1) < 0.000001) + f1 = 1.f; + else + { + f1 = x3c_; + f1 /= f2; + if (f1 >= 1.f) + f1 = 1.f; + } + + zeus::CColor lerpedCol = zeus::CColor::lerp(x40_, x44_, f1); + CModelFlags flags = CalculateFlags(lerpedCol); + SetTargetFlags(mgr, flags); + + if (x3c_ <= x50_) + return; + + End(mgr); + } } -zeus::CColor CScriptColorModulate::CalculateFlags(const zeus::CColor &) const +CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor &) const { return {}; } -void CScriptColorModulate::SetTargetFlags(CStateManager &, const CModelFlags &) +void CScriptColorModulate::SetTargetFlags(CStateManager& stateMgr, const CModelFlags& flags) { + for (const SConnection& conn : x20_conns) + { + if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Activate) + continue; + + auto search = stateMgr.GetIdListForScript(conn.x8_objId); + for (auto it = search.first ; it != search.second ; ++it) + { + CEntity* ent = stateMgr.ObjectById(it->second); + if (CActor* act = TCastToPtr(ent)) + act->SetDrawFlags(flags); + } + } + + if (x34_ != kInvalidUniqueId) + { + CEntity* ent = stateMgr.ObjectById(x34_); + if (CActor* act = TCastToPtr(ent)) + act->SetDrawFlags(flags); + } } void CScriptColorModulate::FadeOutHelper(CStateManager &, TUniqueId, float) @@ -61,7 +178,7 @@ void CScriptColorModulate::End(CStateManager& stateMgr) if (x54_24_ && !x54_29_) { x54_29_ = true; - x38_ = 0; + x38_ = x38_ == 0; return; } @@ -70,12 +187,12 @@ void CScriptColorModulate::End(CStateManager& stateMgr) if (x54_25_) SetTargetFlags(stateMgr, CModelFlags(0, 0, 3, zeus::CColor::skWhite)); - if (x54_24_) - stateMgr.SendScriptMsg(x8_uid, x34_, EScriptObjectMessage::Deactivate); + if (x55_24_) + stateMgr.SendScriptMsgAlways(x34_, x8_uid, EScriptObjectMessage::Deactivate); CEntity::SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None); - if (x54_31_) - stateMgr.FreeScriptObject(x8_uid); + if (!x54_31_) + stateMgr.FreeScriptObject(GetUniqueId()); } } diff --git a/Runtime/World/CScriptColorModulate.hpp b/Runtime/World/CScriptColorModulate.hpp index 0fb8bae69..1db147dff 100644 --- a/Runtime/World/CScriptColorModulate.hpp +++ b/Runtime/World/CScriptColorModulate.hpp @@ -47,7 +47,7 @@ public: void Accept(IVisitor& visitor); void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr); void Think(float, CStateManager &); - zeus::CColor CalculateFlags(const zeus::CColor&) const; + CModelFlags CalculateFlags(const zeus::CColor&) const; void SetTargetFlags(CStateManager&, const CModelFlags&); static void FadeOutHelper(CStateManager&, TUniqueId, float); static void FadeInHelper(CStateManager&, TUniqueId, float); diff --git a/Runtime/World/CScriptGenerator.cpp b/Runtime/World/CScriptGenerator.cpp index 6ead2f59f..80aef8c2c 100644 --- a/Runtime/World/CScriptGenerator.cpp +++ b/Runtime/World/CScriptGenerator.cpp @@ -23,6 +23,7 @@ void CScriptGenerator::Accept(IVisitor& visitor) { visitor.Visit(this); } void CScriptGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) { + return; if (msg == EScriptObjectMessage::SetToZero && GetActive() && !x20_conns.empty()) { std::vector follows;