1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Merge pull request #16570 from ZehMatt/refactor/constexpr-trackdata

Initialize track data table at compile time
This commit is contained in:
ζeh Matt
2022-02-03 11:23:07 -08:00
committed by GitHub
3 changed files with 9 additions and 8 deletions

View File

@@ -416,7 +416,6 @@ namespace OpenRCT2
}
_env->SetBasePath(DIRBASE::RCT2, rct2InstallPath);
}
TrackMetaData::Init();
_objectRepository = CreateObjectRepository(_env);
_objectManager = CreateObjectManager(*_objectRepository);

View File

@@ -5702,15 +5702,13 @@ namespace OpenRCT2
{
namespace TrackMetaData
{
static std::vector<TrackElementDescriptor> _trackElementDescriptors;
void Init()
static constexpr auto BuildDescriptorTable()
{
_trackElementDescriptors.clear();
_trackElementDescriptors.reserve(TrackElemType::Count);
std::array<TrackElementDescriptor, TrackElemType::Count> res{};
TrackElementDescriptor desc;
for (int i = 0; i < TrackElemType::Count; i++)
{
TrackElementDescriptor& desc = res[i];
desc.Description = RideConfigurationStringIds[i];
desc.AlternativeType = AlternativeTrackTypes[i];
desc.Block = const_cast<rct_preview_track*>(TrackBlocks[i]);
@@ -5729,12 +5727,17 @@ namespace OpenRCT2
desc.SequenceElementAllowedWallEdges[j] = TrackSequenceElementAllowedWallEdges[i][j];
desc.SequenceProperties[j] = TrackSequenceProperties[i][j];
}
_trackElementDescriptors.push_back(desc);
}
return res;
}
static constexpr auto _trackElementDescriptors = BuildDescriptorTable();
const TrackElementDescriptor& GetTrackElementDescriptor(const uint32_t type)
{
return _trackElementDescriptors[type];
}
} // namespace TrackMetaData
} // namespace OpenRCT2

View File

@@ -97,7 +97,6 @@ namespace OpenRCT2
{
namespace TrackMetaData
{
void Init();
const TrackElementDescriptor& GetTrackElementDescriptor(const uint32_t type);
} // namespace TrackMetaData
} // namespace OpenRCT2