mirror of https://github.com/PCSX2/pcsx2.git
Common: Purge pxEnum macros
This commit is contained in:
parent
d585712b40
commit
9d49015c0c
|
@ -5,6 +5,13 @@
|
|||
|
||||
#include <type_traits>
|
||||
|
||||
// Template function for casting enumerations to their underlying type
|
||||
template <typename Enumeration>
|
||||
typename std::underlying_type<Enumeration>::type enum_cast(Enumeration E)
|
||||
{
|
||||
return static_cast<typename std::underlying_type<Enumeration>::type>(E);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
/// Marks an enum as supporting boolean operators
|
||||
|
|
|
@ -99,71 +99,6 @@ static constexpr unsigned int __pagemask = __pagesize - 1;
|
|||
#define safe_delete_array(ptr) (delete[] (ptr), (ptr) = nullptr)
|
||||
#define safe_free(ptr) (std::free(ptr), (ptr) = nullptr)
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// ImplementEnumOperators (macro)
|
||||
// --------------------------------------------------------------------------------------
|
||||
// This macro implements ++/-- operators for any conforming enumeration. In order for an
|
||||
// enum to conform, it must have _FIRST and _COUNT members defined, and must have a full
|
||||
// compliment of sequential members (no custom assignments) --- looking like so:
|
||||
//
|
||||
// enum Dummy {
|
||||
// Dummy_FIRST,
|
||||
// Dummy_Item = Dummy_FIRST,
|
||||
// Dummy_Crap,
|
||||
// Dummy_COUNT
|
||||
// };
|
||||
//
|
||||
// The macro also defines utility functions for bounds checking enumerations:
|
||||
// EnumIsValid(value); // returns TRUE if the enum value is between FIRST and COUNT.
|
||||
// EnumAssert(value);
|
||||
//
|
||||
// It also defines a *prototype* for converting the enumeration to a string. Note that this
|
||||
// method is not implemented! You must implement it yourself if you want to use it:
|
||||
// EnumToString(value);
|
||||
//
|
||||
#define ImplementEnumOperators(enumName) \
|
||||
static __fi enumName& operator++(enumName& src) \
|
||||
{ \
|
||||
src = (enumName)((int)src + 1); \
|
||||
return src; \
|
||||
} \
|
||||
\
|
||||
static __fi enumName& operator--(enumName& src) \
|
||||
{ \
|
||||
src = (enumName)((int)src - 1); \
|
||||
return src; \
|
||||
} \
|
||||
\
|
||||
static __fi enumName operator++(enumName& src, int) \
|
||||
{ \
|
||||
enumName orig = src; \
|
||||
src = (enumName)((int)src + 1); \
|
||||
return orig; \
|
||||
} \
|
||||
\
|
||||
static __fi enumName operator--(enumName& src, int) \
|
||||
{ \
|
||||
enumName orig = src; \
|
||||
src = (enumName)((int)src - 1); \
|
||||
return orig; \
|
||||
} \
|
||||
\
|
||||
static __fi bool operator<(const enumName& left, const pxEnumEnd_t&) { return (int)left < enumName##_COUNT; } \
|
||||
static __fi bool operator!=(const enumName& left, const pxEnumEnd_t&) { return (int)left != enumName##_COUNT; } \
|
||||
static __fi bool operator==(const enumName& left, const pxEnumEnd_t&) { return (int)left == enumName##_COUNT; } \
|
||||
\
|
||||
static __fi bool EnumIsValid(enumName id) \
|
||||
{ \
|
||||
return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); \
|
||||
} \
|
||||
\
|
||||
extern const char* EnumToString(enumName id)
|
||||
|
||||
class pxEnumEnd_t
|
||||
{
|
||||
};
|
||||
static const pxEnumEnd_t pxEnumEnd = {};
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// DeclareNoncopyableObject
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "SettingsInterface.h"
|
||||
|
||||
#include "common/EnumOps.h"
|
||||
|
||||
// Helper class which loads or saves depending on the derived class.
|
||||
class SettingsWrapper
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "common/Assertions.h"
|
||||
#include "common/Console.h"
|
||||
#include "common/EnumOps.h"
|
||||
#include "common/FileSystem.h"
|
||||
#include "common/Path.h"
|
||||
#include "common/StringUtil.h"
|
||||
|
|
|
@ -376,15 +376,6 @@ enum class GSHalfPixelOffset : u8
|
|||
MaxCount
|
||||
};
|
||||
|
||||
// Template function for casting enumerations to their underlying type
|
||||
template <typename Enumeration>
|
||||
typename std::underlying_type<Enumeration>::type enum_cast(Enumeration E)
|
||||
{
|
||||
return static_cast<typename std::underlying_type<Enumeration>::type>(E);
|
||||
}
|
||||
|
||||
ImplementEnumOperators(GamefixId);
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// TraceFiltersEE
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
@ -1043,6 +1034,8 @@ struct Pcsx2Config
|
|||
void LoadSave(SettingsWrapper& wrap);
|
||||
GamefixOptions& DisableAll();
|
||||
|
||||
static const char* GetGameFixName(GamefixId id);
|
||||
|
||||
bool Get(GamefixId id) const;
|
||||
void Set(GamefixId id, bool enabled = true);
|
||||
void Clear(GamefixId id) { Set(id, false); }
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "vtlb.h"
|
||||
|
||||
#include "common/Console.h"
|
||||
#include "common/EnumOps.h"
|
||||
#include "common/Error.h"
|
||||
#include "common/FileSystem.h"
|
||||
#include "common/Path.h"
|
||||
|
@ -193,9 +194,9 @@ void GameDatabase::parseAndInsert(const std::string_view& serial, const c4::yml:
|
|||
if (fix.ends_with("Hack"))
|
||||
{
|
||||
fix.erase(fix.size() - 4);
|
||||
for (GamefixId id = GamefixId_FIRST; id < pxEnumEnd; ++id)
|
||||
for (GamefixId id = GamefixId_FIRST; id < GamefixId_COUNT; id = static_cast<GamefixId>(enum_cast(id) + 1))
|
||||
{
|
||||
if (fix.compare(EnumToString(id)) == 0 &&
|
||||
if (fix.compare(Pcsx2Config::GamefixOptions::GetGameFixName(id)) == 0 &&
|
||||
std::find(gameEntry.gameFixes.begin(), gameEntry.gameFixes.end(), id) == gameEntry.gameFixes.end())
|
||||
{
|
||||
gameEntry.gameFixes.push_back(id);
|
||||
|
@ -535,12 +536,12 @@ void GameDatabaseSchema::GameEntry::applyGameFixes(Pcsx2Config& config, bool app
|
|||
{
|
||||
if (!applyAuto)
|
||||
{
|
||||
Console.Warning("[GameDB] Skipping Gamefix: %s", EnumToString(id));
|
||||
Console.Warning("[GameDB] Skipping Gamefix: %s", Pcsx2Config::GamefixOptions::GetGameFixName(id));
|
||||
continue;
|
||||
}
|
||||
// if the fix is present, it is said to be enabled
|
||||
config.Gamefixes.Set(id, true);
|
||||
Console.WriteLn("(GameDB) Enabled Gamefix: %s", EnumToString(id));
|
||||
Console.WriteLn("(GameDB) Enabled Gamefix: %s", Pcsx2Config::GamefixOptions::GetGameFixName(id));
|
||||
|
||||
// The LUT is only used for 1 game so we allocate it only when the gamefix is enabled (save 4MB)
|
||||
if (id == Fix_GoemonTlbMiss && true)
|
||||
|
|
|
@ -1135,7 +1135,7 @@ static const char* const tbl_GamefixNames[] =
|
|||
"FullVU0Sync",
|
||||
};
|
||||
|
||||
const char* EnumToString(GamefixId id)
|
||||
const char* Pcsx2Config::GamefixOptions::GetGameFixName(GamefixId id)
|
||||
{
|
||||
return tbl_GamefixNames[id];
|
||||
}
|
||||
|
@ -1154,7 +1154,6 @@ Pcsx2Config::GamefixOptions& Pcsx2Config::GamefixOptions::DisableAll()
|
|||
|
||||
void Pcsx2Config::GamefixOptions::Set(GamefixId id, bool enabled)
|
||||
{
|
||||
pxAssert(EnumIsValid(id));
|
||||
switch (id)
|
||||
{
|
||||
// clang-format off
|
||||
|
@ -1177,14 +1176,13 @@ void Pcsx2Config::GamefixOptions::Set(GamefixId id, bool enabled)
|
|||
case Fix_VUOverflow: VUOverflowHack = enabled; break;
|
||||
case Fix_BlitInternalFPS: BlitInternalFPSHack = enabled; break;
|
||||
case Fix_FullVU0Sync: FullVU0SyncHack = enabled; break;
|
||||
jNO_DEFAULT;
|
||||
default: break;
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
bool Pcsx2Config::GamefixOptions::Get(GamefixId id) const
|
||||
{
|
||||
pxAssert(EnumIsValid(id));
|
||||
switch (id)
|
||||
{
|
||||
// clang-format off
|
||||
|
@ -1207,7 +1205,7 @@ bool Pcsx2Config::GamefixOptions::Get(GamefixId id) const
|
|||
case Fix_VUOverflow: return VUOverflowHack;
|
||||
case Fix_BlitInternalFPS: return BlitInternalFPSHack;
|
||||
case Fix_FullVU0Sync: return FullVU0SyncHack;
|
||||
jNO_DEFAULT;
|
||||
default: return false;
|
||||
// clang-format on
|
||||
}
|
||||
return false; // unreachable, but we still need to suppress warnings >_<
|
||||
|
|
Loading…
Reference in New Issue