Simplify map structure tracker overloads

Due to less branching, this is actually faster than trying to be clever.

git-svn-id: https://svn.eduke32.com/eduke32@7690 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-06-25 11:27:52 +00:00 committed by Christoph Oelckers
parent dd2e35eab3
commit 0556fe1738
6 changed files with 91 additions and 183 deletions

View file

@ -368,8 +368,6 @@
<ClInclude Include="..\..\source\build\include\softsurface.h" /> <ClInclude Include="..\..\source\build\include\softsurface.h" />
<ClInclude Include="..\..\source\build\include\texcache.h" /> <ClInclude Include="..\..\source\build\include\texcache.h" />
<ClInclude Include="..\..\source\build\include\tracker.hpp" /> <ClInclude Include="..\..\source\build\include\tracker.hpp" />
<ClInclude Include="..\..\source\build\include\tracker_operator.hpp" />
<ClInclude Include="..\..\source\build\include\tracker_operators.hpp" />
<ClInclude Include="..\..\source\build\include\vfs.h" /> <ClInclude Include="..\..\source\build\include\vfs.h" />
<ClInclude Include="..\..\source\build\include\winbits.h" /> <ClInclude Include="..\..\source\build\include\winbits.h" />
<ClInclude Include="..\..\source\build\include\winlayer.h" /> <ClInclude Include="..\..\source\build\include\winlayer.h" />

View file

@ -370,12 +370,6 @@
<ClInclude Include="..\..\source\build\include\tracker.hpp"> <ClInclude Include="..\..\source\build\include\tracker.hpp">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\source\build\include\tracker_operator.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\source\build\include\tracker_operators.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\source\build\include\winbits.h"> <ClInclude Include="..\..\source\build\include\winbits.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>

View file

@ -285,23 +285,23 @@ static FORCE_INLINE void wall_tracker_hook(uintptr_t address);
static FORCE_INLINE void sprite_tracker_hook(uintptr_t address); static FORCE_INLINE void sprite_tracker_hook(uintptr_t address);
} }
#define TRACKER_NAME_ SectorTracker #define TRACKER_NAME__ SectorTracker
#define TRACKER_GLOBAL_HOOK_ sector_tracker_hook #define TRACKER_HOOK_ sector_tracker_hook
#include "tracker.hpp" #include "tracker.hpp"
#undef TRACKER_NAME_ #undef TRACKER_NAME__
#undef TRACKER_GLOBAL_HOOK_ #undef TRACKER_HOOK_
#define TRACKER_NAME_ WallTracker #define TRACKER_NAME__ WallTracker
#define TRACKER_GLOBAL_HOOK_ wall_tracker_hook #define TRACKER_HOOK_ wall_tracker_hook
#include "tracker.hpp" #include "tracker.hpp"
#undef TRACKER_NAME_ #undef TRACKER_NAME__
#undef TRACKER_GLOBAL_HOOK_ #undef TRACKER_HOOK_
#define TRACKER_NAME_ SpriteTracker #define TRACKER_NAME__ SpriteTracker
#define TRACKER_GLOBAL_HOOK_ sprite_tracker_hook #define TRACKER_HOOK_ sprite_tracker_hook
#include "tracker.hpp" #include "tracker.hpp"
#undef TRACKER_NAME_ #undef TRACKER_NAME__
#undef TRACKER_GLOBAL_HOOK_ #undef TRACKER_HOOK_
#define Tracker(Container, Type) Container##Tracker<Type> #define Tracker(Container, Type) Container##Tracker<Type>
#define TrackerCast(x) x.cast() #define TrackerCast(x) x.cast()

View file

