mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 06:52:05 +01:00
Codechange: Use attribute syntax for debug_inline, so clang-format understands it.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
* @return The selected bits, aligned to a LSB.
|
||||
*/
|
||||
template <typename T>
|
||||
debug_inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
|
||||
[[debug_inline]] inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
|
||||
{
|
||||
return (x >> s) & (((T)1U << n) - 1);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ constexpr T AB(T &x, const uint8_t s, const uint8_t n, const U i)
|
||||
* @return True if the bit is set, false else.
|
||||
*/
|
||||
template <typename T>
|
||||
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
|
||||
[[debug_inline]] inline constexpr bool HasBit(const T x, const uint8_t y)
|
||||
{
|
||||
return (x & ((T)1U << y)) != 0;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ inline constexpr auto operator-(enum_type a, enum_type b)
|
||||
* @return True iff the flag is set.
|
||||
*/
|
||||
template <typename T, class = typename std::enable_if_t<std::is_enum_v<T>>>
|
||||
debug_inline constexpr bool HasFlag(const T x, const T y)
|
||||
[[debug_inline]] inline constexpr bool HasFlag(const T x, const T y)
|
||||
{
|
||||
return (x & y) == y;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ debug_inline constexpr bool HasFlag(const T x, const T y)
|
||||
* @param y The flag to toggle.
|
||||
*/
|
||||
template <typename T, class = typename std::enable_if_t<std::is_enum_v<T>>>
|
||||
debug_inline constexpr void ToggleFlag(T &x, const T y)
|
||||
[[debug_inline]] inline constexpr void ToggleFlag(T &x, const T y)
|
||||
{
|
||||
if (HasFlag(x, y)) {
|
||||
x &= ~y;
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
* Create the tile wrapper for the given tile.
|
||||
* @param tile The tile to access the map for.
|
||||
*/
|
||||
debug_inline Tile(TileIndex tile) : tile(tile) {}
|
||||
[[debug_inline]] inline Tile(TileIndex tile) : tile(tile) {}
|
||||
|
||||
/**
|
||||
* Create the tile wrapper for the given tile.
|
||||
@@ -72,12 +72,12 @@ public:
|
||||
/**
|
||||
* Implicit conversion to the TileIndex.
|
||||
*/
|
||||
debug_inline constexpr operator TileIndex() const { return this->tile; }
|
||||
[[debug_inline]] inline constexpr operator TileIndex() const { return this->tile; }
|
||||
|
||||
/**
|
||||
* Implicit conversion to the uint for bounds checking.
|
||||
*/
|
||||
debug_inline constexpr operator uint() const { return this->tile.base(); }
|
||||
[[debug_inline]] inline constexpr operator uint() const { return this->tile.base(); }
|
||||
|
||||
/**
|
||||
* The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &type()
|
||||
[[debug_inline]] inline uint8_t &type()
|
||||
{
|
||||
return base_tiles[this->tile.base()].type;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
* @param tile The tile to get the height for.
|
||||
* @return reference to the byte holding the height.
|
||||
*/
|
||||
debug_inline uint8_t &height()
|
||||
[[debug_inline]] inline uint8_t &height()
|
||||
{
|
||||
return base_tiles[this->tile.base()].height;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &m1()
|
||||
[[debug_inline]] inline uint8_t &m1()
|
||||
{
|
||||
return base_tiles[this->tile.base()].m1;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the uint16_t holding the data.
|
||||
*/
|
||||
debug_inline uint16_t &m2()
|
||||
[[debug_inline]] inline uint16_t &m2()
|
||||
{
|
||||
return base_tiles[this->tile.base()].m2;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &m3()
|
||||
[[debug_inline]] inline uint8_t &m3()
|
||||
{
|
||||
return base_tiles[this->tile.base()].m3;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &m4()
|
||||
[[debug_inline]] inline uint8_t &m4()
|
||||
{
|
||||
return base_tiles[this->tile.base()].m4;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &m5()
|
||||
[[debug_inline]] inline uint8_t &m5()
|
||||
{
|
||||
return base_tiles[this->tile.base()].m5;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &m6()
|
||||
[[debug_inline]] inline uint8_t &m6()
|
||||
{
|
||||
return extended_tiles[this->tile.base()].m6;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the byte holding the data.
|
||||
*/
|
||||
debug_inline uint8_t &m7()
|
||||
[[debug_inline]] inline uint8_t &m7()
|
||||
{
|
||||
return extended_tiles[this->tile.base()].m7;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ public:
|
||||
* @param tile The tile to get the data for.
|
||||
* @return reference to the uint16_t holding the data.
|
||||
*/
|
||||
debug_inline uint16_t &m8()
|
||||
[[debug_inline]] inline uint16_t &m8()
|
||||
{
|
||||
return extended_tiles[this->tile.base()].m8;
|
||||
}
|
||||
@@ -250,7 +250,7 @@ public:
|
||||
* @note try to avoid using this one
|
||||
* @return 2^"return value" == Map::SizeX()
|
||||
*/
|
||||
debug_inline static uint LogX()
|
||||
[[debug_inline]] inline static uint LogX()
|
||||
{
|
||||
return Map::log_x;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public:
|
||||
* Get the size of the map along the X
|
||||
* @return the number of tiles along the X of the map
|
||||
*/
|
||||
debug_inline static uint SizeX()
|
||||
[[debug_inline]] inline static uint SizeX()
|
||||
{
|
||||
return Map::size_x;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
* Get the size of the map
|
||||
* @return the number of tiles of the map
|
||||
*/
|
||||
debug_inline static uint Size()
|
||||
[[debug_inline]] inline static uint Size()
|
||||
{
|
||||
return Map::size;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ public:
|
||||
* Gets the maximum X coordinate within the map, including MP_VOID
|
||||
* @return the maximum X coordinate
|
||||
*/
|
||||
debug_inline static uint MaxX()
|
||||
[[debug_inline]] inline static uint MaxX()
|
||||
{
|
||||
return Map::SizeX() - 1;
|
||||
}
|
||||
@@ -382,7 +382,7 @@ public:
|
||||
* @param y The y coordinate of the tile
|
||||
* @return The TileIndex calculated by the coordinate
|
||||
*/
|
||||
debug_inline static TileIndex TileXY(uint x, uint y)
|
||||
[[debug_inline]] inline static TileIndex TileXY(uint x, uint y)
|
||||
{
|
||||
return TileIndex{(y << Map::LogX()) + x};
|
||||
}
|
||||
@@ -413,7 +413,7 @@ inline TileIndexDiff TileDiffXY(int x, int y)
|
||||
* @param y The virtual y coordinate of the tile.
|
||||
* @return The TileIndex calculated by the coordinate.
|
||||
*/
|
||||
debug_inline static TileIndex TileVirtXY(uint x, uint y)
|
||||
[[debug_inline]] inline static TileIndex TileVirtXY(uint x, uint y)
|
||||
{
|
||||
return TileIndex{(y >> 4 << Map::LogX()) + (x >> 4)};
|
||||
}
|
||||
@@ -424,7 +424,7 @@ debug_inline static TileIndex TileVirtXY(uint x, uint y)
|
||||
* @param tile the tile to get the X component of
|
||||
* @return the X component
|
||||
*/
|
||||
debug_inline static uint TileX(TileIndex tile)
|
||||
[[debug_inline]] inline static uint TileX(TileIndex tile)
|
||||
{
|
||||
return tile.base() & Map::MaxX();
|
||||
}
|
||||
@@ -434,7 +434,7 @@ debug_inline static uint TileX(TileIndex tile)
|
||||
* @param tile the tile to get the Y component of
|
||||
* @return the Y component
|
||||
*/
|
||||
debug_inline static uint TileY(TileIndex tile)
|
||||
[[debug_inline]] inline static uint TileY(TileIndex tile)
|
||||
{
|
||||
return tile.base() >> Map::LogX();
|
||||
}
|
||||
|
||||
@@ -87,11 +87,11 @@ struct CFollowTrackT {
|
||||
this->railtypes = railtype_override;
|
||||
}
|
||||
|
||||
debug_inline static TransportType TT() { return Ttr_type_; }
|
||||
debug_inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; }
|
||||
debug_inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; }
|
||||
[[debug_inline]] inline static TransportType TT() { return Ttr_type_; }
|
||||
[[debug_inline]] inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; }
|
||||
[[debug_inline]] inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; }
|
||||
inline bool IsTram() { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(this->veh)->roadtype); }
|
||||
debug_inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; }
|
||||
[[debug_inline]] inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; }
|
||||
static inline bool Allow90degTurns() { return T90deg_turns_allowed_; }
|
||||
static inline bool DoTrackMasking() { return Tmask_reserved_tracks; }
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ enum class RailTileType : uint8_t {
|
||||
* @pre IsTileType(t, MP_RAILWAY)
|
||||
* @return the RailTileType
|
||||
*/
|
||||
debug_inline static RailTileType GetRailTileType(Tile t)
|
||||
[[debug_inline]] inline static RailTileType GetRailTileType(Tile t)
|
||||
{
|
||||
assert(IsTileType(t, MP_RAILWAY));
|
||||
return static_cast<RailTileType>(GB(t.m5(), 6, 2));
|
||||
@@ -46,7 +46,7 @@ debug_inline static RailTileType GetRailTileType(Tile t)
|
||||
* @pre IsTileType(t, MP_RAILWAY)
|
||||
* @return true if and only if the tile is normal rail (with or without signals)
|
||||
*/
|
||||
debug_inline static bool IsPlainRail(Tile t)
|
||||
[[debug_inline]] inline static bool IsPlainRail(Tile t)
|
||||
{
|
||||
RailTileType rtt = GetRailTileType(t);
|
||||
return rtt == RailTileType::Normal || rtt == RailTileType::Signals;
|
||||
@@ -57,7 +57,7 @@ debug_inline static bool IsPlainRail(Tile t)
|
||||
* @param t the tile to get the information from
|
||||
* @return true if and only if the tile is normal rail (with or without signals)
|
||||
*/
|
||||
debug_inline static bool IsPlainRailTile(Tile t)
|
||||
[[debug_inline]] inline static bool IsPlainRailTile(Tile t)
|
||||
{
|
||||
return IsTileType(t, MP_RAILWAY) && IsPlainRail(t);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ inline void SetHasSignals(Tile tile, bool signals)
|
||||
* @pre IsTileType(t, MP_RAILWAY)
|
||||
* @return true if and only if the tile is a rail depot
|
||||
*/
|
||||
debug_inline static bool IsRailDepot(Tile t)
|
||||
[[debug_inline]] inline static bool IsRailDepot(Tile t)
|
||||
{
|
||||
return GetRailTileType(t) == RailTileType::Depot;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ debug_inline static bool IsRailDepot(Tile t)
|
||||
* @param t the tile to get the information from
|
||||
* @return true if and only if the tile is a rail depot
|
||||
*/
|
||||
debug_inline static bool IsRailDepotTile(Tile t)
|
||||
[[debug_inline]] inline static bool IsRailDepotTile(Tile t)
|
||||
{
|
||||
return IsTileType(t, MP_RAILWAY) && IsRailDepot(t);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ bool MayHaveRoad(Tile t);
|
||||
* @pre IsTileType(t, MP_ROAD)
|
||||
* @return The road tile type.
|
||||
*/
|
||||
debug_inline static RoadTileType GetRoadTileType(Tile t)
|
||||
[[debug_inline]] inline static RoadTileType GetRoadTileType(Tile t)
|
||||
{
|
||||
assert(IsTileType(t, MP_ROAD));
|
||||
return static_cast<RoadTileType>(GB(t.m5(), 6, 2));
|
||||
@@ -45,7 +45,7 @@ debug_inline static RoadTileType GetRoadTileType(Tile t)
|
||||
* @pre IsTileType(t, MP_ROAD)
|
||||
* @return True if normal road.
|
||||
*/
|
||||
debug_inline static bool IsNormalRoad(Tile t)
|
||||
[[debug_inline]] inline static bool IsNormalRoad(Tile t)
|
||||
{
|
||||
return GetRoadTileType(t) == RoadTileType::Normal;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ debug_inline static bool IsNormalRoad(Tile t)
|
||||
* @param t Tile to query.
|
||||
* @return True if normal road tile.
|
||||
*/
|
||||
debug_inline static bool IsNormalRoadTile(Tile t)
|
||||
[[debug_inline]] inline static bool IsNormalRoadTile(Tile t)
|
||||
{
|
||||
return IsTileType(t, MP_ROAD) && IsNormalRoad(t);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ inline bool IsLevelCrossingTile(Tile t)
|
||||
* @pre IsTileType(t, MP_ROAD)
|
||||
* @return True if road depot.
|
||||
*/
|
||||
debug_inline static bool IsRoadDepot(Tile t)
|
||||
[[debug_inline]] inline static bool IsRoadDepot(Tile t)
|
||||
{
|
||||
return GetRoadTileType(t) == RoadTileType::Depot;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ debug_inline static bool IsRoadDepot(Tile t)
|
||||
* @param t Tile to query.
|
||||
* @return True if road depot tile.
|
||||
*/
|
||||
debug_inline static bool IsRoadDepotTile(Tile t)
|
||||
[[debug_inline]] inline static bool IsRoadDepotTile(Tile t)
|
||||
{
|
||||
return IsTileType(t, MP_ROAD) && IsRoadDepot(t);
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ struct GoodsEntry {
|
||||
* Test if this goods entry has optional cargo packet/flow data.
|
||||
* @returns true iff optional data is present.
|
||||
*/
|
||||
debug_inline bool HasData() const { return this->data != nullptr; }
|
||||
[[debug_inline]] inline bool HasData() const { return this->data != nullptr; }
|
||||
|
||||
/**
|
||||
* Clear optional cargo packet/flow data.
|
||||
@@ -314,7 +314,7 @@ struct GoodsEntry {
|
||||
* @pre HasData()
|
||||
* @returns cargo packet/flow data.
|
||||
*/
|
||||
debug_inline const GoodsEntryData &GetData() const
|
||||
[[debug_inline]] inline const GoodsEntryData &GetData() const
|
||||
{
|
||||
assert(this->HasData());
|
||||
return *this->data;
|
||||
@@ -325,7 +325,7 @@ struct GoodsEntry {
|
||||
* @pre HasData()
|
||||
* @returns non-const cargo packet/flow data.
|
||||
*/
|
||||
debug_inline GoodsEntryData &GetData()
|
||||
[[debug_inline]] inline GoodsEntryData &GetData()
|
||||
{
|
||||
assert(this->HasData());
|
||||
return *this->data;
|
||||
|
||||
10
src/stdafx.h
10
src/stdafx.h
@@ -203,7 +203,7 @@ using namespace std::literals::string_view_literals;
|
||||
* inlining. However, the performance benefit can be enormous; when forcing
|
||||
* inlining for the previously mentioned top 5, the debug build ran about 15%
|
||||
* quicker.
|
||||
* The following debug_inline annotation may be added to functions comply
|
||||
* The following debug_inline attribute may be added to functions comply
|
||||
* with the following preconditions:
|
||||
* 1: the function takes more than 0.5% of a profiled debug runtime
|
||||
* 2: the function does not modify the game state
|
||||
@@ -211,7 +211,7 @@ using namespace std::literals::string_view_literals;
|
||||
* i.e. no if, switch, for, do, while, etcetera.
|
||||
* 4: the function is one line of code, excluding assertions.
|
||||
* 5: the function is defined in a header file.
|
||||
* The debug_inline annotation must be placed in front of the function, i.e.
|
||||
* The debug_inline attribute must be placed in front of the function, i.e.
|
||||
* before the optional static or constexpr modifier.
|
||||
*/
|
||||
#if !defined(_DEBUG) || defined(NO_DEBUG_INLINE)
|
||||
@@ -219,16 +219,16 @@ using namespace std::literals::string_view_literals;
|
||||
* Do not force inlining when not in debug. This way we do not work against
|
||||
* any carefully designed compiler optimizations.
|
||||
*/
|
||||
#define debug_inline inline
|
||||
#define debug_inline
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
#define debug_inline [[gnu::always_inline]] inline
|
||||
#define debug_inline gnu::always_inline
|
||||
#else
|
||||
/*
|
||||
* MSVC explicitly disables inlining, even forced inlining, in debug builds
|
||||
* so __forceinline makes no difference compared to inline. Other unknown
|
||||
* compilers can also just fallback to a normal inline.
|
||||
*/
|
||||
#define debug_inline inline
|
||||
#define debug_inline
|
||||
#endif
|
||||
|
||||
/* This is already defined in unix, but not in QNX Neutrino (6.x) or Cygwin. */
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* @return the height of the tile
|
||||
* @pre tile < Map::Size()
|
||||
*/
|
||||
debug_inline static uint TileHeight(Tile tile)
|
||||
[[debug_inline]] inline static uint TileHeight(Tile tile)
|
||||
{
|
||||
assert(tile < Map::Size());
|
||||
return tile.height();
|
||||
@@ -93,7 +93,7 @@ inline uint TilePixelHeightOutsideMap(int x, int y)
|
||||
* @return The tiletype of the tile
|
||||
* @pre tile < Map::Size()
|
||||
*/
|
||||
debug_inline static TileType GetTileType(Tile tile)
|
||||
[[debug_inline]] inline static TileType GetTileType(Tile tile)
|
||||
{
|
||||
assert(tile < Map::Size());
|
||||
return (TileType)GB(tile.type(), 4, 4);
|
||||
@@ -147,7 +147,7 @@ inline void SetTileType(Tile tile, TileType type)
|
||||
* @param type The type to check against
|
||||
* @return true If the type matches against the type of the tile
|
||||
*/
|
||||
debug_inline static bool IsTileType(Tile tile, TileType type)
|
||||
[[debug_inline]] inline static bool IsTileType(Tile tile, TileType type)
|
||||
{
|
||||
return GetTileType(tile) == type;
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ public:
|
||||
* Check if the vehicle is a ground vehicle.
|
||||
* @return True iff the vehicle is a train or a road vehicle.
|
||||
*/
|
||||
debug_inline bool IsGroundVehicle() const
|
||||
[[debug_inline]] inline bool IsGroundVehicle() const
|
||||
{
|
||||
return this->type == VEH_TRAIN || this->type == VEH_ROAD;
|
||||
}
|
||||
@@ -910,7 +910,7 @@ public:
|
||||
* Check if the vehicle is a front engine.
|
||||
* @return Returns true if the vehicle is a front engine.
|
||||
*/
|
||||
debug_inline bool IsFrontEngine() const
|
||||
[[debug_inline]] inline bool IsFrontEngine() const
|
||||
{
|
||||
return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user