OpenTTD Source 20260311-master-g511d3794ce
stdafx.h File Reference

Definition of base types and functions in a cross-platform compatible way. More...

#include <stdint.h>
#include <algorithm>
#include <array>
#include <bit>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cwchar>
#include <deque>
#include <exception>
#include <functional>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <set>
#include <source_location>
#include <span>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <variant>
#include <vector>

Go to the source code of this file.

Macros

#define __STDC_LIMIT_MACROS
#define EMPTY_BASES
#define PATHSEP   "/"
#define PATHSEPCHAR   '/'
#define PACK_N(type_dec, n)
#define PACK(type_dec)
#define debug_inline
 When making a (pure) debug build, the compiler will by default disable inlining of functions.
#define PERSONAL_DIR   ""
#define M_PI_2   1.57079632679489661923
#define M_PI   3.14159265358979323846
#define lengthof(array)
 Return the length of an fixed size array.
#define GNU_TARGET(x)
#define JSON_ASSERT(x)
#define MAX_PATH   260

Typedefs

typedef unsigned int uint

Functions

static std::string FS2OTTD (std::string_view name)
static std::string OTTD2FS (std::string_view name)
template<typename T, size_t N>
char(& ArraySizeHelper (T(&array)[N]))[N]
void NOT_REACHED (const std::source_location location=std::source_location::current())
void AssertFailedError (std::string_view expression, const std::source_location location=std::source_location::current())

Detailed Description

Definition of base types and functions in a cross-platform compatible way.

Definition in file stdafx.h.

Macro Definition Documentation

◆ __STDC_LIMIT_MACROS

#define __STDC_LIMIT_MACROS

Definition at line 32 of file stdafx.h.

◆ debug_inline

#define debug_inline

When making a (pure) debug build, the compiler will by default disable inlining of functions.

This has a detrimental effect on the performance of debug builds, especially when more and more trivial (wrapper) functions get added to the code base. Take for example the savegame called "Wentbourne", when running this game for 100 ticks with the null video driver a number of fairly trivial functions show up on top. The most common one is the implicit conversion operator of TileIndex to unsigned int, which takes up over 5% of the total run time and functionally does absolutely nothing. The remaining functions for the top 5 are GB, GetTileType, Map::Size and IsTileType to a total of about 12.5% of the game's total run time. It is possible to still force inlining in the most commonly used compilers, but that is at the cost of some problems with debugging due to the forced 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 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 3: the function does not contain selection or iteration statements, 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 attribute must be placed in front of the function, i.e. before the optional static or constexpr modifier.

Definition at line 222 of file stdafx.h.

Referenced by GB(), GoodsEntry::GetData(), GoodsEntry::GetData(), GetRailTileType(), GetRoadTileType(), GetTileType(), HasBit(), GoodsEntry::HasData(), HasFlag(), Tile::height(), Vehicle::IsFrontEngine(), Vehicle::IsGroundVehicle(), IsNormalRoad(), IsNormalRoadTile(), IsPlainRail(), IsPlainRailTile(), IsRailDepot(), IsRailDepotTile(), IsRoadDepot(), IsRoadDepotTile(), IsTileType(), Map::LogX(), Tile::m1(), Tile::m2(), Tile::m3(), Tile::m4(), Tile::m5(), Tile::m6(), Tile::m7(), Tile::m8(), Map::MaxX(), Tile::operator TileIndex(), Tile::operator uint(), Map::Size(), Map::SizeX(), Tile::Tile(), TileHeight(), TileVirtXY(), TileX(), TileXY(), TileY(), ToggleFlag(), and Tile::type().

◆ EMPTY_BASES

#define EMPTY_BASES

Definition at line 95 of file stdafx.h.

◆ GNU_TARGET

#define GNU_TARGET ( x)

Definition at line 284 of file stdafx.h.

◆ JSON_ASSERT

#define JSON_ASSERT ( x)
Value:
assert(x)

Definition at line 298 of file stdafx.h.

