Skip to content

Commit

Permalink
Merge pull request #14 from Laupetin/feature/rename-fastfiles
Browse files Browse the repository at this point in the history
Introduce "project" concept and be able to rename built zones
  • Loading branch information
Laupetin authored Sep 28, 2023
2 parents 91deeea + bb94162 commit 98528db
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 125 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
151 changes: 92 additions & 59 deletions src/Linker/Linker.cpp

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions src/Linker/LinkerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CommandLineOption* const OPTION_BASE_FOLDER =
const CommandLineOption* const OPTION_OUTPUT_FOLDER =
CommandLineOption::Builder::Create()
.WithLongName("output-folder")
.WithDescription("Specifies the output folder containing the contents of the unlinked zones. Defaults to \"" + std::string(LinkerArgs::DEFAULT_OUTPUT_FOLDER) + "\".")
.WithDescription("Specifies the output folder containing the build artifacts. Defaults to \"" + std::string(LinkerArgs::DEFAULT_OUTPUT_FOLDER) + "\".")
.WithParameter("outputFolderPath")
.Build();

Expand Down Expand Up @@ -100,9 +100,9 @@ LinkerArgs::LinkerArgs()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent<decltype(COMMAND_LINE_OPTIONS)>::value),
m_base_pattern(R"(\?base\?)"),
m_game_pattern(R"(\?game\?)"),
m_zone_pattern(R"(\?zone\?)"),
m_base_folder_depends_on_zone(false),
m_out_folder_depends_on_zone(false),
m_project_pattern(R"(\?project\?)"),
m_base_folder_depends_on_project(false),
m_out_folder_depends_on_project(false),
m_verbose(false)
{
}
Expand All @@ -116,7 +116,7 @@ void LinkerArgs::PrintUsage()
usage.AddCommandLineOption(commandLineOption);
}

usage.AddArgument("zoneName");
usage.AddArgument("projectName");
usage.SetVariableArguments(true);

usage.Print();
Expand All @@ -129,9 +129,9 @@ void LinkerArgs::SetVerbose(const bool isVerbose)
ObjWriting::Configuration.Verbose = isVerbose;
}

std::string LinkerArgs::GetBasePathForZone(const std::string& zoneName) const
std::string LinkerArgs::GetBasePathForProject(const std::string& projectName) const
{
return std::regex_replace(m_base_folder, m_zone_pattern, zoneName);
return std::regex_replace(m_base_folder, m_project_pattern, projectName);
}

void LinkerArgs::SetDefaultBasePath()
Expand All @@ -148,20 +148,20 @@ void LinkerArgs::SetDefaultBasePath()
}
}

std::set<std::string> LinkerArgs::GetZoneIndependentSearchPaths(const std::set<std::string>& set) const
std::set<std::string> LinkerArgs::GetProjectIndependentSearchPaths(const std::set<std::string>& set) const
{
std::set<std::string> out;

for (const auto& path : set)
{
if (path.find(PATTERN_GAME) != std::string::npos)
continue;
if (path.find(PATTERN_ZONE) != std::string::npos)
if (path.find(PATTERN_PROJECT) != std::string::npos)
continue;

if (path.find(PATTERN_BASE) != std::string::npos)
{
if (m_base_folder_depends_on_zone)
if (m_base_folder_depends_on_project)
continue;

out.emplace(std::regex_replace(path, m_base_pattern, m_base_folder));
Expand All @@ -175,21 +175,21 @@ std::set<std::string> LinkerArgs::GetZoneIndependentSearchPaths(const std::set<s
return out;
}

std::set<std::string> LinkerArgs::GetSearchPathsForZone(const std::set<std::string>& set, const std::string& gameName, const std::string& zoneName) const
std::set<std::string> LinkerArgs::GetSearchPathsForProject(const std::set<std::string>& set, const std::string& gameName, const std::string& projectName) const
{
std::set<std::string> out;
const auto basePath = GetBasePathForZone(zoneName);
const auto basePath = GetBasePathForProject(projectName);

for (const auto& path : set)
{
if (path.find(PATTERN_GAME) == std::string::npos
&& path.find(PATTERN_ZONE) == std::string::npos
&& (!m_base_folder_depends_on_zone || path.find(PATTERN_BASE) == std::string::npos))
&& path.find(PATTERN_PROJECT) == std::string::npos
&& (!m_base_folder_depends_on_project || path.find(PATTERN_BASE) == std::string::npos))
{
continue;
}

out.emplace(std::regex_replace(std::regex_replace(std::regex_replace(path, m_zone_pattern, zoneName), m_game_pattern, gameName), m_base_pattern, basePath));
out.emplace(std::regex_replace(std::regex_replace(std::regex_replace(path, m_project_pattern, projectName), m_game_pattern, gameName), m_base_pattern, basePath));
}

return out;
Expand All @@ -210,10 +210,10 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv)
return false;
}

m_zones_to_build = m_argument_parser.GetArguments();
if (m_zones_to_build.empty())
m_projects_to_build = m_argument_parser.GetArguments();
if (m_projects_to_build.empty())
{
// No zones to build specified...
// No projects to build specified...
PrintUsage();
return false;
}
Expand All @@ -226,14 +226,14 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv)
m_base_folder = m_argument_parser.GetValueForOption(OPTION_BASE_FOLDER);
else
SetDefaultBasePath();
m_base_folder_depends_on_zone = m_base_folder.find(PATTERN_GAME) != std::string::npos || m_base_folder.find(PATTERN_ZONE) != std::string::npos;
m_base_folder_depends_on_project = m_base_folder.find(PATTERN_GAME) != std::string::npos || m_base_folder.find(PATTERN_PROJECT) != std::string::npos;

