From 2233a78fe2b1dfe0be009bd1259b17e32059cf9b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Mar 2020 21:10:15 -0400 Subject: [PATCH] CToken: Add HasReference() member function Has the same semantics of operator bool(), but explains at the call site what is actually being tested for in the relation to the object itself. Aims to make readability slightly better (and removed the need for casts). --- Runtime/CToken.hpp | 4 +++- Runtime/Character/CAnimSourceReader.cpp | 2 +- Runtime/Character/CFBStreamedCompression.hpp | 2 +- Runtime/Character/CModelData.hpp | 12 ++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index 699f3c1ec..7d156928a 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -74,7 +74,9 @@ class CToken { public: /* Added to test for non-null state */ - explicit operator bool() const { return x0_objRef != nullptr; } + explicit operator bool() const { return HasReference(); } + bool HasReference() const { return x0_objRef != nullptr; } + void Unlock(); void Lock(); bool IsLocked() const { return x4_lockHeld; } diff --git a/Runtime/Character/CAnimSourceReader.cpp b/Runtime/Character/CAnimSourceReader.cpp index e98b1660f..f0722dc54 100644 --- a/Runtime/Character/CAnimSourceReader.cpp +++ b/Runtime/Character/CAnimSourceReader.cpp @@ -10,7 +10,7 @@ namespace urde { CAnimSourceInfo::CAnimSourceInfo(const TSubAnimTypeToken& token) : x4_token(token) {} -bool CAnimSourceInfo::HasPOIData() const { return bool(x4_token->x58_evntData); } +bool CAnimSourceInfo::HasPOIData() const { return x4_token->x58_evntData.HasReference(); } const std::vector& CAnimSourceInfo::GetBoolPOIStream() const { return x4_token->GetBoolPOIStream(); } diff --git a/Runtime/Character/CFBStreamedCompression.hpp b/Runtime/Character/CFBStreamedCompression.hpp index be95aa0b6..0c37c0fd6 100644 --- a/Runtime/Character/CFBStreamedCompression.hpp +++ b/Runtime/Character/CFBStreamedCompression.hpp @@ -75,7 +75,7 @@ public: CCharAnimTime GetAnimationDuration() const { return MainHeader().duration; } float GetAverageVelocity() const { return x10_averageVelocity; } const zeus::CVector3f& GetRootOffset() const { return x14_rootOffset; } - bool HasPOIData() const { return bool(x8_evntToken); } + bool HasPOIData() const { return x8_evntToken.HasReference(); } const std::vector& GetBoolPOIStream() const { return x8_evntToken->GetBoolPOIStream(); } const std::vector& GetInt32POIStream() const { return x8_evntToken->GetInt32POIStream(); } const std::vector& GetParticlePOIStream() const { return x8_evntToken->GetParticlePOIStream(); } diff --git a/Runtime/Character/CModelData.hpp b/Runtime/Character/CModelData.hpp index 2010f03c3..3ff8359d7 100644 --- a/Runtime/Character/CModelData.hpp +++ b/Runtime/Character/CModelData.hpp @@ -148,16 +148,16 @@ public: const zeus::CVector3f& GetScale() const { return x0_scale; } void SetScale(const zeus::CVector3f& scale) { x0_scale = scale; } bool HasAnimData() const { return x10_animData != nullptr; } - bool HasNormalModel() const { return bool(x1c_normalModel); } + bool HasNormalModel() const { return x1c_normalModel.HasReference(); } bool HasModel(EWhichModel which) const { if (x10_animData) { switch (which) { case EWhichModel::Normal: return true; case EWhichModel::XRay: - return x10_animData->GetXRayModel().operator bool(); + return x10_animData->GetXRayModel() != nullptr; case EWhichModel::Thermal: - return x10_animData->GetInfraModel().operator bool(); + return x10_animData->GetInfraModel() != nullptr; default: return false; } @@ -165,11 +165,11 @@ public: switch (which) { case EWhichModel::Normal: - return bool(x1c_normalModel); + return x1c_normalModel.HasReference(); case EWhichModel::XRay: - return bool(x2c_xrayModel); + return x2c_xrayModel.HasReference(); case EWhichModel::Thermal: - return bool(x3c_infraModel); + return x3c_infraModel.HasReference(); default: return false; }