◆ lengthof

#define lengthof ( array)
Value:
(sizeof(ArraySizeHelper(array)))

Return the length of an fixed size array.

Unlike sizeof this function returns the number of elements of the given type.

Parameters
arrayThe pointer to the first element of the array
Returns
The number of elements

Definition at line 271 of file stdafx.h.

Referenced by AddAcceptedCargoOfHouse(), AddGenericCallback(), AppendFile(), BuildLandLegend(), BuildLinkStatsLegend(), BulldozerTick(), CmdFoundTown(), CargoesRow::ConnectIndustryAccepted(), DetermineBasePaths(), DrawBridgeRoadBits(), LinkGraphOverlay::DrawContent(), DrawTile_Trees(), ExtractTar(), FillNewGRFVehicleCache(), FinaliseHouseArray(), CoreTextFontCacheFactory::FindFallbackFont(), FixTTOEngines(), FormatBytes(), FormatString(), FreeTerminal(), AirportSpec::Get(), AirportTileSpec::Get(), CargoSpec::Get(), GetAllCargoSuffixes(), CargoSpec::GetArraySize(), GetBridgeSpec(), NWidgetMainToolbarContainer::GetButtonArrangement(), NWidgetScenarioToolbarContainer::GetButtonArrangement(), GetFileTitle(), GetMaxTreeSpriteSize(), GetNewgrfCurrencyIdConverted(), GetNumberOfIndustries(), GetTextfile(), GetVelocityUnits(), NetworkChatWindow::GetWidgetString(), AirportSpec::GetWithoutOverride(), StringReader::HandlePragma(), IndustryCargoesWindow::HousesCanAccept(), IndustriesChangeInfo(), OpenGLBackend::InitShaders(), SmallSet< Tdir, items >::IsFull(), Vehicle::LoadOldVehicle, MakeHeightmapScreenshot(), MakePerformanceDetailPanels(), MidiGetStandardSysexMessage(), NetworkGameLoop(), NetworkServerShowStatusToConsole(), SmallMapWindow::OnInit(), OutputContentState(), ResetObjects(), RunTileLoop(), SmallMapWindow::SetZoomLevel(), CrashLogOSX::SurveyStacktrace(), CrashLogUnix::SurveyStacktrace(), and TownHouseChangeInfo().

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 257 of file stdafx.h.

◆ M_PI_2

#define M_PI_2   1.57079632679489661923

Definition at line 256 of file stdafx.h.

◆ MAX_PATH

#define MAX_PATH   260

Definition at line 307 of file stdafx.h.

◆ PACK

#define PACK ( type_dec)
Value:
PACK_N(type_dec, 1)

Definition at line 187 of file stdafx.h.

◆ PACK_N

#define PACK_N ( type_dec,
n )
Value:
type_dec __attribute__((__packed__, aligned(n)))

Definition at line 185 of file stdafx.h.

◆ PATHSEP

#define PATHSEP   "/"

Definition at line 175 of file stdafx.h.

◆ PATHSEPCHAR

#define PATHSEPCHAR   '/'

Definition at line 176 of file stdafx.h.

◆ PERSONAL_DIR

#define PERSONAL_DIR   ""

Definition at line 240 of file stdafx.h.

Typedef Documentation

◆ uint

typedef unsigned int uint

Definition at line 236 of file stdafx.h.

Function Documentation

◆ AssertFailedError()

void AssertFailedError ( std::string_view expression,
const std::source_location location = std::source_location::current() )

Definition at line 19 of file error.cpp.

◆ FS2OTTD()

std::string FS2OTTD ( std::string_view name)
inlinestatic

Definition at line 166 of file stdafx.h.

◆ NOT_REACHED()

void NOT_REACHED ( const std::source_location location = std::source_location::current())

Definition at line 14 of file error.cpp.

◆ OTTD2FS()

std::string OTTD2FS ( std::string_view name)
inlinestatic

Definition at line 167 of file stdafx.h.