CCollisionMaterial: Make use of std::array

Allows simplifying some size calculations.
This commit is contained in:
Lioncash 2020-06-12 13:14:37 -04:00
parent a51604ca91
commit c020084587
2 changed files with 10 additions and 9 deletions

View File

@ -1,17 +1,18 @@
#include "CCollisionMaterial.h" #include "CCollisionMaterial.h"
#include <Common/Macros.h> #include <Common/Macros.h>
#include <unordered_map> #include <unordered_map>
#include <array>
ECollisionFlag CCollisionMaterial::SurfaceType(EGame Game) const ECollisionFlag CCollisionMaterial::SurfaceType(EGame Game) const
{ {
// Arrays determining the type hierarchy for each game. // Arrays determining the type hierarchy for each game.
// Flags earlier in the list take priority over flags later in the list. // 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_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_Snow, eCF_Lava, eCF_Dirt, eCF_Phazon, eCF_MetalGrating, eCF_Ice, eCF_Grass,
eCF_Metal, eCF_Stone 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_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_Shield, eCF_Fabric, eCF_Snow, eCF_Glass, eCF_AltMetal, eCF_Dirt, eCF_Phazon,
eCF_MetalGrating, eCF_Ice, eCF_Grass, eCF_Metal, eCF_Stone 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. // Determine which list we should use.
const ECollisionFlag* pkFlagArray; const ECollisionFlag* pkFlagArray;
uint32 Num; size_t Num;
if (Game <= EGame::Prime) if (Game <= EGame::Prime)
{ {
pkFlagArray = skPrimeTypeHierarchy; pkFlagArray = skPrimeTypeHierarchy.data();
Num = sizeof(skPrimeTypeHierarchy) / sizeof(ECollisionFlag); Num = skPrimeTypeHierarchy.size();
} }
else else
{ {
pkFlagArray = skEchoesTypeHierarchy; pkFlagArray = skEchoesTypeHierarchy.data();
Num = sizeof(skEchoesTypeHierarchy) / sizeof(ECollisionFlag); Num = skEchoesTypeHierarchy.size();
} }
// Locate type. // Locate type.
for (uint32 iType = 0; iType < Num; iType++) for (size_t iType = 0; iType < Num; iType++)
{ {
if (*this & pkFlagArray[iType]) if (*this & pkFlagArray[iType])
return pkFlagArray[iType]; return pkFlagArray[iType];

View File

@ -51,7 +51,7 @@ enum ECollisionFlag
class CCollisionMaterial : public TFlags<ECollisionFlag> class CCollisionMaterial : public TFlags<ECollisionFlag>
{ {
friend class CCollisionLoader; friend class CCollisionLoader;
uint64 mRawFlags; uint64 mRawFlags = 0;
public: public:
ECollisionFlag SurfaceType(EGame Game) const; ECollisionFlag SurfaceType(EGame Game) const;