Skip to content

Commit

Permalink
Add possibility to override zone name in zone definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Laupetin committed Sep 28, 2023
1 parent e36367f commit bb94162
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Linker/Game/IW3/ZoneCreatorIW3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameIW3);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW3);
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
Expand Down
2 changes: 1 addition & 1 deletion src/Linker/Game/IW4/ZoneCreatorIW4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameIW4);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW4);
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
Expand Down
2 changes: 1 addition & 1 deletion src/Linker/Game/IW5/ZoneCreatorIW5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameIW5);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW5);
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
Expand Down
2 changes: 1 addition & 1 deletion src/Linker/Game/T5/ZoneCreatorT5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameT5);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameT5);
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
Expand Down
2 changes: 1 addition & 1 deletion src/Linker/Game/T6/ZoneCreatorT6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const

std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameT6);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameT6);
CreateZoneAssetPools(zone.get());

for (const auto& assetEntry : context.m_definition->m_assets)
Expand Down
35 changes: 34 additions & 1 deletion src/Linker/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const IZoneCreator* const ZONE_CREATORS[]

class Linker::Impl
{
static constexpr const char* METADATA_NAME = "name";
static constexpr const char* METADATA_GAME = "game";
static constexpr const char* METADATA_GDT = "gdt";

Expand Down Expand Up @@ -277,6 +278,33 @@ class Linker::Impl
return true;
}

static bool GetNameFromZoneDefinition(std::string& name, const std::string& projectName, const ZoneDefinition& zoneDefinition)
{
auto firstNameEntry = true;
const auto [rangeBegin, rangeEnd] = zoneDefinition.m_metadata_lookup.equal_range(METADATA_NAME);
for (auto i = rangeBegin; i != rangeEnd; ++i)
{
if (firstNameEntry)
{
name = i->second->m_value;
firstNameEntry = false;
}
else
{
if (name != i->second->m_value)
{
std::cout << "Conflicting names in project \"" << projectName << "\": " << name << " != " << i->second << std::endl;
return false;
}
}
}

if (firstNameEntry)
name = projectName;

return true;
}

std::unique_ptr<ZoneDefinition> ReadZoneDefinition(const std::string& projectName, ISearchPath* sourceSearchPath) const
{
std::unique_ptr<ZoneDefinition> zoneDefinition;
Expand All @@ -299,6 +327,9 @@ class Linker::Impl
return nullptr;
}

if (!GetNameFromZoneDefinition(zoneDefinition->m_name, projectName, *zoneDefinition))
return nullptr;

if (!IncludeAdditionalZoneDefinitions(projectName, *zoneDefinition, sourceSearchPath))
return nullptr;

Expand Down Expand Up @@ -425,7 +456,7 @@ class Linker::Impl
std::unique_ptr<Zone> CreateZoneForDefinition(const std::string& projectName, ZoneDefinition& zoneDefinition, ISearchPath* assetSearchPath, ISearchPath* gdtSearchPath,
ISearchPath* sourceSearchPath) const
{
auto context = std::make_unique<ZoneCreationContext>(projectName, assetSearchPath, &zoneDefinition);
const auto context = std::make_unique<ZoneCreationContext>(assetSearchPath, &zoneDefinition);
if (!ProcessZoneDefinitionIgnores(projectName, *context, sourceSearchPath))
return nullptr;
if (!GetGameNameFromZoneDefinition(context->m_game_name, projectName, zoneDefinition))
Expand Down Expand Up @@ -461,6 +492,8 @@ class Linker::Impl
return false;
}

std::cout << "Created zone \"" << zoneFilePath.string() << "\"\n";

stream.close();
return true;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Linker/ZoneCreation/ZoneCreationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ ZoneCreationContext::ZoneCreationContext()
{
}

ZoneCreationContext::ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath, ZoneDefinition* definition)
: m_zone_name(std::move(zoneName)),
m_asset_search_path(assetSearchPath),
ZoneCreationContext::ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition)
: m_asset_search_path(assetSearchPath),
m_definition(definition)
{
}
3 changes: 1 addition & 2 deletions src/Linker/ZoneCreation/ZoneCreationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
class ZoneCreationContext
{
public:
std::string m_zone_name;
std::string m_game_name;
ISearchPath* m_asset_search_path;
ZoneDefinition* m_definition;
std::vector<std::unique_ptr<Gdt>> m_gdt_files;
std::vector<AssetListEntry> m_ignored_assets;

ZoneCreationContext();
ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath, ZoneDefinition* definition);
ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition);
};
1 change: 1 addition & 0 deletions src/ZoneCommon/Zone/Definition/ZoneDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ZoneMetaDataEntry
class ZoneDefinition
{
public:
std::string m_name;
std::vector<std::unique_ptr<ZoneMetaDataEntry>> m_metadata;
std::unordered_multimap<std::string, ZoneMetaDataEntry*> m_metadata_lookup;
std::vector<std::string> m_includes;
Expand Down

0 comments on commit bb94162

Please sign in to comment.