CScriptPlatform: Fix breakable behavior; CScriptColorModulate fixes

This commit is contained in:
Luke Street 2020-05-07 02:19:58 -04:00
parent 40ede53949
commit d30ce2b218
4 changed files with 87 additions and 92 deletions

View File

@ -63,5 +63,7 @@ public:
float GetThermalMag() const { return x64_thermalMag; } float GetThermalMag() const { return x64_thermalMag; }
const std::pair<CAssetId, CAssetId>& GetXRayAssets() const { return x44_xrayAssets; } const std::pair<CAssetId, CAssetId>& GetXRayAssets() const { return x44_xrayAssets; }
const std::pair<CAssetId, CAssetId>& GetThermalAssets() const { return x4c_thermalAssets; } const std::pair<CAssetId, CAssetId>& GetThermalAssets() const { return x4c_thermalAssets; }
float GetFadeInTime() const { return x5c_fadeInTime; }
float GetFadeOutTime() const { return x60_fadeOutTime; }
}; };
} // namespace urde } // namespace urde

View File

@ -27,8 +27,9 @@ void CScriptColorModulate::Accept(IVisitor& visitor) { visitor.Visit(this); }
void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) { void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) {
CEntity::AcceptScriptMsg(msg, objId, mgr); CEntity::AcceptScriptMsg(msg, objId, mgr);
if (!GetActive()) if (!GetActive()) {
return; return;
}
switch (msg) { switch (msg) {
case EScriptObjectMessage::Increment: case EScriptObjectMessage::Increment:
@ -36,14 +37,16 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o
x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B;
x54_29_reversing = false; x54_29_reversing = false;
return; return;
} else if (x54_30_enable) { }
if (x38_fadeState == EFadeState::A2B) if (x54_30_enable) {
if (x38_fadeState == EFadeState::A2B) {
x3c_curTime = 0.f; x3c_curTime = 0.f;
else } else {
x3c_curTime = x4c_timeA2B - x4c_timeA2B * (x3c_curTime / x50_timeB2A); x3c_curTime = x4c_timeA2B - x4c_timeA2B * (x3c_curTime / x50_timeB2A);
} else }
} else {
SetTargetFlags(mgr, CalculateFlags(x40_colorA)); SetTargetFlags(mgr, CalculateFlags(x40_colorA));
}
x54_30_enable = true; x54_30_enable = true;
x38_fadeState = EFadeState::A2B; x38_fadeState = EFadeState::A2B;
break; break;
@ -52,14 +55,16 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o
x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B; x38_fadeState = x38_fadeState == EFadeState::A2B ? EFadeState::B2A : EFadeState::A2B;
x54_29_reversing = false; x54_29_reversing = false;
return; return;
} else if (x54_30_enable) { }
if (x38_fadeState == EFadeState::A2B) if (x54_30_enable) {
if (x38_fadeState == EFadeState::A2B) {
x3c_curTime = 0.f; x3c_curTime = 0.f;
else } else {
x3c_curTime = x50_timeB2A - x50_timeB2A * (x3c_curTime / x4c_timeA2B); x3c_curTime = x50_timeB2A - x50_timeB2A * (x3c_curTime / x4c_timeA2B);
} else }
} else {
SetTargetFlags(mgr, CalculateFlags(x44_colorB)); SetTargetFlags(mgr, CalculateFlags(x44_colorB));
}
x54_30_enable = true; x54_30_enable = true;
x38_fadeState = EFadeState::B2A; x38_fadeState = EFadeState::B2A;
break; break;
@ -69,47 +74,38 @@ void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o
} }
void CScriptColorModulate::Think(float dt, CStateManager& mgr) { void CScriptColorModulate::Think(float dt, CStateManager& mgr) {
if (!GetActive() || !x54_30_enable) if (!GetActive() || !x54_30_enable) {
return; 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); x3c_curTime += dt;
CModelFlags flags = CalculateFlags(lerpedCol); if (x38_fadeState == EFadeState::B2A) {
SetTargetFlags(mgr, flags); float t = 1.f;
if (!zeus::close_enough(x50_timeB2A, 0.f)) {
if (x3c_curTime <= x4c_timeA2B) t = std::min(1.f, x3c_curTime / x50_timeB2A);
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;
} }
zeus::CColor lerpedCol = zeus::CColor::lerp(x44_colorB, x40_colorA, t); zeus::CColor lerpedCol = zeus::CColor::lerp(x44_colorB, x40_colorA, t);
CModelFlags flags = CalculateFlags(lerpedCol); CModelFlags flags = CalculateFlags(lerpedCol);
SetTargetFlags(mgr, flags); SetTargetFlags(mgr, flags);
if (x3c_curTime <= x50_timeB2A) if (x3c_curTime > x50_timeB2A) {
return;
End(mgr); End(mgr);
} }
} else {
float t = 1.f;
if (!zeus::close_enough(x4c_timeA2B, 0.f)) {
t = std::min(1.f, x3c_curTime / x4c_timeA2B);
}
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);
}
}
} }
CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const { CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const {
@ -118,7 +114,7 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const
if (x48_blendMode == EBlendMode::Alpha) { if (x48_blendMode == EBlendMode::Alpha) {
ret.x0_blendMode = 5; ret.x0_blendMode = 5;
ret.x1_matSetIdx = 0; 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; ret.x4_color = col;
} else if (x48_blendMode == EBlendMode::Additive) { } else if (x48_blendMode == EBlendMode::Additive) {
ret.x0_blendMode = 7; ret.x0_blendMode = 7;
@ -147,7 +143,7 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const
} else { } else {
if (x48_blendMode == EBlendMode::Alpha) { if (x48_blendMode == EBlendMode::Alpha) {
if (col == zeus::skWhite) { if (col == zeus::skWhite) {
ret.x0_blendMode = 3; ret.x0_blendMode = 0;
ret.x1_matSetIdx = 0; ret.x1_matSetIdx = 0;
ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1;
ret.x4_color = zeus::skWhite; ret.x4_color = zeus::skWhite;
@ -169,7 +165,7 @@ CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor& col) const
ret.x4_color = col; ret.x4_color = col;
} else if (x48_blendMode == EBlendMode::Opaque) { } else if (x48_blendMode == EBlendMode::Opaque) {
if (col == zeus::skWhite) { if (col == zeus::skWhite) {
ret.x0_blendMode = 3; ret.x0_blendMode = 0;
ret.x1_matSetIdx = 0; ret.x1_matSetIdx = 0;
ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1; ret.x2_flags = x54_26_depthCompare << 0 | x54_27_depthUpdate << 1;
ret.x4_color = zeus::skWhite; 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) { void CScriptColorModulate::SetTargetFlags(CStateManager& stateMgr, const CModelFlags& flags) {
for (const SConnection& conn : x20_conns) { 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; continue;
}
auto search = stateMgr.GetIdListForScript(conn.x8_objId); auto search = stateMgr.GetIdListForScript(conn.x8_objId);
for (auto it = search.first; it != search.second; ++it) { for (auto it = search.first; it != search.second; ++it) {
CEntity* ent = stateMgr.ObjectById(it->second); if (TCastToPtr<CActor> act = stateMgr.ObjectById(it->second)) {
if (CActor* act = TCastToPtr<CActor>(ent))
act->SetDrawFlags(flags); act->SetDrawFlags(flags);
} }
} }
}
if (x34_parent != kInvalidUniqueId) { if (x34_parent != kInvalidUniqueId) {
CEntity* ent = stateMgr.ObjectById(x34_parent); if (TCastToPtr<CActor> act = stateMgr.ObjectById(x34_parent)) {
if (CActor* act = TCastToPtr<CActor>(ent))
act->SetDrawFlags(flags); act->SetDrawFlags(flags);
} }
}
} }
TUniqueId CScriptColorModulate::FadeOutHelper(CStateManager& mgr, TUniqueId parent, float fadeTime) { TUniqueId CScriptColorModulate::FadeOutHelper(CStateManager& mgr, TUniqueId parent, float fadeTime) {
TAreaId aId = mgr.GetNextAreaId(); TAreaId aId = mgr.GetNextAreaId();
if (const CEntity* ent = mgr.GetObjectById(parent)) if (const auto* ent = mgr.GetObjectById(parent)) {
aId = ent->GetAreaIdAlways(); aId = ent->GetAreaIdAlways();
}
TUniqueId ret = mgr.AllocateUniqueId(); TUniqueId ret = mgr.AllocateUniqueId();
CScriptColorModulate* colMod = new CScriptColorModulate( auto* colMod = new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::skWhite,
ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::CColor(1.f, 1.f, 1.f, 1.f), zeus::CColor{1.f, 0.f}, EBlendMode::Alpha, fadeTime, 0.f, false, false, true,
zeus::CColor(1.f, 1.f, 1.f, 0.f), EBlendMode::Alpha, fadeTime, 0.f, false, false, true, true, false, true); true, false, true);
mgr.AddObject(colMod); mgr.AddObject(colMod);
colMod->x34_parent = parent; colMod->x34_parent = parent;
colMod->x54_30_enable = true; 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) { TUniqueId CScriptColorModulate::FadeInHelper(CStateManager& mgr, TUniqueId parent, float fadeTime) {
TAreaId aId = mgr.GetNextAreaId(); TAreaId aId = mgr.GetNextAreaId();
if (const CEntity* ent = mgr.GetObjectById(parent)) if (const auto* ent = mgr.GetObjectById(parent)) {
aId = ent->GetAreaIdAlways(); aId = ent->GetAreaIdAlways();
}
TUniqueId ret = mgr.AllocateUniqueId(); TUniqueId ret = mgr.AllocateUniqueId();
CScriptColorModulate* colMod = new CScriptColorModulate( auto* colMod =
ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::CColor(1.f, 1.f, 1.f, 0.f), new CScriptColorModulate(ret, "", CEntityInfo(aId, CEntity::NullConnectionList), zeus::CColor{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); zeus::skWhite, EBlendMode::Alpha, fadeTime, 0.f, false, true, true, true, false, true);
mgr.AddObject(colMod); mgr.AddObject(colMod);
colMod->x34_parent = parent; colMod->x34_parent = parent;
colMod->x54_30_enable = true; colMod->x54_30_enable = true;
@ -259,15 +258,18 @@ void CScriptColorModulate::End(CStateManager& stateMgr) {
x54_30_enable = false; x54_30_enable = false;
x54_29_reversing = false; x54_29_reversing = false;
if (x54_25_resetTargetWhenDone) if (x54_25_resetTargetWhenDone) {
SetTargetFlags(stateMgr, CModelFlags(0, 0, 3, zeus::skWhite)); SetTargetFlags(stateMgr, CModelFlags(0, 0, 3, zeus::skWhite));
}
if (x55_24_isFadeOutHelper) if (x55_24_isFadeOutHelper) {
stateMgr.SendScriptMsgAlways(x34_parent, x8_uid, EScriptObjectMessage::Deactivate); 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()); stateMgr.FreeScriptObject(GetUniqueId());
}
} }
} // namespace urde } // namespace urde

View File

@ -7,6 +7,7 @@
#include "Runtime/Collision/CGameCollision.hpp" #include "Runtime/Collision/CGameCollision.hpp"
#include "Runtime/Collision/CMaterialList.hpp" #include "Runtime/Collision/CMaterialList.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "Runtime/World/CPlayer.hpp" #include "Runtime/World/CPlayer.hpp"
#include "Runtime/World/CScriptColorModulate.hpp" #include "Runtime/World/CScriptColorModulate.hpp"
#include "Runtime/World/CScriptTrigger.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::CTransform& xf, CModelData&& mData, const CActorParameters& actParms,
const zeus::CAABox& aabb, float speed, bool detectCollision, float xrayAlpha, const zeus::CAABox& aabb, float speed, bool detectCollision, float xrayAlpha,
bool active, const CHealthInfo& hInfo, const CDamageVulnerability& dVuln, bool active, const CHealthInfo& hInfo, const CDamageVulnerability& dVuln,
std::optional<TLockedToken<CCollidableOBBTreeGroupContainer>> dcln, std::optional<TLockedToken<CCollidableOBBTreeGroupContainer>> dcln, bool rainSplashes,
bool rainSplashes, u32 maxRainSplashes, u32 rainGenRate) u32 maxRainSplashes, u32 rainGenRate)
: CPhysicsActor(uid, active, name, info, xf, std::move(mData), skPlatformMaterialList, aabb, SMoverData(15000.f), : CPhysicsActor(uid, active, name, info, xf, std::move(mData), skPlatformMaterialList, aabb, SMoverData(15000.f),
actParms, 0.3f, 0.1f) actParms, 0.3f, 0.1f)
, x25c_currentSpeed(speed) , x25c_currentSpeed(speed)
, x268_fadeInTime(actParms.GetFadeInTime())
, x26c_fadeOutTime(actParms.GetFadeOutTime())
, x28c_initialHealth(hInfo) , x28c_initialHealth(hInfo)
, x294_health(hInfo) , x294_health(hInfo)
, x29c_damageVuln(dVuln) , x29c_damageVuln(dVuln)
, x304_treeGroupContainer(std::move(dcln)) { , x304_treeGroupContainer(std::move(dcln))
x348_xrayAlpha = xrayAlpha; , x348_xrayAlpha(xrayAlpha)
x34c_maxRainSplashes = maxRainSplashes; , x34c_maxRainSplashes(maxRainSplashes)
x350_rainGenRate = rainGenRate; , x350_rainGenRate(rainGenRate)
x356_24_dead = false; , x356_26_detectCollision(detectCollision)
x356_25_controlledAnimation = false; , x356_28_rainSplashes(rainSplashes) {
x356_26_detectCollision = detectCollision;
x356_27_squishedRider = false;
x356_28_rainSplashes = rainSplashes;
x356_29_setXrayDrawFlags = false;
x356_30_disableXrayAlpha = false;
x356_31_xrayFog = true;
CActor::SetMaterialFilter(CMaterialFilter::MakeIncludeExclude( CActor::SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(
CMaterialList(EMaterialTypes::Solid), CMaterialList(EMaterialTypes::Solid),
CMaterialList(EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision, EMaterialTypes::Platform))); CMaterialList(EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision, EMaterialTypes::Platform)));
@ -139,11 +136,10 @@ void CScriptPlatform::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
break; break;
} }
case EScriptObjectMessage::Increment: { case EScriptObjectMessage::Increment: {
if (GetActive()) { if (!GetActive()) {
CScriptColorModulate::FadeInHelper(mgr, GetUniqueId(), x268_fadeInTime);
} else {
mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Activate); mgr.SendScriptMsg(this, GetUniqueId(), EScriptObjectMessage::Activate);
} }
CScriptColorModulate::FadeInHelper(mgr, GetUniqueId(), x268_fadeInTime);
break; break;
} }
case EScriptObjectMessage::Decrement: case EScriptObjectMessage::Decrement:

View File

@ -52,19 +52,14 @@ class CScriptPlatform : public CPhysicsActor {
u32 x34c_maxRainSplashes; u32 x34c_maxRainSplashes;
u32 x350_rainGenRate; u32 x350_rainGenRate;
TUniqueId x354_boundsTrigger = kInvalidUniqueId; TUniqueId x354_boundsTrigger = kInvalidUniqueId;
union { bool x356_24_dead : 1 = false;
struct { bool x356_25_controlledAnimation : 1 = false;
bool x356_24_dead : 1;
bool x356_25_controlledAnimation : 1;
bool x356_26_detectCollision : 1; bool x356_26_detectCollision : 1;
bool x356_27_squishedRider : 1; bool x356_27_squishedRider : 1 = false;
bool x356_28_rainSplashes : 1; bool x356_28_rainSplashes : 1;
bool x356_29_setXrayDrawFlags : 1; bool x356_29_setXrayDrawFlags : 1 = false;
bool x356_30_disableXrayAlpha : 1; bool x356_30_disableXrayAlpha : 1 = false;
bool x356_31_xrayFog : 1; bool x356_31_xrayFog : 1 = true;
};
u32 x356_dummy = 0;
};
void DragSlave(CStateManager& mgr, rstl::reserved_vector<u16, 1024>& draggedSet, CActor* actor, void DragSlave(CStateManager& mgr, rstl::reserved_vector<u16, 1024>& draggedSet, CActor* actor,
const zeus::CVector3f& delta); const zeus::CVector3f& delta);