diff --git a/Runtime/World/CActorParameters.hpp b/Runtime/World/CActorParameters.hpp index 22b5e8dfd..32f76e370 100644 --- a/Runtime/World/CActorParameters.hpp +++ b/Runtime/World/CActorParameters.hpp @@ -63,5 +63,7 @@ public: float GetThermalMag() const { return x64_thermalMag; } const std::pair& GetXRayAssets() const { return x44_xrayAssets; } const std::pair& GetThermalAssets() const { return x4c_thermalAssets; } + float GetFadeInTime() const { return x5c_fadeInTime; } + float GetFadeOutTime() const { return x60_fadeOutTime; } }; } // namespace urde diff --git a/Runtime/World/CScriptColorModulate.cpp b/Runtime/World/CScriptColorModulate.cpp index e312be7a6..2a87c61ee 100644 --- a/Runtime/World/CScriptColorModulate.cpp +++ b/Runtime/World/CScriptColorModulate.cpp @@ -27,8 +27,9 @@ void CScriptColorModulate::Accept(IVisitor& visitor) { visitor.Visit(this); } void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) { CEntity::AcceptScriptMsg(msg, objId, mgr); - if (!GetActive()) + if (!GetActive()) { return; + } switch (msg) { case EScriptObjectMessage::Increment: @@ -36,14 +37,16 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; x54_29_reversing = false; return; - } else if (x54_30_enable) { - if (x38_fadeState == EFadeState::A2B) + } + if (x54_30_enable) { + if (x38_fadeState == EFadeState::A2B) { x3c_curTime = 0.f; - else + } else { x3c_curTime = x4c_timeA2B - x4c_timeA2B * (x3c_curTime / x50_timeB2A); - } else + } + } else { SetTargetFlags(mgr, CalculateFlags(x40_colorA)); - + } x54_30_enable = true; x38_fadeState = EFadeState::A2B; break; @@ -52,14 +55,16 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; x54_29_reversing = false; return; - } else if (x54_30_enable) { - if (x38_fadeState == EFadeState::A2B) + } + if (x54_30_enable) { + if (x38_fadeState == EFadeState::A2B) { x3c_curTime = 0.f; - else + } else { x3c_curTime = x50_timeB2A - x50_timeB2A * (x3c_curTime / x4c_timeA2B); - } else + } + } else { SetTargetFlags(mgr, CalculateFlags(x44_colorB)); - + } x54_30_enable = true; x38_fadeState = EFadeState::B2A; break; @@ -69,46 +74,37 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o } void CScriptColorModulate::Think(float dt, CStateManager& mgr) { - if (!GetActive() || !x54_30_enable) + if (!GetActive() || !x54_30_enable) { return; + } x3c_curTime += dt; - if (x38_fadeState == EFadeState::A2B) { - float t; - if (zeus::close_enough(x4c_timeA2B, 0.f)) - t = 1.f; - else { - t = x3c_curTime / x4c_timeA2B; - if (t >= 1.f) - t = 1.f; - } - - zeus::CColor lerpedCol = zeus::CColor::lerp(x40_colorA, x44_colorB, t); - CModelFlags flags = CalculateFlags(lerpedCol); - SetTargetFlags(mgr, flags); - - if (x3c_curTime <= x4c_timeA2B) - return; - - End(mgr); - } else if (x38_fadeState == EFadeState::B2A) { - float t; - if (zeus::close_enough(x50_timeB2A, 0.f)) - t = 1.f; - else { - t = x3c_curTime / x50_timeB2A; - if (t >= 1.f) - t = 1.f; + if (x38_fadeState == EFadeState::B2A) { + float t = 1.f; + if (!zeus::close_enough(x50_timeB2A, 0.f)) { + t = std::min(1.f, x3c_curTime / x50_timeB2A); } zeus::CColor lerpedCol = zeus::CColor::lerp(x44_colorB, x40_colorA, t); CModelFlags flags = CalculateFlags(lerpedCol); SetTargetFlags(mgr, flags); - if (x3c_curTime <= x50_timeB2A) - return; + if (x3c_curTime > x50_timeB2A) { + End(mgr); + } + } else { + float t = 1.f; + if (!zeus::close_enough(x4c_timeA2B, 0.f)) { + t = std::min(1.f, x3c_curTime / x4c_timeA2B); + } - End(mgr); + zeus::CColor lerpedCol = zeus::CColor::lerp(x40_colorA, x44_colorB, t); + CModelFlags flags = CalculateFlags(lerpedCol); + SetTargetFlags(mgr, flags); + + if (x3c_curTime > x4c_timeA2B) { + End(mgr); + } } } @@ -118,7 +114,7 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const if (x48_blendMode == EBlendMode::Alpha) { ret.x0_blendMode = 5; ret.x1_matSetIdx = 0; - ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 3 | 8; + ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1 | 0x8; ret.x4_color = col; } else if (x48_blendMode == EBlendMode::Additive) { ret.x0_blendMode = 7; @@ -147,7 +143,7 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const } else { if (x48_blendMode == EBlendMode::Alpha) { if (col == zeus::skWhite) { - ret.x0_blendMode = 3; + ret.x0_blendMode = 0; ret.x1_matSetIdx = 0; ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = zeus::skWhite; @@ -169,7 +165,7 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const ret.x4_color = col; } else if (x48_blendMode == EBlendMode::Opaque) { if (col == zeus::skWhite) { - ret.x0_blendMode = 3; + ret.x0_blendMode = 0; ret.x1_matSetIdx = 0; ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x4_color = zeus::skWhite; @@ -194,33 +190,35 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const 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) + 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)) + if (TCastToPtr act = stateMgr.ObjectById(it->second)) { act->SetDrawFlags(flags); + } } } if (x34_parent != kInvalidUniqueId) { - CEntity* ent = stateMgr.ObjectById(x34_parent); - if (CActor* act = TCastToPtr(ent)) + if (TCastToPtr act = stateMgr.ObjectById(x34_parent)) { act->SetDrawFlags(flags); + } } } TUniqueId CScriptColorModulate::FadeOutHelper(CStateManager& mgr, TUniqueId parent, float fadeTime) { TAreaId aId = mgr.GetNextAreaId(); - if (const CEntity* ent = mgr.GetObjectById(parent)) + if (const auto* ent = mgr.GetObjectById(parent)) { 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::Alpha, fadeTime, 0.f, false, false, true, true, false, true); + auto* colMod = new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::skWhite, + zeus::CColor{1.f, 0.f}, EBlendMode::Alpha, fadeTime, 0.f, false, false, true, + true, false, true); mgr.AddObject(colMod); colMod->x34_parent = parent; colMod->x54_30_enable = true; @@ -233,13 +231,14 @@ TUniqueId CScriptColorModulate::FadeOutHelper(CStateManager& mgr, TUniqueId pare TUniqueId CScriptColorModulate::FadeInHelper(CStateManager& mgr, TUniqueId parent, float fadeTime) { TAreaId aId = mgr.GetNextAreaId(); - if (const CEntity* ent = mgr.GetObjectById(parent)) + if (const auto* ent = mgr.GetObjectById(parent)) { 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::Alpha, fadeTime, 0.f, false, false, true, true, false, true); + auto* colMod = + new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::CColor{1.f, 0.f}, + zeus::skWhite, EBlendMode::Alpha, fadeTime, 0.f, false, true, true, true, false, true); mgr.AddObject(colMod); colMod->x34_parent = parent; colMod->x54_30_enable = true; @@ -259,15 +258,18 @@ void CScriptColorModulate::End(CStateManager& stateMgr) { x54_30_enable = false; x54_29_reversing = false; - if (x54_25_resetTargetWhenDone) + if (x54_25_resetTargetWhenDone) { SetTargetFlags(stateMgr, CModelFlags(0, 0, 3, zeus::skWhite)); + } - if (x55_24_isFadeOutHelper) + if (x55_24_isFadeOutHelper) { stateMgr.SendScriptMsgAlways(x34_parent, x8_uid, EScriptObjectMessage::Deactivate); + } - CEntity::SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None); + SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None); - if (x54_31_dieOnEnd) + if (x54_31_dieOnEnd) { stateMgr.FreeScriptObject(GetUniqueId()); + } } } // namespace urde diff --git a/Runtime/World/CScriptPlatform.cpp b/Runtime/World/CScriptPlatform.cpp index 4bab7cffa..188a3d7e4 100644 --- a/Runtime/World/CScriptPlatform.cpp +++ b/Runtime/World/CScriptPlatform.cpp @@ -7,6 +7,7 @@ #include "Runtime/Collision/CGameCollision.hpp" #include "Runtime/Collision/CMaterialList.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" +#include "Runtime/World/CActorParameters.hpp" #include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CScriptColorModulate.hpp" #include "Runtime/World/CScriptTrigger.hpp" @@ -24,26 +25,22 @@ CScriptPlatform::CScriptPlatform(TUniqueId uid, std::string_view name, const CEn const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const zeus::CAABox& aabb, float speed, bool detectCollision, float xrayAlpha, bool active, const CHealthInfo& hInfo, const CDamageVulnerability& dVuln, - std::optional> dcln, - bool rainSplashes, u32 maxRainSplashes, u32 rainGenRate) + std::optional> dcln, bool rainSplashes, + u32 maxRainSplashes, u32 rainGenRate) : CPhysicsActor(uid, active, name, info, xf, std::move(mData), skPlatformMaterialList, aabb, SMoverData(15000.f), actParms, 0.3f, 0.1f) , x25c_currentSpeed(speed) +, x268_fadeInTime(actParms.GetFadeInTime()) +, x26c_fadeOutTime(actParms.GetFadeOutTime()) , x28c_initialHealth(hInfo) , x294_health(hInfo) , x29c_damageVuln(dVuln) -, x304_treeGroupContainer(std::move(dcln)) { - x348_xrayAlpha = xrayAlpha; - x34c_maxRainSplashes = maxRainSplashes; - x350_rainGenRate = rainGenRate; - x356_24_dead = false; - x356_25_controlledAnimation = false; - x356_26_detectCollision = detectCollision; - x356_27_squishedRider = false; - x356_28_rainSplashes = rainSplashes; - x356_29_setXrayDrawFlags = false; - x356_30_disableXrayAlpha = false; - x356_31_xrayFog = true; +, x304_treeGroupContainer(std::move(dcln)) +, x348_xrayAlpha(xrayAlpha) +, x34c_maxRainSplashes(maxRainSplashes) +, x350_rainGenRate(rainGenRate) +, x356_26_detectCollision(detectCollision) +, x356_28_rainSplashes(rainSplashes) { CActor::SetMaterialFilter(CMaterialFilter::MakeIncludeExclude( CMaterialList(EMaterialTypes::Solid), CMaterialList(EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision, EMaterialTypes::Platform))); @@ -139,11 +136,10 @@ void CScriptPlatform::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C break; } case EScriptObjectMessage::Increment: { - if (GetActive()) { - CScriptColorModulate::FadeInHelper(mgr, GetUniqueId(), x268_fadeInTime); - } else { + if (!GetActive()) { mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Activate); } + CScriptColorModulate::FadeInHelper(mgr, GetUniqueId(), x268_fadeInTime); break; } case EScriptObjectMessage::Decrement: @@ -418,7 +414,7 @@ void CScriptPlatform::AddRider(std::vector& riders, TUniqueId riderId, void CScriptPlatform::AddSlave(TUniqueId id, CStateManager& mgr) { const auto& search = std::find_if(x338_slavesDynamic.begin(), x338_slavesDynamic.end(), - [id](const SRiders& r) { return r.x0_uid == id; }); + [id](const SRiders& r) { return r.x0_uid == id; }); if (search != x338_slavesDynamic.end()) { return; } diff --git a/Runtime/World/CScriptPlatform.hpp b/Runtime/World/CScriptPlatform.hpp index 0d000ffe0..c4020896e 100644 --- a/Runtime/World/CScriptPlatform.hpp +++ b/Runtime/World/CScriptPlatform.hpp @@ -52,19 +52,14 @@ class CScriptPlatform : public CPhysicsActor { u32 x34c_maxRainSplashes; u32 x350_rainGenRate; TUniqueId x354_boundsTrigger = kInvalidUniqueId; - union { - struct { - bool x356_24_dead : 1; - bool x356_25_controlledAnimation : 1; - bool x356_26_detectCollision : 1; - bool x356_27_squishedRider : 1; - bool x356_28_rainSplashes : 1; - bool x356_29_setXrayDrawFlags : 1; - bool x356_30_disableXrayAlpha : 1; - bool x356_31_xrayFog : 1; - }; - u32 x356_dummy = 0; - }; + bool x356_24_dead : 1 = false; + bool x356_25_controlledAnimation : 1 = false; + bool x356_26_detectCollision : 1; + bool x356_27_squishedRider : 1 = false; + bool x356_28_rainSplashes : 1; + bool x356_29_setXrayDrawFlags : 1 = false; + bool x356_30_disableXrayAlpha : 1 = false; + bool x356_31_xrayFog : 1 = true; void DragSlave(CStateManager& mgr, rstl::reserved_vector& draggedSet, CActor* actor, const zeus::CVector3f& delta);