1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 21:43:06 +01:00

Merge pull request #24259 from ZehMatt/heterogeneous-opts

This commit is contained in:
Aaron van Geffen
2025-04-21 15:23:20 +02:00
committed by GitHub
10 changed files with 49 additions and 40 deletions

View File

@@ -23,7 +23,7 @@
#include <chrono>
#include <list>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
template<typename TItem>
@@ -210,7 +210,7 @@ private:
return allItems;
}
std::tuple<bool, std::vector<TItem>> ReadIndexFile(int32_t language, const DirectoryStats& stats) const
std::pair<bool, std::vector<TItem>> ReadIndexFile(int32_t language, const DirectoryStats& stats) const
{
bool loadedItems = false;
std::vector<TItem> items;
@@ -251,7 +251,7 @@ private:
OpenRCT2::Console::Error::WriteLine("%s", e.what());
}
}
return std::make_tuple(loadedItems, std::move(items));
return { loadedItems, std::move(items) };
}
void WriteIndexFile(int32_t language, const DirectoryStats& stats, const std::vector<TItem>& items) const

View File

@@ -20,6 +20,7 @@
#include <array>
#include <cstdint>
#include <optional>
#include <sfl/small_vector.hpp>
#include <span>
#include <stack>
#include <type_traits>
@@ -69,7 +70,7 @@ namespace OpenRCT2
IStream* _stream;
Mode _mode;
Header _header;
std::vector<ChunkEntry> _chunks;
sfl::small_vector<ChunkEntry, 32> _chunks;
MemoryStream _buffer;
ChunkEntry _currentChunk;

View File