// --output-folder
if (m_argument_parser.IsOptionSpecified(OPTION_OUTPUT_FOLDER))
m_out_folder = m_argument_parser.GetValueForOption(OPTION_OUTPUT_FOLDER);
else
m_out_folder = DEFAULT_OUTPUT_FOLDER;
m_out_folder_depends_on_zone = m_out_folder.find(PATTERN_ZONE) != std::string::npos;
m_out_folder_depends_on_project = m_out_folder.find(PATTERN_PROJECT) != std::string::npos;

// --asset-search-path
if (m_argument_parser.IsOptionSpecified(OPTION_ASSET_SEARCH_PATH))
Expand Down Expand Up @@ -286,37 +286,37 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv)
return true;
}

std::string LinkerArgs::GetOutputFolderPathForZone(const std::string& zoneName) const
std::string LinkerArgs::GetOutputFolderPathForProject(const std::string& projectName) const
{
return std::regex_replace(std::regex_replace(m_out_folder, m_zone_pattern, zoneName), m_base_pattern, GetBasePathForZone(zoneName));
return std::regex_replace(std::regex_replace(m_out_folder, m_project_pattern, projectName), m_base_pattern, GetBasePathForProject(projectName));
}

std::set<std::string> LinkerArgs::GetZoneIndependentAssetSearchPaths() const
std::set<std::string> LinkerArgs::GetProjectIndependentAssetSearchPaths() const
{
return GetZoneIndependentSearchPaths(m_asset_search_paths);
return GetProjectIndependentSearchPaths(m_asset_search_paths);
}

std::set<std::string> LinkerArgs::GetZoneIndependentGdtSearchPaths() const
std::set<std::string> LinkerArgs::GetProjectIndependentGdtSearchPaths() const
{
return GetZoneIndependentSearchPaths(m_gdt_search_paths);
return GetProjectIndependentSearchPaths(m_gdt_search_paths);
}

std::set<std::string> LinkerArgs::GetZoneIndependentSourceSearchPaths() const
std::set<std::string> LinkerArgs::GetProjectIndependentSourceSearchPaths() const
{
return GetZoneIndependentSearchPaths(m_source_search_paths);
return GetProjectIndependentSearchPaths(m_source_search_paths);
}

std::set<std::string> LinkerArgs::GetAssetSearchPathsForZone(const std::string& gameName, const std::string& zoneName) const
std::set<std::string> LinkerArgs::GetAssetSearchPathsForProject(const std::string& gameName, const std::string& projectName) const
{
return GetSearchPathsForZone(m_asset_search_paths, gameName, zoneName);
return GetSearchPathsForProject(m_asset_search_paths, gameName, projectName);
}

std::set<std::string> LinkerArgs::GetGdtSearchPathsForZone(const std::string& gameName, const std::string& zoneName) const
std::set<std::string> LinkerArgs::GetGdtSearchPathsForProject(const std::string& gameName, const std::string& projectName) const
{
return GetSearchPathsForZone(m_gdt_search_paths, gameName, zoneName);
return GetSearchPathsForProject(m_gdt_search_paths, gameName, projectName);
}

std::set<std::string> LinkerArgs::GetSourceSearchPathsForZone(const std::string& zoneName) const
std::set<std::string> LinkerArgs::GetSourceSearchPathsForProject(const std::string& projectName) const
{
return GetSearchPathsForZone(m_source_search_paths, "", zoneName);
return GetSearchPathsForProject(m_source_search_paths, "", projectName);
}
44 changes: 22 additions & 22 deletions src/Linker/LinkerArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ class LinkerArgs
public:
static constexpr const char* PATTERN_BASE = "?base?";
static constexpr const char* PATTERN_GAME = "?game?";
static constexpr const char* PATTERN_ZONE = "?zone?";
static constexpr const char* PATTERN_PROJECT = "?project?";

