From c020084587b82cab22303c3abdfa856107a677b2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 12 Jun 2020 13:14:37 -0400 Subject: [PATCH] CCollisionMaterial: Make use of std::array Allows simplifying some size calculations. --- .../Resource/Collision/CCollisionMaterial.cpp | 17 +++++++++-------- .../Resource/Collision/CCollisionMaterial.h | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Core/Resource/Collision/CCollisionMaterial.cpp b/src/Core/Resource/Collision/CCollisionMaterial.cpp index faee1931..16ac4693 100644 --- a/src/Core/Resource/Collision/CCollisionMaterial.cpp +++ b/src/Core/Resource/Collision/CCollisionMaterial.cpp @@ -1,17 +1,18 @@ #include "CCollisionMaterial.h" #include #include +#include ECollisionFlag CCollisionMaterial::SurfaceType(EGame Game) const { // Arrays determining the type hierarchy for each game. // Flags earlier in the list take priority over flags later in the list. - static const ECollisionFlag skPrimeTypeHierarchy[] = { + static constexpr std::array skPrimeTypeHierarchy{ eCF_Organic, eCF_Wood, eCF_Sand, eCF_Shield, eCF_Glass, eCF_Mud, eCF_SlowMud, eCF_Snow, eCF_Lava, eCF_Dirt, eCF_Phazon, eCF_MetalGrating, eCF_Ice, eCF_Grass, eCF_Metal, eCF_Stone }; - static const ECollisionFlag skEchoesTypeHierarchy[] = { + static constexpr std::array skEchoesTypeHierarchy{ eCF_Rubber, eCF_Organic, eCF_Wood, eCF_Web, eCF_MothSeedOrganics, eCF_Sand, eCF_Shield, eCF_Fabric, eCF_Snow, eCF_Glass, eCF_AltMetal, eCF_Dirt, eCF_Phazon, eCF_MetalGrating, eCF_Ice, eCF_Grass, eCF_Metal, eCF_Stone @@ -19,21 +20,21 @@ ECollisionFlag CCollisionMaterial::SurfaceType(EGame Game) const // Determine which list we should use. const ECollisionFlag* pkFlagArray; - uint32 Num; + size_t Num; if (Game <= EGame::Prime) { - pkFlagArray = skPrimeTypeHierarchy; - Num = sizeof(skPrimeTypeHierarchy) / sizeof(ECollisionFlag); + pkFlagArray = skPrimeTypeHierarchy.data(); + Num = skPrimeTypeHierarchy.size(); } else { - pkFlagArray = skEchoesTypeHierarchy; - Num = sizeof(skEchoesTypeHierarchy) / sizeof(ECollisionFlag); + pkFlagArray = skEchoesTypeHierarchy.data(); + Num = skEchoesTypeHierarchy.size(); } // Locate type. - for (uint32 iType = 0; iType < Num; iType++) + for (size_t iType = 0; iType < Num; iType++) { if (*this & pkFlagArray[iType]) return pkFlagArray[iType]; diff --git a/src/Core/Resource/Collision/CCollisionMaterial.h b/src/Core/Resource/Collision/CCollisionMaterial.h index e06592aa..5c5d6963 100644 --- a/src/Core/Resource/Collision/CCollisionMaterial.h +++ b/src/Core/Resource/Collision/CCollisionMaterial.h @@ -51,7 +51,7 @@ enum ECollisionFlag class CCollisionMaterial : public TFlags { friend class CCollisionLoader; - uint64 mRawFlags; + uint64 mRawFlags = 0; public: ECollisionFlag SurfaceType(EGame Game) const;