@ -1,109 +1,109 @@
template<typename T>
class TRACKER_NAME__
template<typename TrackedType>
class TRACKER_NAME_
{ {
public: public:
TrackedType TrackedValue; T value;
inline TrackedType* operator & () inline T *operator&()
{ {
TRACKER_GLOBAL_HOOK_((uintptr_t)&this->TrackedValue); TRACKER_HOOK_((uintptr_t) & this->value);
return &this->TrackedValue; return &this->value;
} }
inline TrackedType operator ++ () inline T operator++()
{ {
TRACKER_GLOBAL_HOOK_((uintptr_t)&this->TrackedValue); TRACKER_HOOK_((uintptr_t) & this->value);
return ++this->TrackedValue; return ++this->value;
} }
inline TrackedType operator ++ (int) inline T operator++(int)
{ {
TRACKER_GLOBAL_HOOK_((uintptr_t)&this->TrackedValue); TRACKER_HOOK_((uintptr_t) & this->value);
return this->TrackedValue++; return this->value++;
} }
inline TrackedType operator -- () inline T operator--()
{ {
TRACKER_GLOBAL_HOOK_((uintptr_t)&this->TrackedValue); TRACKER_HOOK_((uintptr_t) & this->value);
return --this->TrackedValue; return --this->value;
} }
inline TrackedType operator -- (int) inline T operator--(int)
{ {
TRACKER_GLOBAL_HOOK_((uintptr_t)&this->TrackedValue); TRACKER_HOOK_((uintptr_t) & this->value);
return this->TrackedValue--; return this->value--;
} }
template <typename RightHandType> template <typename Tt> inline T operator=(Tt operand)
inline TrackedType operator = (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value = (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator+=(Tt operand)
inline TrackedType operator += (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value += (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator-=(Tt operand)
inline TrackedType operator -= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value -= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator*=(Tt operand)
inline TrackedType operator *= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value *= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator/=(Tt operand)
inline TrackedType operator /= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value /= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator|=(Tt operand)
inline TrackedType operator |= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value |= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator&=(Tt operand)
inline TrackedType operator &= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value &= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator^=(Tt operand)
inline TrackedType operator ^= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value ^= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator<<=(Tt operand)
inline TrackedType operator <<= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value <<= (T)operand;
}
template <typename RightHandType> template <typename Tt> inline T operator>>=(Tt operand)
inline TrackedType operator >>= (RightHandType); {
TRACKER_HOOK_((uintptr_t) & this->value);
return this->value >>= (T)operand;
}
inline operator TrackedType() const; inline operator T() const { return this->value; }
inline TrackedType cast() const; inline T cast() const { return this->value; }
};
struct is_signed
#ifndef tracker_hpp_ {
#define tracker_hpp_ static constexpr bool value = std::is_signed<T>::value;
};
enum { struct is_unsigned
TRACKER_NOOP_RIGHTHAND_EQUAL_ = 0, {
TRACKER_NOOP_RIGHTHAND_ZERO_, static constexpr bool value = std::is_unsigned<T>::value;
TRACKER_NOOP_RIGHTHAND_ONE_, };
__TRACKER_NEVER,
};
#endif
#include "tracker_operators.hpp"
template<typename TrackedType>
inline TRACKER_NAME_<TrackedType>::operator TrackedType() const
{
return this->TrackedValue;
}
template<typename TrackedType>
inline TrackedType TRACKER_NAME_<TrackedType>::cast() const
{
return this->TrackedValue;
}
template <typename TrackedType>
struct is_signed<TRACKER_NAME_<TrackedType>>
{
static constexpr bool value = std::is_signed<TrackedType>::value;
};
template <typename TrackedType>
struct is_unsigned<TRACKER_NAME_<TrackedType>>
{
static constexpr bool value = std::is_unsigned<TrackedType>::value;
}; };

View file

@ -1,25 +0,0 @@
template <typename TrackedType>
template <typename RightHandType>
inline TrackedType TRACKER_NAME_<TrackedType>::operator TRACKER_OPERATOR_ (RightHandType rightHand)
{
bool isNoop = false;
switch (TRACKER_NOOP_)
{
case TRACKER_NOOP_RIGHTHAND_EQUAL_: isNoop = (this->TrackedValue == (TrackedType)rightHand); break;
case TRACKER_NOOP_RIGHTHAND_ZERO_: isNoop = (rightHand == 0); break;
case TRACKER_NOOP_RIGHTHAND_ONE_: isNoop = (rightHand == 1);
fallthrough__;
// case __TRACKER_NEVER:
default:
break;
}
if (!isNoop)
{
TRACKER_GLOBAL_HOOK_((uintptr_t) & this->TrackedValue);
return this->TrackedValue TRACKER_OPERATOR_ (TrackedType)rightHand;
}
else return this->TrackedValue;
}

View file

@ -1,59 +0,0 @@
#define TRACKER_OPERATOR_ =
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_EQUAL_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ +=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ZERO_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ -=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ZERO_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ *=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ONE_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ /=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ONE_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ |=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ZERO_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ &=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_EQUAL_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ ^=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ZERO_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ <<=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ZERO_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_
#define TRACKER_OPERATOR_ >>=
#define TRACKER_NOOP_ TRACKER_NOOP_RIGHTHAND_ZERO_
#include "tracker_operator.hpp"
#undef TRACKER_OPERATOR_
#undef TRACKER_NOOP_