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.
This commit is contained in:
Lioncash 2020-01-31 22:28:25 -05:00
parent cbf7140d21
commit 3147d39cd9
10 changed files with 38 additions and 28 deletions

View File

@ -185,9 +185,10 @@ EWeaponCollisionResponseTypes CScriptActor::GetCollisionResponseType(const zeus:
} }
std::optional<zeus::CAABox> CScriptActor::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptActor::GetTouchBounds() const {
if (GetActive() && x68_material.HasMaterial(EMaterialTypes::Solid)) if (GetActive() && x68_material.HasMaterial(EMaterialTypes::Solid)) {
return {CPhysicsActor::GetBoundingBox()}; return {CPhysicsActor::GetBoundingBox()};
return {}; }
return std::nullopt;
} }
void CScriptActor::Touch(CActor&, CStateManager&) { void CScriptActor::Touch(CActor&, CStateManager&) {

View File

@ -28,10 +28,11 @@ void CScriptCoverPoint::Think(float delta, CStateManager&) {
} }
std::optional<zeus::CAABox> CScriptCoverPoint::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptCoverPoint::GetTouchBounds() const {
if (x100_touchBounds) if (x100_touchBounds) {
return x100_touchBounds; return x100_touchBounds;
}
return {}; return std::nullopt;
} }
void CScriptCoverPoint::SetInUse(bool inUse) { void CScriptCoverPoint::SetInUse(bool inUse) {

View File

@ -193,9 +193,10 @@ void CScriptDamageableTrigger::Think(float dt, CStateManager& mgr) {
} }
std::optional<zeus::CAABox> CScriptDamageableTrigger::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptDamageableTrigger::GetTouchBounds() const {
if (x30_24_active && x300_24_notOccluded) if (x30_24_active && x300_24_notOccluded) {
return {zeus::CAABox(x14c_bounds.min + GetTranslation(), x14c_bounds.max + GetTranslation())}; return zeus::CAABox(x14c_bounds.min + GetTranslation(), x14c_bounds.max + GetTranslation());
return {}; }
return std::nullopt;
} }
} // namespace urde } // namespace urde

View File

@ -352,9 +352,10 @@ void CScriptDebris::Touch(CActor& other, CStateManager& mgr) {
} }
std::optional<zeus::CAABox> CScriptDebris::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptDebris::GetTouchBounds() const {
if (x281_31_dieOnProjectile) if (x281_31_dieOnProjectile) {
return {GetBoundingBox()}; return GetBoundingBox();
return {}; }
return std::nullopt;
} }
void CScriptDebris::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { void CScriptDebris::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {

View File

@ -150,8 +150,9 @@ void CScriptDock::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStat
} }
std::optional<zeus::CAABox> CScriptDock::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptDock::GetTouchBounds() const {
if (x264_dockState == EDockState::Three) if (x264_dockState == EDockState::Three) {
return {}; return std::nullopt;
}
return GetBoundingBox(); return GetBoundingBox();
} }

View File

@ -365,15 +365,17 @@ void CScriptDoor::SetDoorAnimation(CScriptDoor::EDoorAnimType type) {
} }
std::optional<zeus::CAABox> CScriptDoor::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptDoor::GetTouchBounds() const {
if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) {
return {CPhysicsActor::GetBoundingBox()}; return CPhysicsActor::GetBoundingBox();
return {}; }
return std::nullopt;
} }
std::optional<zeus::CAABox> CScriptDoor::GetProjectileBounds() const { std::optional<zeus::CAABox> CScriptDoor::GetProjectileBounds() const {
if (x2a8_28_projectilesCollide) if (x2a8_28_projectilesCollide) {
return {{x284_modelBounds.min + GetTranslation(), x284_modelBounds.max + GetTranslation()}}; return zeus::CAABox{x284_modelBounds.min + GetTranslation(), x284_modelBounds.max + GetTranslation()};
return {}; }
return std::nullopt;
} }
} // namespace urde } // namespace urde

View File

@ -311,9 +311,10 @@ void CScriptGunTurret::Touch(CActor& act, CStateManager& mgr) {
} }
std::optional<zeus::CAABox> CScriptGunTurret::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptGunTurret::GetTouchBounds() const {
if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) if (GetActive() && GetMaterialList().HasMaterial(EMaterialTypes::Solid)) {
return {GetBoundingBox()}; return GetBoundingBox();
return {}; }
return std::nullopt;
} }
zeus::CVector3f CScriptGunTurret::GetOrbitPosition(const CStateManager& mgr) const { return GetAimPosition(mgr, 0.f); } zeus::CVector3f CScriptGunTurret::GetOrbitPosition(const CStateManager& mgr) const { return GetAimPosition(mgr, 0.f); }

View File

@ -27,9 +27,10 @@ void CScriptSpiderBallAttractionSurface::AcceptScriptMsg(EScriptObjectMessage ms
} }
std::optional<zeus::CAABox> CScriptSpiderBallAttractionSurface::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptSpiderBallAttractionSurface::GetTouchBounds() const {
if (GetActive()) if (GetActive()) {
return {zeus::CAABox(xf4_aabb.min + GetTranslation(), xf4_aabb.max + GetTranslation())}; return zeus::CAABox(xf4_aabb.min + GetTranslation(), xf4_aabb.max + GetTranslation());
return {}; }
return std::nullopt;
} }
void CScriptSpiderBallAttractionSurface::Touch(CActor& actor, CStateManager& mgr) { void CScriptSpiderBallAttractionSurface::Touch(CActor& actor, CStateManager& mgr) {

View File

@ -203,9 +203,10 @@ void CScriptTrigger::UpdateInhabitants(float dt, CStateManager& mgr) {
std::list<CScriptTrigger::CObjectTracker>& CScriptTrigger::GetInhabitants() { return xe8_inhabitants; } std::list<CScriptTrigger::CObjectTracker>& CScriptTrigger::GetInhabitants() { return xe8_inhabitants; }
std::optional<zeus::CAABox> CScriptTrigger::GetTouchBounds() const { std::optional<zeus::CAABox> CScriptTrigger::GetTouchBounds() const {
if (x30_24_active) if (x30_24_active) {
return {GetTriggerBoundsWR()}; return GetTriggerBoundsWR();
return {}; }
return std::nullopt;
} }
constexpr auto sktonOHurtWeaponMode = CWeaponMode(EWeaponType::Power, false, false, true); constexpr auto sktonOHurtWeaponMode = CWeaponMode(EWeaponType::Power, false, false, true);

View File

@ -111,7 +111,7 @@ void CScriptVisorGoo::Render(const CStateManager& mgr) const {
// Empty // Empty
} }
std::optional<zeus::CAABox> CScriptVisorGoo::GetTouchBounds() const { return {}; } std::optional<zeus::CAABox> CScriptVisorGoo::GetTouchBounds() const { return std::nullopt; }
void CScriptVisorGoo::Touch(CActor& other, CStateManager& mgr) { void CScriptVisorGoo::Touch(CActor& other, CStateManager& mgr) {
// Empty // Empty