@@ -172,11 +172,6 @@ namespace OpenRCT2::String
return equalsImpl(a, b, false);
}
bool equals(const u8string& a, const u8string& b)
{
return equalsImpl(a, b, false);
}
bool equals(const utf8* a, const utf8* b, bool ignoreCase)
{
if (a == b)
@@ -197,11 +192,6 @@ namespace OpenRCT2::String
return equalsImpl(a, b, true);
}
bool iequals(const u8string& a, const u8string& b)
{
return equalsImpl(a, b, true);
}
bool iequals(const utf8* a, const utf8* b)
{
if (a == b)

View File

@@ -19,6 +19,24 @@
namespace OpenRCT2::String
{
struct Hash
{
using is_transparent = void;
size_t operator()(const char* txt) const
{
return std::hash<std::string_view>{}(txt);
}
size_t operator()(std::string_view txt) const
{
return std::hash<std::string_view>{}(txt);
}
size_t operator()(const std::string& txt) const
{
return std::hash<std::string>{}(txt);
}
};
std::string toStd(const utf8* str);
std::string toUtf8(std::wstring_view src);
std::wstring toWideChar(std::string_view src);
@@ -34,10 +52,8 @@ namespace OpenRCT2::String
int32_t compare(const utf8* a, const utf8* b, bool ignoreCase = false);
bool equals(u8string_view a, u8string_view b);
bool equals(const u8string& a, const u8string& b);
bool equals(const utf8* a, const utf8* b, bool ignoreCase = false);
bool iequals(u8string_view a, u8string_view b);
bool iequals(const u8string& a, const u8string& b);
bool iequals(const utf8* a, const utf8* b);
bool startsWith(std::string_view str, std::string_view match, bool ignoreCase = false);

View File

@@ -227,9 +227,9 @@ namespace OpenRCT2::ObjectFactory
static std::unique_ptr<Object> CreateObjectFromJson(
IObjectRepository& objectRepository, json_t& jRoot, const IFileDataRetriever* fileRetriever, bool loadImageTable);
static ObjectSourceGame ParseSourceGame(const std::string& s)
static ObjectSourceGame ParseSourceGame(const std::string_view s)
{
static const std::unordered_map<std::string, ObjectSourceGame> LookupTable{
static const std::unordered_map<std::string_view, ObjectSourceGame> LookupTable{
{ "rct1", ObjectSourceGame::RCT1 },
{ "rct1aa", ObjectSourceGame::AddedAttractions },
{ "rct1ll", ObjectSourceGame::LoopyLandscapes },

View File

@@ -69,7 +69,7 @@ struct ObjectEntryEqual
}
};
using ObjectIdentifierMap = std::unordered_map<std::string, size_t>;
using ObjectIdentifierMap = std::unordered_map<std::string, size_t, String::Hash, std::equal_to<>>;
using ObjectEntryMap = std::unordered_map<RCTObjectEntry, size_t, ObjectEntryHash, ObjectEntryEqual>;
class ObjectFileIndex final : public FileIndex<ObjectRepositoryItem>
@@ -235,7 +235,7 @@ public:
const ObjectRepositoryItem* FindObject(std::string_view identifier) const override final
{
auto kvp = _newItemMap.find(std::string(identifier));
auto kvp = _newItemMap.find(identifier);
if (kvp != _newItemMap.end())
{
return &_items[kvp->second];

View File

@@ -24,11 +24,12 @@
#include "../ride/Track.h"
#include "ParkFile.h"
#include <map>
#include <array>
#include <unordered_map>
using namespace OpenRCT2;
static std::map<std::string_view, std::string_view> oldObjectIds = {
static const std::unordered_map<std::string_view, std::string_view> kOldObjectIds = {
{ "official.scgpanda", "rct2dlc.scenery_group.scgpanda" },
{ "official.wtrpink", "rct2dlc.water.wtrpink" },
{ "official.ttrftl07", "toontowner.scenery_small.ttrftl07" },
@@ -2186,15 +2187,15 @@ static std::map<std::string_view, std::string_view> oldObjectIds = {
std::string_view MapToNewObjectIdentifier(std::string_view s)
{
auto it = oldObjectIds.find(s);
if (it != oldObjectIds.end())
auto it = kOldObjectIds.find(s);
if (it != kOldObjectIds.end())
{
return it->second;
}
return "";
}
static std::map<std::string_view, std::string_view> DATPathNames = {
static const std::unordered_map<std::string_view, std::string_view> kDATPathNames = {
{ "rct2.pathash", "PATHASH " }, { "rct2.pathcrzy", "PATHCRZY" }, { "rct2.pathdirt", "PATHDIRT" },
{ "rct2.pathspce", "PATHSPCE" }, { "rct2.road", "ROAD " }, { "rct2.tarmacb", "TARMACB " },
{ "rct2.tarmacg", "TARMACG " }, { "rct2.tarmac", "TARMAC " }, { "rct2.1920path", "1920PATH" },
@@ -2204,21 +2205,21 @@ static std::map<std::string_view, std::string_view> DATPathNames = {
std::optional<std::string_view> GetDATPathName(std::string_view newPathName)
{
auto it = DATPathNames.find(newPathName);
if (it != DATPathNames.end())
auto it = kDATPathNames.find(newPathName);
if (it != kDATPathNames.end())
{
return it->second;
}
return std::nullopt;
}
static RCT2::FootpathMapping _extendedFootpathMappings[] = {
static constexpr auto kExtendedFootpathMappings = std::to_array<RCT2::FootpathMapping>({
{ "rct1.path.tarmac", "rct1.footpath_surface.tarmac", "rct1.footpath_surface.queue_blue", "rct2.footpath_railings.wood" },
};
});
const RCT2::FootpathMapping* GetFootpathMapping(const ObjectEntryDescriptor& desc)
{
for (const auto& mapping : _extendedFootpathMappings)
for (const auto& mapping : kExtendedFootpathMappings)
{
if (mapping.Original == desc.GetName())
{
@@ -2275,7 +2276,7 @@ void UpdateFootpathsFromMapping(
pathToRailingsMap[entryIndex] = railingIndex;
}
const std::vector<std::string_view> peepAnimObjects = {
static constexpr auto kPeepAnimObjects = std::to_array<std::string_view>({
"rct2.peep_animations.guest",
"rct2.peep_animations.handyman",
"rct2.peep_animations.mechanic",
@@ -2291,11 +2292,11 @@ const std::vector<std::string_view> peepAnimObjects = {
"rct2.peep_animations.entertainer_roman",
"rct2.peep_animations.entertainer_sheriff",
"rct2.peep_animations.entertainer_snowman",
};
});
const std::vector<std::string_view>& GetLegacyPeepAnimationObjects()
std::span<const std::string_view> GetLegacyPeepAnimationObjects()
{
return peepAnimObjects;
return kPeepAnimObjects;
}
using AnimObjectConversionTable = std::map<RCT12PeepAnimationGroup, std::pair<ObjectEntryIndex, PeepAnimationGroup>>;
@@ -2378,12 +2379,12 @@ void ConvertPeepAnimationTypeToObjects(OpenRCT2::GameState_t& gameState)
LOG_INFO("Converted %d peep entities", numConverted);
}
static constexpr std::array kClimateObjectIdsByLegacyClimateType = {
static constexpr auto kClimateObjectIdsByLegacyClimateType = std::to_array<std::string_view>({
"rct2.climate.cool_and_wet",
"rct2.climate.warm",
"rct2.climate.hot_and_dry",
"rct2.climate.cold",
};
});
std::string_view GetClimateObjectIdFromLegacyClimateType(OpenRCT2::RCT12::ClimateType climate)
{

View File

@@ -14,8 +14,8 @@
#include <cstdint>
#include <optional>
#include <span>
#include <string_view>
#include <vector>
namespace OpenRCT2
{
@@ -48,7 +48,7 @@ void UpdateFootpathsFromMapping(
ObjectList& requiredObjects, ObjectEntryIndex& surfaceCount, ObjectEntryIndex& railingCount, ObjectEntryIndex entryIndex,
const OpenRCT2::RCT2::FootpathMapping* footpathMapping);
const std::vector<std::string_view>& GetLegacyPeepAnimationObjects();
std::span<const std::string_view> GetLegacyPeepAnimationObjects();
void ConvertPeepAnimationTypeToObjects(OpenRCT2::GameState_t& gameState);
std::string_view GetClimateObjectIdFromLegacyClimateType(OpenRCT2::RCT12::ClimateType);

View File

@@ -818,7 +818,7 @@ void RCT12AddDefaultObjects(ObjectList& objectList)
}
}
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const std::vector<std::string_view>& objectNames)
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, std::span<const std::string_view> objectNames)
{
for (const auto& objectName : objectNames)
{

View File

@@ -21,6 +21,7 @@
#include "../world/tile_element/TileElementType.h"
#include "Limits.h"
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>
@@ -1255,7 +1256,7 @@ std::string_view GetStationIdentifierFromStyle(uint8_t style);
uint8_t GetStationStyleFromIdentifier(u8string_view identifier);
std::optional<uint8_t> GetStyleFromMusicIdentifier(std::string_view identifier);
void RCT12AddDefaultObjects(ObjectList& objectList);
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const std::vector<std::string_view>& objectNames);
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, std::span<const std::string_view> objectNames);
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const OpenRCT2::RCT12::EntryList& entryList);
bool IsUserStringID(StringId stringId);