static constexpr const char* DEFAULT_BASE_FOLDER = ".";
static constexpr const char* DEFAULT_BASE_FOLDER_MOD_TOOLS = "..";
static constexpr const char* DEFAULT_OUTPUT_FOLDER = "?base?/zone_out/?zone?";
static constexpr const char* DEFAULT_ASSET_SEARCH_PATH = "?base?/raw;?base?/raw/?game?;?base?/zone_raw/?zone?";
static constexpr const char* DEFAULT_GDT_SEARCH_PATH = "?base?/source_data;?base?/zone_raw/?zone?/source_data";
static constexpr const char* DEFAULT_SOURCE_SEARCH_PATH = "?base?/zone_source;?base?/zone_raw/?zone?/zone_source";
static constexpr const char* DEFAULT_OUTPUT_FOLDER = "?base?/zone_out/?project?";
static constexpr const char* DEFAULT_ASSET_SEARCH_PATH = "?base?/raw;?base?/raw/?game?;?base?/zone_raw/?project?";
static constexpr const char* DEFAULT_GDT_SEARCH_PATH = "?base?/source_data;?base?/zone_raw/?project?/source_data";
static constexpr const char* DEFAULT_SOURCE_SEARCH_PATH = "?base?/zone_source;?base?/zone_raw/?project?/zone_source";

private:
ArgumentParser m_argument_parser;
std::regex m_base_pattern;
std::regex m_game_pattern;
std::regex m_zone_pattern;
std::regex m_project_pattern;

/**
* \brief Prints a command line usage help text for the Linker tool to stdout.
Expand All @@ -34,19 +34,19 @@ class LinkerArgs

void SetVerbose(bool isVerbose);

_NODISCARD std::string GetBasePathForZone(const std::string& zoneName) const;
_NODISCARD std::string GetBasePathForProject(const std::string& projectName) const;
void SetDefaultBasePath();
_NODISCARD std::set<std::string> GetZoneIndependentSearchPaths(const std::set<std::string>& set) const;
_NODISCARD std::set<std::string> GetSearchPathsForZone(const std::set<std::string>& set, const std::string& gameName, const std::string& zoneName) const;
_NODISCARD std::set<std::string> GetProjectIndependentSearchPaths(const std::set<std::string>& set) const;
_NODISCARD std::set<std::string> GetSearchPathsForProject(const std::set<std::string>& set, const std::string& gameName, const std::string& projectName) const;

public:
std::vector<std::string> m_zones_to_load;
std::vector<std::string> m_zones_to_build;
std::vector<std::string> m_projects_to_build;

std::string m_base_folder;
std::string m_out_folder;
bool m_base_folder_depends_on_zone;
bool m_out_folder_depends_on_zone;
bool m_base_folder_depends_on_project;
bool m_out_folder_depends_on_project;

std::set<std::string> m_asset_search_paths;
std::set<std::string> m_gdt_search_paths;
Expand All @@ -58,17 +58,17 @@ class LinkerArgs
bool ParseArgs(int argc, const char** argv);

/**
* \brief Converts the output path specified by command line arguments to a path applies for the specified zone.
* \param zoneName The name of the zone to resolve the path input for.
* \return An output path for the zone based on the user input.
* \brief Converts the output path specified by command line arguments to a path applies for the specified project.
* \param projectName The name of the project to resolve the path input for.
* \return An output path for the project based on the user input.
*/
_NODISCARD std::string GetOutputFolderPathForZone(const std::string& zoneName) const;
_NODISCARD std::string GetOutputFolderPathForProject(const std::string& projectName) const;

_NODISCARD std::set<std::string> GetZoneIndependentAssetSearchPaths() const;
_NODISCARD std::set<std::string> GetZoneIndependentGdtSearchPaths() const;
_NODISCARD std::set<std::string> GetZoneIndependentSourceSearchPaths() const;
_NODISCARD std::set<std::string> GetProjectIndependentAssetSearchPaths() const;
_NODISCARD std::set<std::string> GetProjectIndependentGdtSearchPaths() const;
_NODISCARD std::set<std::string> GetProjectIndependentSourceSearchPaths() const;

_NODISCARD std::set<std::string> GetAssetSearchPathsForZone(const std::string& gameName, const std::string& zoneName) const;
_NODISCARD std::set<std::string> GetGdtSearchPathsForZone(const std::string& gameName, const std::string& zoneName) const;
_NODISCARD std::set<std::string> GetSourceSearchPathsForZone(const std::string& zoneName) const;
_NODISCARD std::set<std::string> GetAssetSearchPathsForProject(const std::string& gameName, const std::string& projectName) const;
_NODISCARD std::set<std::string> GetGdtSearchPathsForProject(const std::string& gameName, const std::string& projectName) const;
_NODISCARD std::set<std::string> GetSourceSearchPathsForProject(const std::string& projectName) const;
};
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 98528db

Please sign in to comment.