Browse Source

Make `IsWall` easier for the compiler to inline

This appears to be a very hot function.
Makes it fully inlineable (even in Debug mode).
pull/6629/head
Gleb Mazovetskiy 3 years ago
parent
commit
e5c426c315
  1. 2
      Source/engine/render/scrollrt.cpp
  2. 7
      Source/levels/gendung.cpp
  3. 8
      Source/levels/gendung.h
  4. 28
      Source/utils/enum_traits.h

2
Source/engine/render/scrollrt.cpp

@ -843,7 +843,7 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio
}
}
bool IsWall(Point position)
[[nodiscard]] DVL_ALWAYS_INLINE bool IsWall(Point position)
{
return TileHasAny(dPiece[position.x][position.y], TileProperties::Solid) || dSpecial[position.x][position.y] != 0;
}

7
Source/levels/gendung.cpp

@ -27,7 +27,7 @@ std::unique_ptr<uint16_t[]> pSetPiece;
OptionalOwnedClxSpriteList pSpecialCels;
std::unique_ptr<MegaTile[]> pMegaTiles;
std::unique_ptr<std::byte[]> pDungeonCels;
std::array<TileProperties, MAXTILES> SOLData;
TileProperties SOLData[MAXTILES];
WorldTilePosition dminPosition;
WorldTilePosition dmaxPosition;
dungeon_type leveltype;
@ -417,11 +417,6 @@ void CreateDungeon(uint32_t rseed, lvl_entry entry)
Make_SetPC(SetPiece);
}
bool TileHasAny(int tileId, TileProperties property)
{
return HasAnyOf(SOLData[tileId], property);
}
void LoadLevelSOLData()
{
switch (leveltype) {

8
Source/levels/gendung.h

@ -167,7 +167,7 @@ extern std::unique_ptr<std::byte[]> pDungeonCels;
/**
* List tile properties
*/
extern DVL_API_FOR_TEST std::array<TileProperties, MAXTILES> SOLData;
extern DVL_API_FOR_TEST TileProperties SOLData[MAXTILES];
/** Specifies the minimum X,Y-coordinates of the map. */
extern WorldTilePosition dminPosition;
/** Specifies the maximum X,Y-coordinates of the map. */
@ -334,7 +334,11 @@ struct Miniset {
}
};
bool TileHasAny(int tileId, TileProperties property);
[[nodiscard]] DVL_ALWAYS_INLINE bool TileHasAny(int tileId, TileProperties property)
{
return HasAnyOf(SOLData[tileId], property);
}
void LoadLevelSOLData();
void SetDungeonMicros();
void DRLG_InitTrans();

28
Source/utils/enum_traits.h

@ -8,6 +8,8 @@
#include <cstddef>
#include <type_traits>
#include "utils/attributes.h"
namespace devilution {
template <typename T>
@ -27,17 +29,17 @@ public:
{
}
const T operator*() const
[[nodiscard]] DVL_ALWAYS_INLINE const T operator*() const
{
return static_cast<T>(m_value);
}
void operator++()
DVL_ALWAYS_INLINE void operator++()
{
m_value++;
}
bool operator!=(Iterator rhs) const
[[nodiscard]] DVL_ALWAYS_INLINE bool operator!=(Iterator rhs) const
{
return m_value != rhs.m_value;
}
@ -45,13 +47,13 @@ public:
};
template <typename T>
typename enum_values<T>::Iterator begin(enum_values<T>)
[[nodiscard]] DVL_ALWAYS_INLINE typename enum_values<T>::Iterator begin(enum_values<T>)
{
return typename enum_values<T>::Iterator(static_cast<typename std::underlying_type<T>::type>(T::FIRST));
}
template <typename T>
typename enum_values<T>::Iterator end(enum_values<T>)
[[nodiscard]] DVL_ALWAYS_INLINE typename enum_values<T>::Iterator end(enum_values<T>)
{
return typename enum_values<T>::Iterator(static_cast<typename std::underlying_type<T>::type>(T::LAST) + 1);
}
@ -66,54 +68,54 @@ struct is_flags_enum : std::false_type {
};
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr EnumType operator|(EnumType lhs, EnumType rhs)
[[nodiscard]] DVL_ALWAYS_INLINE constexpr EnumType operator|(EnumType lhs, EnumType rhs)
{
using T = std::underlying_type_t<EnumType>;
return static_cast<EnumType>(static_cast<T>(lhs) | static_cast<T>(rhs));
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr EnumType operator|=(EnumType &lhs, EnumType rhs)
DVL_ALWAYS_INLINE constexpr EnumType operator|=(EnumType &lhs, EnumType rhs)
{
lhs = lhs | rhs;
return lhs;
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr EnumType operator&(EnumType lhs, EnumType rhs)
[[nodiscard]] DVL_ALWAYS_INLINE constexpr EnumType operator&(EnumType lhs, EnumType rhs)
{
using T = std::underlying_type_t<EnumType>;
return static_cast<EnumType>(static_cast<T>(lhs) & static_cast<T>(rhs));
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr EnumType operator&=(EnumType &lhs, EnumType rhs)
DVL_ALWAYS_INLINE constexpr EnumType operator&=(EnumType &lhs, EnumType rhs)
{
lhs = lhs & rhs;
return lhs;
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr EnumType operator~(EnumType value)
[[nodiscard]] DVL_ALWAYS_INLINE constexpr EnumType operator~(EnumType value)
{
using T = std::underlying_type_t<EnumType>;
return static_cast<EnumType>(~static_cast<T>(value));
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr bool HasAnyOf(EnumType lhs, EnumType test)
[[nodiscard]] DVL_ALWAYS_INLINE constexpr bool HasAnyOf(EnumType lhs, EnumType test)
{
return (lhs & test) != static_cast<EnumType>(0); // Some flags enums may not use a None value outside this check so we don't require an EnumType::None definition here.
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr bool HasAllOf(EnumType lhs, EnumType test)
[[nodiscard]] DVL_ALWAYS_INLINE constexpr bool HasAllOf(EnumType lhs, EnumType test)
{
return (lhs & test) == test;
}
template <typename EnumType, std::enable_if_t<std::is_enum<EnumType>::value && is_flags_enum<EnumType>::value, bool> = true>
constexpr bool HasNoneOf(EnumType lhs, EnumType test)
[[nodiscard]] DVL_ALWAYS_INLINE constexpr bool HasNoneOf(EnumType lhs, EnumType test)
{
return !HasAnyOf(lhs, test);
}

Loading…
Cancel
Save