mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Rework AppendRequiredObjects to take a std::string_view instead
This commit is contained in:
@@ -380,7 +380,7 @@ namespace OpenRCT2
|
||||
if (version < kPeepNamesObjectsVersion)
|
||||
{
|
||||
AppendRequiredObjects(
|
||||
requiredObjects, ObjectType::PeepNames, std::vector<std::string>({ "rct2.peep_names.original" }));
|
||||
requiredObjects, ObjectType::PeepNames, std::vector<std::string_view>({ "rct2.peep_names.original" }));
|
||||
}
|
||||
|
||||
RequiredObjects = std::move(requiredObjects);
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace OpenRCT2::RCT1
|
||||
|
||||
String::Set(dst->InternalName, sizeof(dst->InternalName), desc.title);
|
||||
|
||||
if (desc.textObjectId != nullptr)
|
||||
if (!desc.textObjectId.empty())
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
@@ -1514,13 +1514,14 @@ namespace OpenRCT2::RCT1
|
||||
AppendRequiredObjects(result, ObjectType::PathAdditions, _pathAdditionEntries);
|
||||
AppendRequiredObjects(result, ObjectType::SceneryGroup, _sceneryGroupEntries);
|
||||
AppendRequiredObjects(result, ObjectType::Banners, _bannerEntries);
|
||||
AppendRequiredObjects(result, ObjectType::ParkEntrance, std::vector<std::string>({ "rct2.park_entrance.pkent1" }));
|
||||
AppendRequiredObjects(
|
||||
result, ObjectType::ParkEntrance, std::vector<std::string_view>({ "rct2.park_entrance.pkent1" }));
|
||||
AppendRequiredObjects(result, ObjectType::Water, _waterEntry);
|
||||
AppendRequiredObjects(result, ObjectType::TerrainSurface, _terrainSurfaceEntries);
|
||||
AppendRequiredObjects(result, ObjectType::TerrainEdge, _terrainEdgeEntries);
|
||||
AppendRequiredObjects(result, ObjectType::FootpathSurface, _footpathSurfaceEntries);
|
||||
AppendRequiredObjects(result, ObjectType::FootpathRailings, _footpathRailingsEntries);
|
||||
AppendRequiredObjects(result, ObjectType::PeepNames, std::vector<std::string>({ "rct2.peep_names.original" }));
|
||||
AppendRequiredObjects(result, ObjectType::PeepNames, std::vector<std::string_view>({ "rct2.peep_names.original" }));
|
||||
RCT12AddDefaultObjects(result);
|
||||
|
||||
// Normalise the name to make the scenario as recognisable as possible
|
||||
@@ -1528,8 +1529,8 @@ namespace OpenRCT2::RCT1
|
||||
|
||||
// Infer what scenario text object to use, if any
|
||||
SourceDescriptor desc;
|
||||
if (ScenarioSources::TryGetByName(normalisedName.c_str(), &desc) && desc.textObjectId != nullptr)
|
||||
AppendRequiredObjects(result, ObjectType::ScenarioText, std::vector<std::string>({ desc.textObjectId }));
|
||||
if (ScenarioSources::TryGetByName(normalisedName.c_str(), &desc) && !desc.textObjectId.empty())
|
||||
AppendRequiredObjects(result, ObjectType::ScenarioText, std::vector<std::string_view>({ desc.textObjectId }));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -2345,7 +2346,7 @@ namespace OpenRCT2::RCT1
|
||||
if (scNumber != -1)
|
||||
{
|
||||
SourceDescriptor desc;
|
||||
if (ScenarioSources::TryGetById(scNumber, &desc) && desc.textObjectId != nullptr)
|
||||
if (ScenarioSources::TryGetById(scNumber, &desc) && !desc.textObjectId.empty())
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
@@ -21,7 +20,7 @@ namespace OpenRCT2::RCT12
|
||||
class EntryList
|
||||
{
|
||||
private:
|
||||
std::vector<std::string> _entries;
|
||||
std::vector<std::string_view> _entries;
|
||||
|
||||
public:
|
||||
size_t GetCount() const
|
||||
@@ -29,7 +28,7 @@ namespace OpenRCT2::RCT12
|
||||
return _entries.size();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GetEntries() const
|
||||
const std::vector<std::string_view>& GetEntries() const
|
||||
{
|
||||
return _entries;
|
||||
}
|
||||
|
||||
@@ -818,7 +818,7 @@ void RCT12AddDefaultObjects(ObjectList& objectList)
|
||||
}
|
||||
}
|
||||
|
||||
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const std::vector<std::string>& objectNames)
|
||||
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const std::vector<std::string_view>& objectNames)
|
||||
{
|
||||
for (const auto& objectName : objectNames)
|
||||
{
|
||||
|
||||
@@ -1197,7 +1197,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>& objectNames);
|
||||
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const std::vector<std::string_view>& objectNames);
|
||||
void AppendRequiredObjects(ObjectList& objectList, ObjectType objectType, const OpenRCT2::RCT12::EntryList& entryList);
|
||||
bool IsUserStringID(StringId stringId);
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ namespace OpenRCT2::RCT2
|
||||
String::Set(dst->InternalName, sizeof(dst->InternalName), dst->Name);
|
||||
String::Set(dst->Details, sizeof(dst->Details), _s6.Info.Details);
|
||||
|
||||
if (desc.textObjectId != nullptr)
|
||||
if (!desc.textObjectId.empty())
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
@@ -1887,7 +1887,8 @@ namespace OpenRCT2::RCT2
|
||||
|
||||
AppendRequiredObjects(objectList, ObjectType::TerrainSurface, _terrainSurfaceEntries);
|
||||
AppendRequiredObjects(objectList, ObjectType::TerrainEdge, _terrainEdgeEntries);
|
||||
AppendRequiredObjects(objectList, ObjectType::PeepNames, std::vector<std::string>({ "rct2.peep_names.original" }));
|
||||
AppendRequiredObjects(
|
||||
objectList, ObjectType::PeepNames, std::vector<std::string_view>({ "rct2.peep_names.original" }));
|
||||
RCT12AddDefaultObjects(objectList);
|
||||
|
||||
// Normalise the name to make the scenario as recognisable as possible
|
||||
@@ -1895,8 +1896,9 @@ namespace OpenRCT2::RCT2
|
||||
|
||||
// Infer what scenario text object to use, if any
|
||||
SourceDescriptor desc;
|
||||
if (ScenarioSources::TryGetByName(normalisedName.c_str(), &desc) && desc.textObjectId != nullptr)
|
||||
AppendRequiredObjects(objectList, ObjectType::ScenarioText, std::vector<std::string>({ desc.textObjectId }));
|
||||
if (ScenarioSources::TryGetByName(normalisedName.c_str(), &desc) && !desc.textObjectId.empty())
|
||||
AppendRequiredObjects(
|
||||
objectList, ObjectType::ScenarioText, std::vector<std::string_view>({ desc.textObjectId }));
|
||||
|
||||
return objectList;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRCT2::ScenarioSources
|
||||
const uint8_t Id;
|
||||
const utf8* Title;
|
||||
const uint8_t Category;
|
||||
const char* TextObjectId;
|
||||
u8string_view TextObjectId;
|
||||
};
|
||||
|
||||
#pragma region Scenario Data
|
||||
@@ -386,7 +386,7 @@ namespace OpenRCT2::ScenarioSources
|
||||
outDesc->source = static_cast<uint8_t>(ScenarioSource::Other);
|
||||
outDesc->index = -1;
|
||||
outDesc->category = SCENARIO_CATEGORY_OTHER;
|
||||
outDesc->textObjectId = nullptr;
|
||||
outDesc->textObjectId = {};
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ namespace OpenRCT2::ScenarioSources
|
||||
outDesc->source = static_cast<uint8_t>(ScenarioSource::Other);
|
||||
outDesc->index = -1;
|
||||
outDesc->category = SCENARIO_CATEGORY_OTHER;
|
||||
outDesc->textObjectId = nullptr;
|
||||
outDesc->textObjectId = {};
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ struct SourceDescriptor
|
||||
uint8_t source;
|
||||
int32_t index;
|
||||
uint8_t category;
|
||||
const char* textObjectId;
|
||||
u8string_view textObjectId;
|
||||
};
|
||||
|
||||
namespace OpenRCT2::ScenarioSources
|
||||
|
||||
Reference in New Issue
Block a user