Refactor enum flags with __underlying_type and new EnumHasAnyFlags/EnumHasAllFlags

Fixes #832
Closes #886
This commit is contained in:
Wojtek Figat
2023-01-15 12:44:39 +01:00
parent 810f7fb803
commit f127bbebe1
101 changed files with 424 additions and 414 deletions

View File

@@ -42,7 +42,6 @@ public:
/// <summary>
/// Gets the string representation of this object.
/// </summary>
/// <returns>The string.</returns>
virtual String ToString() const = 0;
/// <summary>

View File

@@ -113,7 +113,7 @@ void ObjectsRemovalService::Flush(float dt, float gameDelta)
for (auto i = Pool.Begin(); i.IsNotEnd(); ++i)
{
auto obj = i->Key;
const float ttl = i->Value - (obj->Flags & ObjectFlags::UseGameTimeForDelete ? gameDelta : dt);
const float ttl = i->Value - ((obj->Flags & ObjectFlags::UseGameTimeForDelete) != ObjectFlags::None ? gameDelta : dt);
if (ttl <= ZeroTolerance)
{
Pool.Remove(i);

View File

@@ -141,13 +141,28 @@ struct Color32;
// Declares full set of operators for the enum type (using binary operation on integer values)
#define DECLARE_ENUM_OPERATORS(T) \
inline constexpr T operator~ (T a) { return (T)~(int)a; } \
inline constexpr T operator| (T a, T b) { return (T)((int)a | (int)b); } \
inline constexpr int operator& (T a, T b) { return ((int)a & (int)b); } \
inline constexpr T operator^ (T a, T b) { return (T)((int)a ^ (int)b); } \
inline T& operator|= (T& a, T b) { return (T&)((int&)a |= (int)b); } \
inline T& operator&= (T& a, T b) { return (T&)((int&)a &= (int)b); } \
inline T& operator^= (T& a, T b) { return (T&)((int&)a ^= (int)b); }
inline constexpr bool operator!(T a) { return !(__underlying_type(T))a; } \
inline constexpr T operator~(T a) { return (T)~(__underlying_type(T))a; } \
inline constexpr T operator|(T a, T b) { return (T)((__underlying_type(T))a | (__underlying_type(T))b); } \
inline constexpr T operator&(T a, T b) { return (T)((__underlying_type(T))a & (__underlying_type(T))b); } \
inline constexpr T operator^(T a, T b) { return (T)((__underlying_type(T))a ^ (__underlying_type(T))b); } \
inline T& operator|=(T& a, T b) { return a = (T)((__underlying_type(T))a | (__underlying_type(T))b); } \
inline T& operator&=(T& a, T b) { return a = (T)((__underlying_type(T))a & (__underlying_type(T))b); } \
inline T& operator^=(T& a, T b) { return a = (T)((__underlying_type(T))a ^ (__underlying_type(T))b); }
// Returns true if given enum value has one or more enum flags set
template<typename T>
constexpr bool EnumHasAnyFlags(T value, T flags)
{
return ((__underlying_type(T))value & (__underlying_type(T))flags) != 0;
}
// Returns true if given enum value has all of the enum flags set
template<typename T>
constexpr bool EnumHasAllFlags(T value, T flags)
{
return ((__underlying_type(T))value & (__underlying_type(T))flags) == (__underlying_type(T))flags;
}
// Returns byte offset from the object pointer in vtable to the begin of the given inherited type implementation
#define VTABLE_OFFSET(type, baseType) (((intptr)static_cast<baseType*>((type*)1))-1)