From 3147d39cd9e57926a2abf76312c391853a5e3272 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 31 Jan 2020 22:28:25 -0500 Subject: [PATCH] CScript*: Return std::nullopt in GetTouchBounds() In some implementations, returning via default construction for std::optional can cause the entire inner buffer to be zeroed out. Returning with std::nullopt causes only the internal validity flag to be set and nothing more. --- Runtime/World/CScriptActor.cpp | 5 +++-- Runtime/World/CScriptCoverPoint.cpp | 5 +++-- Runtime/World/CScriptDamageableTrigger.cpp | 7 ++++--- Runtime/World/CScriptDebris.cpp | 7 ++++--- Runtime/World/CScriptDock.cpp | 5 +++-- Runtime/World/CScriptDoor.cpp | 14 ++++++++------ Runtime/World/CScriptGunTurret.cpp | 7 ++++--- .../World/CScriptSpiderBallAttractionSurface.cpp | 7 ++++--- Runtime/World/CScriptTrigger.cpp | 7 ++++--- Runtime/World/CScriptVisorGoo.cpp | 2 +- 10 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Runtime/World/CScriptActor.cpp b/Runtime/World/CScriptActor.cpp index 0834af607..a8a77351e 100644 --- a/Runtime/World/CScriptActor.cpp +++ b/Runtime/World/CScriptActor.cpp @@ -185,9 +185,10 @@ EWeaponCollisionResponseTypes CScriptActor::GetCollisionResponseType(const zeus: } std::optional CScriptActor::GetTouchBounds() const { - if (GetActive() && x68_material.HasMaterial(EMaterialTypes::Solid)) + if (GetActive() && x68_material.HasMaterial(EMaterialTypes::Solid)) { return {CPhysicsActor::GetBoundingBox()}; - return {}; + } + return std::nullopt; } void CScriptActor::Touch(CActor&, CStateManager&) { diff --git a/Runtime/World/CScriptCoverPoint.cpp b/Runtime/World/CScriptCoverPoint.cpp index c42730507..20bbf4eb9 100644 --- a/Runtime/World/CScriptCoverPoint.cpp +++ b/Runtime/World/CScriptCoverPoint.cpp @@ -28,10 +28,11 @@ void CScriptCoverPoint::Think(float delta, CStateManager&) { } std::optional CScriptCoverPoint::GetTouchBounds() const { - if (x100_touchBounds) + if (x100_touchBounds) { return x100_touchBounds; + } - return {}; + return std::nullopt; } void CScriptCoverPoint::SetInUse(bool inUse) { diff --git a/Runtime/World/CScriptDamageableTrigger.cpp b/Runtime/World/CScriptDamageableTrigger.cpp index c7d1a26a1..59b0796df 100644 --- a/Runtime/World/CScriptDamageableTrigger.cpp +++ b/Runtime/World/CScriptDamageableTrigger.cpp @@ -193,9 +193,10 @@ void CScriptDamageableTrigger::Think(float dt, CStateManager& mgr) { } std::optional CScriptDamageableTrigger::GetTouchBounds() const { - if (x30_24_active && x300_24_notOccluded) - return {zeus::CAABox(x14c_bounds.min + GetTranslation(), x14c_bounds.max + GetTranslation())}; - return {}; + if (x30_24_active && x300_24_notOccluded) { + return zeus::CAABox(x14c_bounds.min + GetTranslation(), x14c_bounds.max + GetTranslation()); + } + return std::nullopt; } } // namespace urde diff --git a/Runtime/World/CScriptDebris.cpp b/Runtime/World/CScriptDebris.cpp index 01acf53aa..5c7c669e7 100644 --- a/Runtime/World/CScriptDebris.cpp +++ b/Runtime/World/CScriptDebris.cpp @@ -352,9 +352,10 @@ void CScriptDebris::Touch(CActor& other, CStateManager& mgr) { } std::optional CScriptDebris::GetTouchBounds() const { - if (x281_31_dieOnProjectile) - return {GetBoundingBox()}; - return {}; + if (x281_31_dieOnProjectile) { + return GetBoundingBox(); + } + return std::nullopt; } void CScriptDebris::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { diff --git a/Runtime/World/CScriptDock.cpp b/Runtime/World/CScriptDock.cpp index f348d4ffb..9440242a9 100644 --- a/Runtime/World/CScriptDock.cpp +++ b/Runtime/World/CScriptDock.cpp @@ -150,8 +150,9 @@ void CScriptDock::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStat } std::optional CScriptDock::GetTouchBounds() const { - if (x264_dockState == EDockState::Three) - return {}; + if (x264_dockState == EDockState::Three) { + return std::nullopt; + } return GetBoundingBox(); } diff --git a/Runtime/World/CScriptDoor.cpp b/Runtime/World/CScriptDoor.cpp index 28d4e7f24..0d392dacb 100644 --- a/Runtime/World/CScriptDoor.cpp +++ b/Runtime/World/CScriptDoor.cpp @@ -365,15 +365,17 @@ void CScriptDoor::SetDoorAnimation(CScriptDoor::EDoorAnimType type) { } std::optional CScriptDoor::GetTouchBounds() const { - if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) - return {CPhysicsActor::GetBoundingBox()}; - return {}; + if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) { + return CPhysicsActor::GetBoundingBox(); + } + return std::nullopt; } std::optional CScriptDoor::GetProjectileBounds() const { - if (x2a8_28_projectilesCollide) - return {{x284_modelBounds.min + GetTranslation(), x284_modelBounds.max + GetTranslation()}}; - return {}; + if (x2a8_28_projectilesCollide) { + return zeus::CAABox{x284_modelBounds.min + GetTranslation(), x284_modelBounds.max + GetTranslation()}; + } + return std::nullopt; } } // namespace urde diff --git a/Runtime/World/CScriptGunTurret.cpp b/Runtime/World/CScriptGunTurret.cpp index 084724948..9bc9dc430 100644 --- a/Runtime/World/CScriptGunTurret.cpp +++ b/Runtime/World/CScriptGunTurret.cpp @@ -311,9 +311,10 @@ void CScriptGunTurret::Touch(CActor& act, CStateManager& mgr) { } std::optional CScriptGunTurret::GetTouchBounds() const { - if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) - return {GetBoundingBox()}; - return {}; + if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) { + return GetBoundingBox(); + } + return std::nullopt; } zeus::CVector3f CScriptGunTurret::GetOrbitPosition(const CStateManager& mgr) const { return GetAimPosition(mgr, 0.f); } diff --git a/Runtime/World/CScriptSpiderBallAttractionSurface.cpp b/Runtime/World/CScriptSpiderBallAttractionSurface.cpp index ed7c035c5..40c9390b6 100644 --- a/Runtime/World/CScriptSpiderBallAttractionSurface.cpp +++ b/Runtime/World/CScriptSpiderBallAttractionSurface.cpp @@ -27,9 +27,10 @@ void CScriptSpiderBallAttractionSurface::AcceptScriptMsg(EScriptObjectMessage ms } std::optional CScriptSpiderBallAttractionSurface::GetTouchBounds() const { - if (GetActive()) - return {zeus::CAABox(xf4_aabb.min + GetTranslation(), xf4_aabb.max + GetTranslation())}; - return {}; + if (GetActive()) { + return zeus::CAABox(xf4_aabb.min + GetTranslation(), xf4_aabb.max + GetTranslation()); + } + return std::nullopt; } void CScriptSpiderBallAttractionSurface::Touch(CActor& actor, CStateManager& mgr) { diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index 105a11f3a..bd84015e6 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -203,9 +203,10 @@ void CScriptTrigger::UpdateInhabitants(float dt, CStateManager& mgr) { std::list& CScriptTrigger::GetInhabitants() { return xe8_inhabitants; } std::optional CScriptTrigger::GetTouchBounds() const { - if (x30_24_active) - return {GetTriggerBoundsWR()}; - return {}; + if (x30_24_active) { + return GetTriggerBoundsWR(); + } + return std::nullopt; } constexpr auto sktonOHurtWeaponMode = CWeaponMode(EWeaponType::Power, false, false, true); diff --git a/Runtime/World/CScriptVisorGoo.cpp b/Runtime/World/CScriptVisorGoo.cpp index 7600e59cd..5463479d2 100644 --- a/Runtime/World/CScriptVisorGoo.cpp +++ b/Runtime/World/CScriptVisorGoo.cpp @@ -111,7 +111,7 @@ void CScriptVisorGoo::Render(const CStateManager& mgr) const { // Empty } -std::optional CScriptVisorGoo::GetTouchBounds() const { return {}; } +std::optional CScriptVisorGoo::GetTouchBounds() const { return std::nullopt; } void CScriptVisorGoo::Touch(CActor& other, CStateManager& mgr) { // Empty