diff --git a/DataSpec/DNAMP1/ScriptObjects/ActorKeyframe.hpp b/DataSpec/DNAMP1/ScriptObjects/ActorKeyframe.hpp index 7c2c1600b..079822930 100644 --- a/DataSpec/DNAMP1/ScriptObjects/ActorKeyframe.hpp +++ b/DataSpec/DNAMP1/ScriptObjects/ActorKeyframe.hpp @@ -13,10 +13,10 @@ struct ActorKeyframe : IScriptObject AT_DECL_DNAV String<-1> name; Value animationId; - Value unknown1; - Value unknown2; + Value looping; + Value lifetime; Value active; - Value unknown3; + Value fadeOut; Value totalPlayback; }; } diff --git a/DataSpec/DNAMP1/ScriptObjects/ColorModulate.hpp b/DataSpec/DNAMP1/ScriptObjects/ColorModulate.hpp index ec06c76e4..6a438e5d0 100644 --- a/DataSpec/DNAMP1/ScriptObjects/ColorModulate.hpp +++ b/DataSpec/DNAMP1/ScriptObjects/ColorModulate.hpp @@ -12,17 +12,17 @@ struct ColorModulate : IScriptObject AT_DECL_DNA_YAML AT_DECL_DNAV String<-1> name; - Value unknown1; - Value unknown2; - Value unknown3; - Value unknown4; - Value unknown5; - Value unknown6; - Value unknown7; - Value unknown8; - Value unknown9; - Value unknown10; - Value unknown11; + Value colorA; + Value colorB; + Value blendMode; + Value timeA2B; + Value timeB2A; + Value doReverse; + Value resetTargetWhenDone; + Value depthCompare; + Value depthUpdate; + Value depthBackwards; + Value active; }; } diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index e1538f752..5b263e862 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -2339,9 +2339,7 @@ void CStateManager::RemoveObject(TUniqueId uid) if (CEntity* ent = GetAllObjectList().GetValidObjectById(uid)) { if (ent->GetEditorId() != kInvalidEditorId) - { x890_scriptIdMap.erase(ent->GetEditorId()); - } if (ent->GetAreaIdAlways() != kInvalidAreaId) { CGameArea* area = x850_world->GetArea(ent->GetAreaIdAlways()); diff --git a/Runtime/Character/CAdditiveAnimPlayback.cpp b/Runtime/Character/CAdditiveAnimPlayback.cpp index e875667fd..b643bbfef 100644 --- a/Runtime/Character/CAdditiveAnimPlayback.cpp +++ b/Runtime/Character/CAdditiveAnimPlayback.cpp @@ -7,11 +7,12 @@ namespace urde { CAdditiveAnimPlayback::CAdditiveAnimPlayback(const std::weak_ptr& anim, - float weight, bool active, const CAdditiveAnimationInfo& info, bool b) + float weight, bool active, const CAdditiveAnimationInfo& info, + bool fadeOut) : x0_info(info), x8_anim(anim.lock()), xc_targetWeight(weight), x14_active(active) { - if (!active && b) - x20_ = true; + if (!active && fadeOut) + x20_needsFadeOut = true; } void CAdditiveAnimPlayback::AddToSegStatementSet(const CSegIdList& list, diff --git a/Runtime/Character/CAdditiveAnimPlayback.hpp b/Runtime/Character/CAdditiveAnimPlayback.hpp index dd89fa986..728af3484 100644 --- a/Runtime/Character/CAdditiveAnimPlayback.hpp +++ b/Runtime/Character/CAdditiveAnimPlayback.hpp @@ -45,10 +45,10 @@ class CAdditiveAnimPlayback bool x14_active; float x18_weightTimer = 0.f; EAdditivePlaybackPhase x1c_phase = EAdditivePlaybackPhase::FadingIn; - bool x20_ = false; + bool x20_needsFadeOut = false; public: CAdditiveAnimPlayback(const std::weak_ptr& anim, float weight, bool active, - const CAdditiveAnimationInfo& info, bool b); + const CAdditiveAnimationInfo& info, bool fadeOut); void AddToSegStatementSet(const CSegIdList& list, const CCharLayoutInfo&, CSegStatementSet&) const; void Update(float dt); @@ -60,8 +60,8 @@ public: const std::shared_ptr& GetAnim() const {return x8_anim;} std::shared_ptr& GetAnim() {return x8_anim;} EAdditivePlaybackPhase GetPhase() const {return x1c_phase;} - void Set20(bool b) {x20_ = b;} - bool Get20() const {return x20_;} + void SetNeedsFadeOut(bool b) {x20_needsFadeOut = b;} + bool NeedsFadeOut() const {return x20_needsFadeOut;} }; } diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index 5383fb802..03e2eb96a 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -187,7 +187,7 @@ SAdvancementDeltas CAnimData::UpdateAdditiveAnims(float dt) { it->second.Update(dt); CCharAnimTime timeRem = it->second.GetAnim()->VGetTimeRemaining(); - if (timeRem.EpsilonZero() && it->second.Get20()) + if (timeRem.EpsilonZero() && it->second.NeedsFadeOut()) it->second.FadeOut(); if (it->second.GetPhase() == EAdditivePlaybackPhase::FadedOut) { @@ -252,7 +252,7 @@ void CAnimData::DelAdditiveAnimation(u32 idx) } } -void CAnimData::AddAdditiveAnimation(u32 idx, float weight, bool active, bool b) +void CAnimData::AddAdditiveAnimation(u32 idx, float weight, bool active, bool fadeOut) { u32 animIdx = xc_charInfo.GetAnimationIndex(idx); for (std::pair& anim : x434_additiveAnims) @@ -263,7 +263,7 @@ void CAnimData::AddAdditiveAnimation(u32 idx, float weight, bool active, bool b) { anim.second.SetActive(active); anim.second.SetWeight(weight); - anim.second.Set20(!anim.second.IsActive() && b); + anim.second.SetNeedsFadeOut(!anim.second.IsActive() && fadeOut); return; } } @@ -272,7 +272,7 @@ void CAnimData::AddAdditiveAnimation(u32 idx, float weight, bool active, bool b) GetAnimationManager()->GetAnimationTree(animIdx, CMetaAnimTreeBuildOrders::NoSpecialOrders()); const CAdditiveAnimationInfo& info = x0_charFactory->FindAdditiveInfo(animIdx); - x434_additiveAnims.emplace_back(std::make_pair(idx, CAdditiveAnimPlayback(node, weight, active, info, b))); + x434_additiveAnims.emplace_back(std::make_pair(idx, CAdditiveAnimPlayback(node, weight, active, info, fadeOut))); } float CAnimData::GetAdditiveAnimationWeight(u32 idx) const @@ -330,7 +330,7 @@ CCharAnimTime CAnimData::GetTimeOfUserEvent(EUserEventType type, const CCharAnim void CAnimData::MultiplyPlaybackRate(float mul) { - x200_speedScale += mul; + x200_speedScale *= mul; } void CAnimData::SetPlaybackRate(float set) diff --git a/Runtime/World/CPatterned.hpp b/Runtime/World/CPatterned.hpp index 7d98b9cae..e6d6f3647 100644 --- a/Runtime/World/CPatterned.hpp +++ b/Runtime/World/CPatterned.hpp @@ -184,6 +184,9 @@ public: virtual bool IsOnGround() const { return x328_27_onGround; } virtual float GetGravityConstant() const { return 24.525002f; } float GetDamageDuration() const { return x504_damageDur; } + + const CBodyController* GetBodyController() const { return x450_bodyController.get(); } + CBodyController* BodyController() { return x450_bodyController.get(); } }; } diff --git a/Runtime/World/CScriptActorKeyframe.cpp b/Runtime/World/CScriptActorKeyframe.cpp index b303b1396..e8d9d0507 100644 --- a/Runtime/World/CScriptActorKeyframe.cpp +++ b/Runtime/World/CScriptActorKeyframe.cpp @@ -2,13 +2,14 @@ #include "CStateManager.hpp" #include "World/CScriptActor.hpp" #include "World/CScriptPlatform.hpp" -#include "World/CAi.hpp" +#include "World/CPatterned.hpp" #include "TCastTo.hpp" namespace urde { CScriptActorKeyframe::CScriptActorKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 animId, - bool looping, float lifetime, bool b2, u32 w2, bool active, float totalPlayback) + bool looping, float lifetime, bool disableUpdate, u32 fadeOut, bool active, + float totalPlayback) : CEntity(uid, info, active, name) , x34_animationId(animId) , x38_initialLifetime(lifetime) @@ -16,9 +17,9 @@ CScriptActorKeyframe::CScriptActorKeyframe(TUniqueId uid, std::string_view name, , x40_lifetime(lifetime) { x44_24_looping = looping; - x44_25_disableUpdate = b2; - x44_26_ = w2; - x44_27_ = w2; + x44_25_disableUpdate = disableUpdate; + x44_26_fadeOut = fadeOut; + x44_27_timedLoop = fadeOut; x44_28_playing = false; x44_29_ = false; } @@ -63,7 +64,7 @@ void CScriptActorKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId u void CScriptActorKeyframe::Think(float dt, CStateManager& mgr) { - if (x44_25_disableUpdate || !x44_24_looping || !x44_27_ || !x44_28_playing || x40_lifetime <= 0.f) + if (x44_25_disableUpdate || !x44_24_looping || !x44_27_timedLoop || !x44_28_playing || x40_lifetime <= 0.f) { CEntity::Think(dt, mgr); return; @@ -94,12 +95,18 @@ void CScriptActorKeyframe::Think(float dt, CStateManager& mgr) animData->EnableLooping(false); } } - else if (TCastToPtr ai = ent) + else if (TCastToPtr ai = ent) { - CAnimData* animData = act->ModelData()->AnimationData(); + CAnimData* animData = ai->ModelData()->AnimationData(); if (animData->IsAdditiveAnimation(x34_animationId)) + { animData->DelAdditiveAnimation(x34_animationId); - /* TODO: Finish */ + } + else if (ai->GetBodyController()->GetCurrentStateId() == pas::EAnimationState::Scripted && + animData->GetDefaultAnimation() == x34_animationId) + { + ai->BodyController()->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState)); + } } } @@ -125,7 +132,7 @@ void CScriptActorKeyframe::UpdateEntity(TUniqueId uid, CStateManager& mgr) CAnimData* animData = act->ModelData()->AnimationData(); if (animData->IsAdditiveAnimation(x34_animationId)) { - animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_); + animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_fadeOut); } else { @@ -135,7 +142,18 @@ void CScriptActorKeyframe::UpdateEntity(TUniqueId uid, CStateManager& mgr) } } } - /* else if (TCastTo ai = ent) - * TODO: Finish */ + else if (TCastToPtr ai = ent) + { + CAnimData* animData = ai->ModelData()->AnimationData(); + if (animData->IsAdditiveAnimation(x34_animationId)) + { + animData->AddAdditiveAnimation(x34_animationId, 1.f, x44_24_looping, x44_26_fadeOut); + } + else + { + ai->BodyController()->GetCommandMgr().DeliverCmd( + CBCScriptedCmd(x34_animationId, x44_24_looping, x44_27_timedLoop, x38_initialLifetime)); + } + } } } diff --git a/Runtime/World/CScriptActorKeyframe.hpp b/Runtime/World/CScriptActorKeyframe.hpp index fa146c601..ef266af8c 100644 --- a/Runtime/World/CScriptActorKeyframe.hpp +++ b/Runtime/World/CScriptActorKeyframe.hpp @@ -17,8 +17,8 @@ private: { bool x44_24_looping : 1; bool x44_25_disableUpdate : 1; - bool x44_26_ : 1; - bool x44_27_ : 1; + bool x44_26_fadeOut : 1; + bool x44_27_timedLoop : 1; bool x44_28_playing : 1; bool x44_29_ : 1; }; @@ -26,8 +26,9 @@ private: }; public: - CScriptActorKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 w1, bool b1, float f1, - bool b2, u32 w2, bool active, float f2); + CScriptActorKeyframe(TUniqueId uid, std::string_view name, const CEntityInfo& info, s32 animId, + bool looping, float lifetime, bool disableUpdate, u32 fadeOut, bool active, + float totalPlayback); void Accept(IVisitor& visitor); void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr); diff --git a/Runtime/World/CScriptColorModulate.cpp b/Runtime/World/CScriptColorModulate.cpp index 8d985d992..b6af0314f 100644 --- a/Runtime/World/CScriptColorModulate.cpp +++ b/Runtime/World/CScriptColorModulate.cpp @@ -6,25 +6,26 @@ namespace urde { CScriptColorModulate::CScriptColorModulate(TUniqueId uid, std::string_view name, const CEntityInfo& info, - const zeus::CColor& c1, const zeus::CColor& c2, - EBlendMode bm, float f1, float f2, - bool b1, bool b2, bool b3, bool b4, bool b5, bool active) + const zeus::CColor& colorA, const zeus::CColor& colorB, + EBlendMode blendMode, float timeA2B, float timeB2A, bool doReverse, + bool resetTargetWhenDone, bool depthCompare, bool depthUpdate, + bool depthBackwards, bool active) : CEntity(uid, info, active, name), - x40_(c1), - x44_(c2), - x48_blendMode(bm), - x4c_(f1), - x50_(f2) + x40_colorA(colorA), + x44_colorB(colorB), + x48_blendMode(blendMode), + x4c_timeA2B(timeA2B), + x50_timeB2A(timeB2A) { - x54_24_ = b1; - x54_25_ = b2; - x54_26_depthEqual = b3; - x54_27_depthUpdate = b4; - x54_28_ = b5; - x54_29_ = false; - x54_30_ = false; - x54_31_ = false; - x55_24_ = false; + x54_24_doReverse = doReverse; + x54_25_resetTargetWhenDone = resetTargetWhenDone; + x54_26_depthCompare = depthCompare; + x54_27_depthUpdate = depthUpdate; + x54_28_depthBackwards = depthBackwards; + x54_29_reversing = false; + x54_30_enable = false; + x54_31_dieOnEnd = false; + x55_24_isFadeOutHelper = false; } void CScriptColorModulate::Accept(IVisitor& visitor) @@ -39,98 +40,97 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o if (!GetActive()) return; - if (msg == EScriptObjectMessage::Decrement) + switch (msg) { - if (x54_29_) + case EScriptObjectMessage::Increment: + if (x54_29_reversing) { - x38_ = x38_ == 0; - x54_29_ = false; + x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; + x54_29_reversing = false; return; } - else if (x54_30_) + else if (x54_30_enable) { - if (x38_ == 0) - x3c_ = 0.f; + if (x38_fadeState == EFadeState::A2B) + x3c_curTime = 0.f; else - x3c_ = -((x50_ * (x3c_ / x4c_)) - x50_); + x3c_curTime = x4c_timeA2B - x4c_timeA2B * (x3c_curTime / x50_timeB2A); } else - SetTargetFlags(mgr, CalculateFlags(x44_)); + SetTargetFlags(mgr, CalculateFlags(x40_colorA)); - x54_30_ = true; - x38_ = 0; - } - else if (msg == EScriptObjectMessage::Increment) - { - if (x54_29_) + x54_30_enable = true; + x38_fadeState = EFadeState::A2B; + break; + case EScriptObjectMessage::Decrement: + if (x54_29_reversing) { - x38_ = x38_ == 0; - x54_29_ = false; + x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; + x54_29_reversing = false; return; } - else if (x54_30_) + else if (x54_30_enable) { - if (x38_ == 0) - x3c_ = 0.f; + if (x38_fadeState == EFadeState::A2B) + x3c_curTime = 0.f; else - x3c_ = -((x4c_ * (x3c_ / x50_)) - x4c_); + x3c_curTime = x50_timeB2A - x50_timeB2A * (x3c_curTime / x4c_timeA2B); } else - SetTargetFlags(mgr, CalculateFlags(x40_)); + SetTargetFlags(mgr, CalculateFlags(x44_colorB)); - x54_30_ = true; - x38_ = 0; + x54_30_enable = true; + x38_fadeState = EFadeState::B2A; + break; + default: + break; } } void CScriptColorModulate::Think(float dt, CStateManager& mgr) { - if (!GetActive() || !x54_30_) + if (!GetActive() || !x54_30_enable) return; - x3c_ += dt; - if (x38_ == 0) + x3c_curTime += dt; + if (x38_fadeState == EFadeState::A2B) { - float f2 = x4c_; - float f1 = f2 - dt; - if (std::fabs(f1) < 0.000001) - f1 = 1.f; + float t; + if (zeus::close_enough(x4c_timeA2B, 0.f)) + t = 1.f; else { - f1 = x3c_; - f1 /= f2; - if (f1 >= 1.f) - f1 = 1.f; + t = x3c_curTime / x4c_timeA2B; + if (t >= 1.f) + t = 1.f; } - zeus::CColor lerpedCol = zeus::CColor::lerp(x40_, x44_, f1); + zeus::CColor lerpedCol = zeus::CColor::lerp(x40_colorA, x44_colorB, t); CModelFlags flags = CalculateFlags(lerpedCol); SetTargetFlags(mgr, flags); - if (x3c_ <= x4c_) + if (x3c_curTime <= x4c_timeA2B) return; End(mgr); } - else if (x38_ == 1) + else if (x38_fadeState == EFadeState::B2A) { - float f2 = x50_; - float f1 = f2 - dt; - if (std::fabs(f1) < 0.000001) - f1 = 1.f; + float t; + if (zeus::close_enough(x50_timeB2A, 0.f)) + t = 1.f; else { - f1 = x3c_; - f1 /= f2; - if (f1 >= 1.f) - f1 = 1.f; + t = x3c_curTime / x50_timeB2A; + if (t >= 1.f) + t = 1.f; } - zeus::CColor lerpedCol = zeus::CColor::lerp(x40_, x44_, f1); + zeus::CColor lerpedCol = zeus::CColor::lerp(x44_colorB, x40_colorA, t); CModelFlags flags = CalculateFlags(lerpedCol); SetTargetFlags(mgr, flags); - if (x3c_ <= x50_) + if (x3c_curTime <= x50_timeB2A) return; End(mgr); @@ -140,46 +140,41 @@ void CScriptColorModulate::Think(float dt, CStateManager& mgr) CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const { CModelFlags ret; - if (x54_28_) + if (x54_28_depthBackwards) { - if (x48_blendMode == EBlendMode::Zero) + if (x48_blendMode == EBlendMode::Alpha) { - CModelFlags ret; ret.x0_blendMode = 5; ret.x1_matSetIdx = 0; - ret.x2_flags = (x54_29_ << 1) | (x54_27_depthUpdate << 0) | 3 | 8; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 3 | 8; ret.x4_color = col; } - else if (x48_blendMode == EBlendMode::One) + else if (x48_blendMode == EBlendMode::Additive) { - CModelFlags ret; ret.x0_blendMode = 7; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1 | 0x8; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 0x8; ret.x4_color = col; } - else if (x48_blendMode == EBlendMode::Two) + else if (x48_blendMode == EBlendMode::Additive2) { - CModelFlags ret; ret.x0_blendMode = 8; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1 | 0x8; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 0x8; ret.x4_color = col; } - else if (x48_blendMode == EBlendMode::Three) + else if (x48_blendMode == EBlendMode::Opaque) { - CModelFlags ret; ret.x0_blendMode = 1; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1 | 0x8; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 0x8; ret.x4_color = col; } - else if (x48_blendMode == EBlendMode::Four) + else if (x48_blendMode == EBlendMode::Opaque2) { - CModelFlags ret; ret.x0_blendMode = 2; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1 | 0x8; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 0x8; ret.x4_color = col; } else @@ -190,59 +185,59 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const } else { - if (x48_blendMode == EBlendMode::Zero) + if (x48_blendMode == EBlendMode::Alpha) { if (col == zeus::CColor::skWhite) { ret.x0_blendMode = 3; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = zeus::CColor::skWhite; } else { ret.x0_blendMode = 5; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = col; } } - else if (x48_blendMode == EBlendMode::One) + else if (x48_blendMode == EBlendMode::Additive) { ret.x0_blendMode = 7; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = col; } - else if (x48_blendMode == EBlendMode::Two) + else if (x48_blendMode == EBlendMode::Additive2) { ret.x0_blendMode = 8; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = col; } - else if (x48_blendMode == EBlendMode::Three) + else if (x48_blendMode == EBlendMode::Opaque) { if (col == zeus::CColor::skWhite) { ret.x0_blendMode = 3; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = zeus::CColor::skWhite; } else { ret.x0_blendMode = 1; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = col; } } - else if (x48_blendMode == EBlendMode::Four) + else if (x48_blendMode == EBlendMode::Opaque2) { ret.x0_blendMode = 2; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthEqual << 0 | x54_27_depthUpdate << 1; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = col; } else @@ -285,12 +280,14 @@ TUniqueId CScriptColorModulate::FadeOutHelper(CStateManager& mgr, TUniqueId pare aId = ent->GetAreaIdAlways(); TUniqueId ret = mgr.AllocateUniqueId(); - CScriptColorModulate* colMod = new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::CColor(1.f, 1.f, 1.f, 0.f), zeus::CColor(1.f, 1.f, 1.f, 1.f), EBlendMode::Zero, dt, 0.f, false, false, true, true, false, true); + CScriptColorModulate* colMod = new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), + zeus::CColor(1.f, 1.f, 1.f, 0.f), zeus::CColor(1.f, 1.f, 1.f, 1.f), EBlendMode::Alpha, dt, 0.f, + false, false, true, true, false, true); mgr.AddObject(colMod); colMod->x34_parent = parent; - colMod->x54_30_ = true; - colMod->x54_31_ = true; - colMod->x55_24_ = true; + colMod->x54_30_enable = true; + colMod->x54_31_dieOnEnd = true; + colMod->x55_24_isFadeOutHelper = true; colMod->Think(0.f, mgr); return ret; @@ -303,11 +300,13 @@ TUniqueId CScriptColorModulate::FadeInHelper(CStateManager& mgr, TUniqueId paren aId = ent->GetAreaIdAlways(); TUniqueId ret = mgr.AllocateUniqueId(); - CScriptColorModulate* colMod = new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::CColor(1.f, 1.f, 1.f, 1.f), zeus::CColor(1.f, 1.f, 1.f, 0.f), EBlendMode::Zero, dt, 0.f, false, false, true, true, false, true); + CScriptColorModulate* colMod = new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), + zeus::CColor(1.f, 1.f, 1.f, 1.f), zeus::CColor(1.f, 1.f, 1.f, 0.f), EBlendMode::Alpha, dt, 0.f, + false, false, true, true, false, true); mgr.AddObject(colMod); colMod->x34_parent = parent; - colMod->x54_30_ = true; - colMod->x54_31_ = true; + colMod->x54_30_enable = true; + colMod->x54_31_dieOnEnd = true; colMod->Think(0.f, mgr); return ret; @@ -315,25 +314,25 @@ TUniqueId CScriptColorModulate::FadeInHelper(CStateManager& mgr, TUniqueId paren void CScriptColorModulate::End(CStateManager& stateMgr) { - x3c_ = 0.f; - if (x54_24_ && !x54_29_) + x3c_curTime = 0.f; + if (x54_24_doReverse && !x54_29_reversing) { - x54_29_ = true; - x38_ = x38_ == 0; + x54_29_reversing = true; + x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; return; } - x54_30_ = false; - x54_29_ = false; - if (x54_25_) + x54_30_enable = false; + x54_29_reversing = false; + if (x54_25_resetTargetWhenDone) SetTargetFlags(stateMgr, CModelFlags(0, 0, 3, zeus::CColor::skWhite)); - if (x55_24_) + if (x55_24_isFadeOutHelper) stateMgr.SendScriptMsgAlways(x34_parent, x8_uid, EScriptObjectMessage::Deactivate); CEntity::SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None); - if (!x54_31_) + if (x54_31_dieOnEnd) stateMgr.FreeScriptObject(GetUniqueId()); } } diff --git a/Runtime/World/CScriptColorModulate.hpp b/Runtime/World/CScriptColorModulate.hpp index 7537290ab..eef618114 100644 --- a/Runtime/World/CScriptColorModulate.hpp +++ b/Runtime/World/CScriptColorModulate.hpp @@ -12,42 +12,50 @@ class CScriptColorModulate : public CEntity public: enum class EBlendMode { - Zero, - One, - Two, - Three, - Four, + Alpha, + Additive, + Additive2, + Opaque, + Opaque2, + }; + enum class EFadeState + { + A2B, + B2A }; private: TUniqueId x34_parent = kInvalidUniqueId; - u32 x38_ = 0; - float x3c_; - zeus::CColor x40_; - zeus::CColor x44_; + EFadeState x38_fadeState = EFadeState::A2B; + float x3c_curTime; + zeus::CColor x40_colorA; + zeus::CColor x44_colorB; EBlendMode x48_blendMode; - float x4c_; - float x50_; + float x4c_timeA2B; + float x50_timeB2A; union { struct { - bool x54_24_ : 1; - bool x54_25_ : 1; - bool x54_26_depthEqual : 1; + bool x54_24_doReverse : 1; + bool x54_25_resetTargetWhenDone : 1; + bool x54_26_depthCompare : 1; bool x54_27_depthUpdate : 1; - bool x54_28_ : 1; - bool x54_29_ : 1; - bool x54_30_ : 1; - bool x54_31_ : 1; - bool x55_24_ : 1; + bool x54_28_depthBackwards : 1; + bool x54_29_reversing : 1; + bool x54_30_enable : 1; + bool x54_31_dieOnEnd : 1; + bool x55_24_isFadeOutHelper : 1; }; u32 _dummy = 0; }; public: - CScriptColorModulate(TUniqueId, std::string_view, const CEntityInfo&, const zeus::CColor&, const zeus::CColor&, - EBlendMode, float, float, bool, bool, bool, bool, bool, bool); + CScriptColorModulate(TUniqueId uid, std::string_view name, const CEntityInfo& info, + const zeus::CColor& colorA, const zeus::CColor& colorB, + EBlendMode blendMode, float timeA2B, float timeB2A, bool doReverse, + bool resetTargetWhenDone, bool depthCompare, bool depthUpdate, + bool depthBackwards, bool active); void Accept(IVisitor& visitor); void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr); diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 0cef22d92..b10c38b23 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -1186,13 +1186,14 @@ CEntity* ScriptLoader::LoadActorKeyframe(CStateManager& mgr, CInputStream& in, i bool looping = in.readBool(); float lifetime = in.readFloatBig(); bool active = in.readBool(); - u32 w2 = in.readUint32Big(); + u32 fadeOut = in.readUint32Big(); float totalPlayback = in.readFloatBig(); if (animId == -1) return nullptr; - return new CScriptActorKeyframe(mgr.AllocateUniqueId(), name, info, animId, looping, lifetime, false, w2, active, totalPlayback); + return new CScriptActorKeyframe(mgr.AllocateUniqueId(), name, info, animId, looping, lifetime, false, + fadeOut, active, totalPlayback); } CEntity* ScriptLoader::LoadWater(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) @@ -2257,20 +2258,21 @@ CEntity* ScriptLoader::LoadColorModulate(CStateManager& mgr, CInputStream& in, i return nullptr; std::string name = mgr.HashInstanceName(in); - zeus::CColor c1; - c1.readRGBABig(in); - zeus::CColor c2; - c2.readRGBABig(in); - CScriptColorModulate::EBlendMode bm = CScriptColorModulate::EBlendMode(in.readUint32Big()); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - bool b1 = in.readBool(); - bool b2 = in.readBool(); - bool b3 = in.readBool(); - bool b4 = in.readBool(); - bool b5 = in.readBool(); + zeus::CColor colorA; + colorA.readRGBABig(in); + zeus::CColor colorB; + colorB.readRGBABig(in); + CScriptColorModulate::EBlendMode blendMode = CScriptColorModulate::EBlendMode(in.readUint32Big()); + float timeA2B = in.readFloatBig(); + float timeB2A = in.readFloatBig(); + bool doReverse = in.readBool(); + bool resetTargetWhenDone = in.readBool(); + bool depthCompare = in.readBool(); + bool depthUpdate = in.readBool(); + bool depthBackwards = in.readBool(); bool active = in.readBool(); - return new CScriptColorModulate(mgr.AllocateUniqueId(), name, info, c1, c2, bm, f1, f2, b1, b2, b3, b4, b5, active); + return new CScriptColorModulate(mgr.AllocateUniqueId(), name, info, colorA, colorB, blendMode, timeA2B, timeB2A, + doReverse, resetTargetWhenDone, depthCompare, depthUpdate, depthBackwards, active); } CEntity* ScriptLoader::LoadThardusRockProjectile(CStateManager& mgr, CInputStream& in, int propCount,