2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-02-10 17:43:03 +00:00

Merge pull request #672 from Laupetin/refactor/game-asset-type-names

refactor: game asset type names
This commit is contained in:
Jan
2026-02-05 18:15:52 +01:00
committed by GitHub
67 changed files with 509 additions and 770 deletions

View File

@@ -1,8 +1,10 @@
#pragma once #pragma once
#include "GameLanguage.h" #include "GameLanguage.h"
#include "Zone/ZoneTypes.h"
#include <cstdint> #include <cstdint>
#include <optional>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
@@ -64,5 +66,8 @@ public:
[[nodiscard]] virtual const std::string& GetShortName() const = 0; [[nodiscard]] virtual const std::string& GetShortName() const = 0;
[[nodiscard]] virtual const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const = 0; [[nodiscard]] virtual const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const = 0;
[[nodiscard]] virtual asset_type_t GetAssetTypeCount() const = 0;
[[nodiscard]] virtual std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const = 0;
static IGame* GetGameById(GameId gameId); static IGame* GetGameById(GameId gameId);
}; };

View File

@@ -1,28 +1,56 @@
#include "GameIW3.h" #include "GameIW3.h"
#include "IW3.h"
#include <algorithm> #include <algorithm>
using namespace IW3; using namespace IW3;
GameId Game::GetId() const namespace
{ {
return GameId::IW3; constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{
} "xmodelpieces", "physpreset", "xanim", "xmodel", "material", "techniqueset", "image", "sound", "soundcurve", "loadedsound",
"clipmap_unused", "clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents", "gfxworld", "lightdef", "uimap", "font",
"menulist", "menu", "localize", "weapon", "snddriverglobals", "fx", "impactfx", "aitype", "mptype", "character",
"xmodelalias", "rawfile", "stringtable",
};
} // namespace
const std::string& Game::GetFullName() const namespace IW3
{ {
static std::string fullName = "Call Of Duty 4: Modern Warfare"; GameId Game::GetId() const
return fullName; {
} return GameId::IW3;
}
const std::string& Game::GetShortName() const const std::string& Game::GetFullName() const
{ {
static std::string shortName = "IW3"; static std::string fullName = "Call Of Duty 4: Modern Warfare";
return shortName; return fullName;
} }
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const const std::string& Game::GetShortName() const
{ {
static std::vector<GameLanguagePrefix> prefixes; static std::string shortName = "IW3";
return prefixes; return shortName;
} }
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes;
return prefixes;
}
asset_type_t Game::GetAssetTypeCount() const
{
return ASSET_TYPE_COUNT;
}
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
{
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
} // namespace IW3

View File

@@ -1,4 +1,5 @@
#pragma once #pragma once
#include "Game/IGame.h" #include "Game/IGame.h"
namespace IW3 namespace IW3
@@ -10,5 +11,8 @@ namespace IW3
[[nodiscard]] const std::string& GetFullName() const override; [[nodiscard]] const std::string& GetFullName() const override;
[[nodiscard]] const std::string& GetShortName() const override; [[nodiscard]] const std::string& GetShortName() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override; [[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
}; };
} // namespace IW3 } // namespace IW3

View File

@@ -1,28 +1,61 @@
#include "GameIW4.h" #include "GameIW4.h"
#include "IW4.h"
#include <algorithm> #include <algorithm>
using namespace IW4; using namespace IW4;
GameId Game::GetId() const namespace
{ {
return GameId::IW4; constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{
} "physpreset", "physcollmap", "xanim", "xmodelsurfs", "xmodel",
"material", "pixelshader", "vertexshader", "vertexdecl", "techniqueset",
"image", "sound", "soundcurve", "loadedsound", "clipmap_unused",
"clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents",
"fxworld", "gfxworld", "lightdef", "uimap", "font",
"menulist", "menu", "localize", "weapon", "snddriverglobals",
"fx", "impactfx", "aitype", "mptype", "character",
"xmodelalias", "rawfile", "stringtable", "leaderboard", "structureddatadef",
"tracer", "vehicle", "addonmapents",
};
} // namespace
const std::string& Game::GetFullName() const namespace IW4
{ {
static std::string fullName = "Call Of Duty: Modern Warfare 2"; GameId Game::GetId() const
return fullName; {
} return GameId::IW4;
}
const std::string& Game::GetShortName() const const std::string& Game::GetFullName() const
{ {
static std::string shortName = "IW4"; static std::string fullName = "Call Of Duty: Modern Warfare 2";
return shortName; return fullName;
} }
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const const std::string& Game::GetShortName() const
{ {
static std::vector<GameLanguagePrefix> prefixes; static std::string shortName = "IW4";
return prefixes; return shortName;
} }
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes;
return prefixes;
}
asset_type_t Game::GetAssetTypeCount() const
{
return ASSET_TYPE_COUNT;
}
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
{
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
} // namespace IW4

View File

@@ -10,5 +10,8 @@ namespace IW4
[[nodiscard]] const std::string& GetFullName() const override; [[nodiscard]] const std::string& GetFullName() const override;
[[nodiscard]] const std::string& GetShortName() const override; [[nodiscard]] const std::string& GetShortName() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override; [[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
}; };
} // namespace IW4 } // namespace IW4

View File

@@ -1,28 +1,98 @@
#include "GameIW5.h" #include "GameIW5.h"
#include "IW5.h"
#include <algorithm> #include <algorithm>
using namespace IW5; using namespace IW5;
GameId Game::GetId() const namespace
{ {
return GameId::IW5; constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{
} "physpreset",
"physcollmap",
"xanim",
"xmodelsurfs",
"xmodel",
"material",
"pixelshader",
"vertexshader",
"vertexdecl",
"techniqueset",
"image",
"sound",
"soundcurve",
"loadedsound",
"clipmap",
"comworld",
"glassworld",
"pathdata",
"vehicletrack",
"mapents",
"fxworld",
"gfxworld",
"lightdef",
"uimap",
"font",
"menulist",
"menu",
"localize",
"attachment",
"weapon",
"snddriverglobals",
"fx",
"impactfx",
"surfacefx",
"aitype",
"mptype",
"character",
"xmodelalias",
"rawfile",
"scriptfile",
"stringtable",
"leaderboard",
"structureddatadef",
"tracer",
"vehicle",
"addonmapents",
};
} // namespace
const std::string& Game::GetFullName() const namespace IW5
{ {
static std::string fullName = "Call Of Duty: Modern Warfare 3"; GameId Game::GetId() const
return fullName; {
} return GameId::IW5;
}
const std::string& Game::GetShortName() const const std::string& Game::GetFullName() const
{ {
static std::string shortName = "IW5"; static std::string fullName = "Call Of Duty: Modern Warfare 3";
return shortName; return fullName;
} }
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const const std::string& Game::GetShortName() const
{ {
static std::vector<GameLanguagePrefix> prefixes; static std::string shortName = "IW5";
return prefixes; return shortName;
} }
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes;
return prefixes;
}
asset_type_t Game::GetAssetTypeCount() const
{
return ASSET_TYPE_COUNT;
}
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
{
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
} // namespace IW5

View File

@@ -10,5 +10,8 @@ namespace IW5
[[nodiscard]] const std::string& GetFullName() const override; [[nodiscard]] const std::string& GetFullName() const override;
[[nodiscard]] const std::string& GetShortName() const override; [[nodiscard]] const std::string& GetShortName() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override; [[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
}; };
} // namespace IW5 } // namespace IW5

View File

@@ -1,43 +1,74 @@
#include "GameT5.h" #include "GameT5.h"
#include "T5.h"
#include <algorithm> #include <algorithm>
using namespace T5; using namespace T5;
GameId Game::GetId() const namespace
{ {
return GameId::T5; constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{
} "xmodelpieces", "physpreset", "physconstraints", "destructibledef", "xanim", "xmodel", "material",
"techniqueset", "image", "soundbank", "soundpatch", "clipmap_unused", "clipmap", "comworld",
const std::string& Game::GetFullName() const "gameworldsp", "gameworldmp", "mapents", "gfxworld", "gfxlightdef", "uimap", "font",
{ "menulist", "menu", "localize", "weapon", "weapondef", "weaponvariant", "snddriverglobals",
static std::string fullName = "Call Of Duty: Black Ops"; "fx", "fximpacttable", "aitype", "mptype", "mpbody", "mphead", "character",
return fullName; "xmodelalias", "rawfile", "stringtable", "packindex", "xglobals", "ddl", "glasses",
} "emblemset",
const std::string& Game::GetShortName() const
{
static std::string shortName = "T5";
return shortName;
}
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes{
{GameLanguage::LANGUAGE_ENGLISH, "en_"},
{GameLanguage::LANGUAGE_FRENCH, "fr_"},
{GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"},
{GameLanguage::LANGUAGE_GERMAN, "ge_"},
{GameLanguage::LANGUAGE_AUSTRIAN, "ge_"},
{GameLanguage::LANGUAGE_ITALIAN, "it_"},
{GameLanguage::LANGUAGE_SPANISH, "sp_"},
{GameLanguage::LANGUAGE_BRITISH, "br_"},
{GameLanguage::LANGUAGE_RUSSIAN, "ru_"},
{GameLanguage::LANGUAGE_POLISH, "po_"},
{GameLanguage::LANGUAGE_KOREAN, "ko_"},
{GameLanguage::LANGUAGE_JAPANESE, "ja_"},
{GameLanguage::LANGUAGE_CZECH, "cz_"},
}; };
} // namespace
return prefixes; namespace T5
} {
GameId Game::GetId() const
{
return GameId::T5;
}
const std::string& Game::GetFullName() const
{
static std::string fullName = "Call Of Duty: Black Ops";
return fullName;
}
const std::string& Game::GetShortName() const
{
static std::string shortName = "T5";
return shortName;
}
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes{
{GameLanguage::LANGUAGE_ENGLISH, "en_"},
{GameLanguage::LANGUAGE_FRENCH, "fr_"},
{GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"},
{GameLanguage::LANGUAGE_GERMAN, "ge_"},
{GameLanguage::LANGUAGE_AUSTRIAN, "ge_"},
{GameLanguage::LANGUAGE_ITALIAN, "it_"},
{GameLanguage::LANGUAGE_SPANISH, "sp_"},
{GameLanguage::LANGUAGE_BRITISH, "br_"},
{GameLanguage::LANGUAGE_RUSSIAN, "ru_"},
{GameLanguage::LANGUAGE_POLISH, "po_"},
{GameLanguage::LANGUAGE_KOREAN, "ko_"},
{GameLanguage::LANGUAGE_JAPANESE, "ja_"},
{GameLanguage::LANGUAGE_CZECH, "cz_"},
};
return prefixes;
}
asset_type_t Game::GetAssetTypeCount() const
{
return ASSET_TYPE_COUNT;
}
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
{
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
} // namespace T5

View File

@@ -10,5 +10,8 @@ namespace T5
[[nodiscard]] const std::string& GetFullName() const override; [[nodiscard]] const std::string& GetFullName() const override;
[[nodiscard]] const std::string& GetShortName() const override; [[nodiscard]] const std::string& GetShortName() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override; [[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
}; };
} // namespace T5 } // namespace T5

View File

@@ -1,46 +1,130 @@
#include "GameT6.h" #include "GameT6.h"
#include "T6.h"
#include <algorithm> #include <algorithm>
using namespace T6; using namespace T6;
GameId Game::GetId() const namespace
{ {
return GameId::T6; constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{
} "xmodelpieces",
"physpreset",
const std::string& Game::GetFullName() const "physconstraints",
{ "destructibledef",
static std::string fullName = "Call Of Duty: Black Ops II"; "xanim",
return fullName; "xmodel",
} "material",
"techniqueset",
const std::string& Game::GetShortName() const "image",
{ "soundbank",
static std::string shortName = "T6"; "soundpatch",
return shortName; "clipmap_unused",
} "clipmap",
"comworld",
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const "gameworldsp",
{ "gameworldmp",
static std::vector<GameLanguagePrefix> prefixes{ "mapents",
{GameLanguage::LANGUAGE_ENGLISH, "en_"}, "gfxworld",
{GameLanguage::LANGUAGE_FRENCH, "fr_"}, "gfxlightdef",
{GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"}, "uimap",
{GameLanguage::LANGUAGE_GERMAN, "ge_"}, "font",
{GameLanguage::LANGUAGE_AUSTRIAN, "as_"}, "fonticon",
{GameLanguage::LANGUAGE_ITALIAN, "it_"}, "menulist",
{GameLanguage::LANGUAGE_SPANISH, "sp_"}, "menu",
{GameLanguage::LANGUAGE_BRITISH, "br_"}, "localize",
{GameLanguage::LANGUAGE_RUSSIAN, "ru_"}, "weapon",
{GameLanguage::LANGUAGE_POLISH, "po_"}, "weapondef",
{GameLanguage::LANGUAGE_KOREAN, "ko_"}, "weaponvariant",
{GameLanguage::LANGUAGE_JAPANESE, "ja_"}, "weaponfull",
{GameLanguage::LANGUAGE_CZECH, "cz_"}, "attachment",
{GameLanguage::LANGUAGE_FULL_JAPANESE, "fj_"}, "attachmentunique",
{GameLanguage::LANGUAGE_PORTUGUESE, "bp_"}, "camo",
{GameLanguage::LANGUAGE_MEXICAN_SPANISH, "ms_"}, "snddriverglobals",
"fx",
"fximpacttable",
"aitype",
"mptype",
"mpbody",
"mphead",
"character",
"xmodelalias",
"rawfile",
"stringtable",
"leaderboard",
"xglobals",
"ddl",
"glasses",
"emblemset",
"script",
"keyvaluepairs",
"vehicle",
"memoryblock",
"addonmapents",
"tracer",
"skinnedverts",
"qdb",
"slug",
"footsteptable",
"footstepfxtable",
"zbarrier",
}; };
} // namespace
return prefixes; namespace T6
} {
GameId Game::GetId() const
{
return GameId::T6;
}
const std::string& Game::GetFullName() const
{
static std::string fullName = "Call Of Duty: Black Ops II";
return fullName;
}
const std::string& Game::GetShortName() const
{
static std::string shortName = "T6";
return shortName;
}
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes{
{GameLanguage::LANGUAGE_ENGLISH, "en_"},
{GameLanguage::LANGUAGE_FRENCH, "fr_"},
{GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"},
{GameLanguage::LANGUAGE_GERMAN, "ge_"},
{GameLanguage::LANGUAGE_AUSTRIAN, "as_"},
{GameLanguage::LANGUAGE_ITALIAN, "it_"},
{GameLanguage::LANGUAGE_SPANISH, "sp_"},
{GameLanguage::LANGUAGE_BRITISH, "br_"},
{GameLanguage::LANGUAGE_RUSSIAN, "ru_"},
{GameLanguage::LANGUAGE_POLISH, "po_"},
{GameLanguage::LANGUAGE_KOREAN, "ko_"},
{GameLanguage::LANGUAGE_JAPANESE, "ja_"},
{GameLanguage::LANGUAGE_CZECH, "cz_"},
{GameLanguage::LANGUAGE_FULL_JAPANESE, "fj_"},
{GameLanguage::LANGUAGE_PORTUGUESE, "bp_"},
{GameLanguage::LANGUAGE_MEXICAN_SPANISH, "ms_"},
};
return prefixes;
}
asset_type_t Game::GetAssetTypeCount() const
{
return ASSET_TYPE_COUNT;
}
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
{
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
} // namespace T6

View File

@@ -10,5 +10,8 @@ namespace T6
[[nodiscard]] const std::string& GetFullName() const override; [[nodiscard]] const std::string& GetFullName() const override;
[[nodiscard]] const std::string& GetShortName() const override; [[nodiscard]] const std::string& GetShortName() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override; [[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
}; };
} // namespace T6 } // namespace T6

View File

@@ -4,7 +4,6 @@
#include <cassert> #include <cassert>
#include <format> #include <format>
#include <iostream>
IgnoredAssetLookup::IgnoredAssetLookup() = default; IgnoredAssetLookup::IgnoredAssetLookup() = default;
@@ -89,7 +88,7 @@ XAssetInfoGeneric* AssetCreationContext::AddAssetGeneric(GenericAssetRegistratio
addedAsset = m_zone.m_pools->AddAsset(std::move(xAssetInfo)); addedAsset = m_zone.m_pools->AddAsset(std::move(xAssetInfo));
if (addedAsset == nullptr) if (addedAsset == nullptr)
con::error("Failed to add asset of type \"{}\" to pool: \"{}\"", *m_zone.m_pools->GetAssetTypeName(assetType), pAssetName); con::error(R"(Failed to add asset of type "{}" to pool: "{}")", *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType), pAssetName);
return addedAsset; return addedAsset;
} }
@@ -99,7 +98,7 @@ XAssetInfoGeneric* AssetCreationContext::LoadDefaultAssetDependency(const asset_
if (result.HasTakenAction() && !result.HasFailed()) if (result.HasTakenAction() && !result.HasFailed())
return result.GetAssetInfo(); return result.GetAssetInfo();
con::error("Failed to create default asset of type {}", *m_zone.m_pools->GetAssetTypeName(assetType)); con::error("Failed to create default asset of type {}", *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType));
return nullptr; return nullptr;
} }
@@ -129,11 +128,11 @@ XAssetInfoGeneric* AssetCreationContext::LoadDependencyGeneric(const asset_type_
if (!result.HasFailed()) if (!result.HasFailed())
return result.GetAssetInfo(); return result.GetAssetInfo();
con::error("Could not load asset \"{}\" of type \"{}\"", assetName, *m_zone.m_pools->GetAssetTypeName(assetType)); con::error(R"(Could not load asset "{}" of type "{}")", assetName, *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType));
} }
else if (required) else if (required)
{ {
con::error("Missing asset \"{}\" of type \"{}\"", assetName, *m_zone.m_pools->GetAssetTypeName(assetType)); con::error(R"(Missing asset "{}" of type "{}")", assetName, *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType));
} }
return nullptr; return nullptr;
@@ -151,7 +150,8 @@ IndirectAssetReference AssetCreationContext::LoadIndirectAssetReferenceGeneric(c
const auto result = m_creators->CreateAsset(assetType, assetName, *this); const auto result = m_creators->CreateAsset(assetType, assetName, *this);
if (!result.HasTakenAction() && !result.HasFailed()) if (!result.HasTakenAction() && !result.HasFailed())
{ {
con::warn("Could not load indirectly referenced asset \"{}\" of type \"{}\"", assetName, *m_zone.m_pools->GetAssetTypeName(assetType)); con::warn(
R"(Could not load indirectly referenced asset "{}" of type "{}")", assetName, *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType));
} }
return IndirectAssetReference(assetType, assetName); return IndirectAssetReference(assetType, assetName);
} }
@@ -187,11 +187,11 @@ XAssetInfoGeneric* AssetCreationContext::ForceLoadDependencyGeneric(const asset_
if (!result.HasFailed()) if (!result.HasFailed())
return result.GetAssetInfo(); return result.GetAssetInfo();
con::error("Could not load asset \"{}\" of type \"{}\"", assetName, *m_zone.m_pools->GetAssetTypeName(assetType)); con::error(R"(Could not load asset "{}" of type "{}")", assetName, *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType));
} }
else else
{ {
con::error("Missing asset \"{}\" of type \"{}\"", assetName, *m_zone.m_pools->GetAssetTypeName(assetType)); con::error(R"(Missing asset "{}" of type "{}")", assetName, *IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeName(assetType));
} }
return nullptr; return nullptr;

View File

@@ -11,7 +11,6 @@
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
class AssetCreatorCollection; class AssetCreatorCollection;

View File

@@ -4,9 +4,10 @@
AssetCreatorCollection::AssetCreatorCollection(const Zone& zone) AssetCreatorCollection::AssetCreatorCollection(const Zone& zone)
{ {
m_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount()); const auto* game = IGame::GetGameById(zone.m_game_id);
m_asset_post_processors_by_type.resize(zone.m_pools->GetAssetTypeCount()); m_asset_creators_by_type.resize(game->GetAssetTypeCount());
m_default_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount()); m_asset_post_processors_by_type.resize(game->GetAssetTypeCount());
m_default_asset_creators_by_type.resize(game->GetAssetTypeCount());
} }
void AssetCreatorCollection::AddAssetCreator(std::unique_ptr<IAssetCreator> creator) void AssetCreatorCollection::AddAssetCreator(std::unique_ptr<IAssetCreator> creator)

View File

@@ -18,7 +18,7 @@ void ContentPrinter::PrintContent() const
con::info("Content:"); con::info("Content:");
for (const auto& asset : *pools) for (const auto& asset : *pools)
con::info("{}, {}", *pools->GetAssetTypeName(asset->m_type), asset->m_name); con::info("{}, {}", *game->GetAssetTypeName(asset->m_type), asset->m_name);
con::info(""); con::info("");
} }

View File

@@ -8,9 +8,9 @@
#include "SearchPath/OutputPathFilesystem.h" #include "SearchPath/OutputPathFilesystem.h"
#include "UnlinkerArgs.h" #include "UnlinkerArgs.h"
#include "UnlinkerPaths.h" #include "UnlinkerPaths.h"
#include "Utils/ClassUtils.h"
#include "Utils/Logging/Log.h" #include "Utils/Logging/Log.h"
#include "Utils/ObjFileStream.h" #include "Utils/ObjFileStream.h"
#include "Zone/AssetNameResolver.h"
#include "Zone/Definition/ZoneDefWriter.h" #include "Zone/Definition/ZoneDefWriter.h"
#include "ZoneLoading.h" #include "ZoneLoading.h"
@@ -18,7 +18,6 @@
#include <filesystem> #include <filesystem>
#include <format> #include <format>
#include <fstream> #include <fstream>
#include <regex>
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -27,7 +26,7 @@ namespace
class UnlinkerImpl : public Unlinker class UnlinkerImpl : public Unlinker
{ {
public: public:
UnlinkerImpl(UnlinkerArgs args) explicit UnlinkerImpl(UnlinkerArgs args)
: m_args(std::move(args)) : m_args(std::move(args))
{ {
} }
@@ -96,34 +95,27 @@ namespace
void UpdateAssetIncludesAndExcludes(const AssetDumpingContext& context) const void UpdateAssetIncludesAndExcludes(const AssetDumpingContext& context) const
{ {
const auto assetTypeCount = context.m_zone.m_pools->GetAssetTypeCount(); const auto gameId = context.m_zone.m_game_id;
const auto* game = IGame::GetGameById(gameId);
const auto assetTypeCount = game->GetAssetTypeCount();
ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector<bool>(assetTypeCount); const auto initialValue = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::EXCLUDE;
ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector(assetTypeCount, initialValue);
std::vector<bool> handledSpecifiedAssets(m_args.m_specified_asset_types.size()); std::vector<bool> handledSpecifiedAssets(m_args.m_specified_asset_types.size());
for (auto i = 0u; i < assetTypeCount; i++) const AssetNameResolver assetNameResolver(gameId);
{
const auto assetTypeName = std::string(*context.m_zone.m_pools->GetAssetTypeName(i));
const auto foundSpecifiedEntry = m_args.m_specified_asset_type_map.find(assetTypeName);
if (foundSpecifiedEntry != m_args.m_specified_asset_type_map.end())
{
ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::INCLUDE;
assert(foundSpecifiedEntry->second < handledSpecifiedAssets.size());
handledSpecifiedAssets[foundSpecifiedEntry->second] = true;
}
else
ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::EXCLUDE;
}
auto anySpecifiedValueInvalid = false; auto anySpecifiedValueInvalid = false;
for (auto i = 0u; i < handledSpecifiedAssets.size(); i++) for (const auto& specifiedValue : m_args.m_specified_asset_types)
{ {
if (!handledSpecifiedAssets[i]) const auto maybeAssetType = assetNameResolver.GetAssetTypeByName(specifiedValue);
if (!maybeAssetType)
{ {
con::error("Unknown asset type \"{}\"", m_args.m_specified_asset_types[i]); con::error("Unknown asset type \"{}\"", specifiedValue);
anySpecifiedValueInvalid = true; anySpecifiedValueInvalid = true;
continue;
} }
ObjWriting::Configuration.AssetTypesToHandleBitfield[*maybeAssetType] = !initialValue;
} }
if (anySpecifiedValueInvalid) if (anySpecifiedValueInvalid)
@@ -134,7 +126,7 @@ namespace
std::ostringstream ss; std::ostringstream ss;
for (auto i = 0u; i < assetTypeCount; i++) for (auto i = 0u; i < assetTypeCount; i++)
{ {
const auto assetTypeName = std::string(*context.m_zone.m_pools->GetAssetTypeName(i)); const auto assetTypeName = std::string(*game->GetAssetTypeName(i));
if (first) if (first)
first = false; first = false;

View File

@@ -35,7 +35,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxTrailDef // FxTrailDef
use FxTrailDef; use FxTrailDef;

View File

@@ -7,7 +7,7 @@ set string szInternalName;
set string szDisplayName; set string szDisplayName;
set string szOverlayName; set string szOverlayName;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set string szModeName; set string szModeName;
set scriptstring hideTags; set scriptstring hideTags;
set scriptstring notetrackSoundMapKeys; set scriptstring notetrackSoundMapKeys;

View File

@@ -37,7 +37,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxElemExtendedDefPtr // FxElemExtendedDefPtr
use FxElemExtendedDefPtr; use FxElemExtendedDefPtr;

View File

@@ -10,7 +10,7 @@ set reusable hideTags;
set scriptstring hideTags; set scriptstring hideTags;
set count hideTags 32; set count hideTags 32;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set reusable szXAnims; set reusable szXAnims;
set count szXAnims 37; set count szXAnims 37;
set string szAltWeaponName; set string szAltWeaponName;
@@ -26,11 +26,11 @@ set reusable gunXModel;
set count gunXModel 16; set count gunXModel 16;
set reusable szXAnimsRightHanded; set reusable szXAnimsRightHanded;
set string szXAnimsRightHanded; set string szXAnimsRightHanded;
set assetref szXAnimsRightHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsRightHanded AssetXAnim;
set count szXAnimsRightHanded 37; set count szXAnimsRightHanded 37;
set reusable szXAnimsLeftHanded; set reusable szXAnimsLeftHanded;
set string szXAnimsLeftHanded; set string szXAnimsLeftHanded;
set assetref szXAnimsLeftHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsLeftHanded AssetXAnim;
set count szXAnimsLeftHanded 37; set count szXAnimsLeftHanded 37;
set string szModeName; set string szModeName;
set reusable notetrackSoundMapKeys; set reusable notetrackSoundMapKeys;

View File

@@ -38,7 +38,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxElemExtendedDefPtr // FxElemExtendedDefPtr
use FxElemExtendedDefPtr; use FxElemExtendedDefPtr;

View File

@@ -16,7 +16,7 @@ set count underBarrels 3;
set reusable others; set reusable others;
set count others 4; set count others 4;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set reusable szXAnims; set reusable szXAnims;
set count szXAnims WEAP_ANIM_COUNT; set count szXAnims WEAP_ANIM_COUNT;
set reusable animOverrides; set reusable animOverrides;
@@ -39,8 +39,8 @@ set count aiVsPlayerAccuracyGraphKnots aiVsPlayerAccuracyGraphKnotCount;
use AnimOverrideEntry; use AnimOverrideEntry;
set string overrideAnim; set string overrideAnim;
set string altmodeAnim; set string altmodeAnim;
set assetref overrideAnim ASSET_TYPE_XANIMPARTS; set assetref overrideAnim AssetXAnim;
set assetref altmodeAnim ASSET_TYPE_XANIMPARTS; set assetref altmodeAnim AssetXAnim;
// NoteTrackToSoundEntry // NoteTrackToSoundEntry
use NoteTrackToSoundEntry; use NoteTrackToSoundEntry;
@@ -58,11 +58,11 @@ set reusable gunXModel;
set count gunXModel 16; set count gunXModel 16;
set reusable szXAnimsRightHanded; set reusable szXAnimsRightHanded;
set string szXAnimsRightHanded; set string szXAnimsRightHanded;
set assetref szXAnimsRightHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsRightHanded AssetXAnim;
set count szXAnimsRightHanded WEAP_ANIM_COUNT; set count szXAnimsRightHanded WEAP_ANIM_COUNT;
set reusable szXAnimsLeftHanded; set reusable szXAnimsLeftHanded;
set string szXAnimsLeftHanded; set string szXAnimsLeftHanded;
set assetref szXAnimsLeftHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsLeftHanded AssetXAnim;
set count szXAnimsLeftHanded WEAP_ANIM_COUNT; set count szXAnimsLeftHanded WEAP_ANIM_COUNT;
set string szModeName; set string szModeName;
set reusable notetrackSoundMapKeys; set reusable notetrackSoundMapKeys;
@@ -121,4 +121,4 @@ set condition sound never;
// snd_alias_list_name // snd_alias_list_name
use snd_alias_list_name; use snd_alias_list_name;
set string soundName; set string soundName;
set assetref soundName ASSET_TYPE_SOUND; set assetref soundName AssetSound;

View File

@@ -37,7 +37,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxTrailDef // FxTrailDef
use FxTrailDef; use FxTrailDef;

View File

@@ -8,7 +8,7 @@ set reusable weapDef;
set string szDisplayName; set string szDisplayName;
set string szAltWeaponName; set string szAltWeaponName;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set count szXAnims NUM_WEAP_ANIMS; set count szXAnims NUM_WEAP_ANIMS;
set reusable szXAnims; set reusable szXAnims;
set scriptstring hideTags; set scriptstring hideTags;

View File

@@ -38,7 +38,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxElemExtendedDefPtr // FxElemExtendedDefPtr
use FxElemExtendedDefPtr; use FxElemExtendedDefPtr;

View File

@@ -12,7 +12,7 @@ set reusable hideTags;
set string viewModelTag; set string viewModelTag;
set string worldModelTag; set string worldModelTag;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set count szXAnims 88; set count szXAnims 88;
set reusable szXAnims; set reusable szXAnims;
set count locationDamageMultipliers 21; set count locationDamageMultipliers 21;

View File

@@ -13,7 +13,7 @@ set reusable attachments;
set count attachmentUniques 95; set count attachmentUniques 95;
set reusable attachmentUniques; set reusable attachmentUniques;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set count szXAnims NUM_WEAP_ANIMS; set count szXAnims NUM_WEAP_ANIMS;
set reusable szXAnims; set reusable szXAnims;
set scriptstring hideTags; set scriptstring hideTags;

View File

@@ -8,7 +8,6 @@ MemberInformation::MemberInformation(StructureInformation* parent, StructureInfo
m_is_script_string(false), m_is_script_string(false),
m_is_reusable(false), m_is_reusable(false),
m_is_leaf(false), m_is_leaf(false),
m_fast_file_block(nullptr), m_fast_file_block(nullptr)
m_asset_ref(nullptr)
{ {
} }

View File

@@ -25,5 +25,5 @@ public:
std::unique_ptr<IEvaluation> m_alloc_alignment; std::unique_ptr<IEvaluation> m_alloc_alignment;
std::unique_ptr<CustomAction> m_post_load_action; std::unique_ptr<CustomAction> m_post_load_action;
const FastFileBlock* m_fast_file_block; const FastFileBlock* m_fast_file_block;
const EnumMember* m_asset_ref; std::string m_asset_ref;
}; };

View File

@@ -397,22 +397,22 @@ namespace
{ {
if (modifier.IsArray()) if (modifier.IsArray())
{ {
LINEF("MarkArray_IndirectAssetRef({0}, {1}, {2});", LINEF("MarkArray_IndirectAssetRef({0}::EnumEntry, {1}, {2});",
member->m_asset_ref->m_name, member->m_asset_ref,
MakeMemberAccess(info, member, modifier), MakeMemberAccess(info, member, modifier),
modifier.GetArraySize()) modifier.GetArraySize())
} }
else else
{ {
LINEF("MarkArray_IndirectAssetRef({0}, {1}, {2});", LINEF("MarkArray_IndirectAssetRef({0}::EnumEntry, {1}, {2});",
member->m_asset_ref->m_name, member->m_asset_ref,
MakeMemberAccess(info, member, modifier), MakeMemberAccess(info, member, modifier),
MakeEvaluation(modifier.GetPointerArrayCountEvaluation())) MakeEvaluation(modifier.GetPointerArrayCountEvaluation()))
} }
} }
else if (loadType == MemberLoadType::SINGLE_POINTER) else if (loadType == MemberLoadType::SINGLE_POINTER)
{ {
LINEF("Mark_IndirectAssetRef({0}, {1});", member->m_asset_ref->m_name, MakeMemberAccess(info, member, modifier)) LINEF("Mark_IndirectAssetRef({0}::EnumEntry, {1});", member->m_asset_ref, MakeMemberAccess(info, member, modifier))
} }
else else
{ {
@@ -505,7 +505,7 @@ namespace
{ {
MarkMember_ScriptString(info, member, modifier, loadType); MarkMember_ScriptString(info, member, modifier, loadType);
} }
else if (member->m_asset_ref) else if (!member->m_asset_ref.empty())
{ {
MarkMember_AssetRef(info, member, modifier, loadType); MarkMember_AssetRef(info, member, modifier, loadType);
} }
@@ -740,7 +740,7 @@ namespace
if (computations.ShouldIgnore() || computations.IsInRuntimeBlock()) if (computations.ShouldIgnore() || computations.IsInRuntimeBlock())
return; return;
if (member->m_is_script_string || member->m_asset_ref if (member->m_is_script_string || !member->m_asset_ref.empty()
|| member->m_type && (member->m_type->m_requires_marking || StructureComputations(member->m_type).IsAsset())) || member->m_type && (member->m_type->m_requires_marking || StructureComputations(member->m_type).IsAsset()))
{ {
if (info->m_definition->GetType() == DataDefinitionType::UNION) if (info->m_definition->GetType() == DataDefinitionType::UNION)

View File

@@ -5,8 +5,8 @@
namespace namespace
{ {
static constexpr auto CAPTURE_TYPE = 1; constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ASSET_NAME = 2; constexpr auto CAPTURE_ASSET_NAME = 2;
} // namespace } // namespace
SequenceAsset::SequenceAsset() SequenceAsset::SequenceAsset()
@@ -31,7 +31,7 @@ void SequenceAsset::ProcessMatch(CommandsParserState* state, SequenceResult<Comm
if (definition == nullptr) if (definition == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Unknown type"); throw ParsingException(typeNameToken.GetPos(), "Unknown type");
auto* definitionWithMembers = dynamic_cast<DefinitionWithMembers*>(definition); const auto* definitionWithMembers = dynamic_cast<DefinitionWithMembers*>(definition);
if (definitionWithMembers == nullptr) if (definitionWithMembers == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Type must be struct or union"); throw ParsingException(typeNameToken.GetPos(), "Type must be struct or union");

View File

@@ -7,10 +7,17 @@
namespace namespace
{ {
static constexpr auto TAG_DEFAULT = 1; constexpr auto CAPTURE_TYPE = 1;
constexpr auto CAPTURE_ASSET_NAME = 2;
static constexpr auto CAPTURE_TYPE = 1; bool AssetWithNameIsKnown(const std::string& assetName, const IDataRepository& repository)
static constexpr auto CAPTURE_ASSET_TYPE_ENUM_ENTRY = 2; {
return std::ranges::any_of(repository.GetAllStructureInformation(),
[&assetName](const StructureInformation* info)
{
return !info->m_asset_name.empty() && info->m_asset_name == assetName;
});
}
} // namespace } // namespace
SequenceAssetRef::SequenceAssetRef() SequenceAssetRef::SequenceAssetRef()
@@ -22,17 +29,18 @@ SequenceAssetRef::SequenceAssetRef()
create.Keyword("set"), create.Keyword("set"),
create.Keyword("assetref"), create.Keyword("assetref"),
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
create.Identifier().Capture(CAPTURE_ASSET_TYPE_ENUM_ENTRY), create.Identifier().Capture(CAPTURE_ASSET_NAME),
create.Char(';'), create.Char(';'),
}); });
} }
void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{ {
const auto& enumEntryToken = result.NextCapture(CAPTURE_ASSET_TYPE_ENUM_ENTRY); const auto& assetNameToken = result.NextCapture(CAPTURE_ASSET_NAME);
const auto* enumMember = state->GetRepository()->GetEnumMemberByName(enumEntryToken.IdentifierValue()); auto assetName = assetNameToken.IdentifierValue();
if (enumMember == nullptr)
throw ParsingException(enumEntryToken.GetPos(), "Unknown asset type enum entry"); if (!AssetWithNameIsKnown(assetName, *state->GetRepository()))
throw ParsingException(assetNameToken.GetPos(), "No asset with this name");
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE); const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
@@ -75,5 +83,5 @@ void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<C
if (typeDecl->m_type->GetType() != DataDefinitionType::BASE_TYPE) if (typeDecl->m_type->GetType() != DataDefinitionType::BASE_TYPE)
throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a base type"); throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a base type");
lastMember->m_asset_ref = enumMember; lastMember->m_asset_ref = std::move(assetName);
} }

View File

@@ -47,7 +47,7 @@ namespace
continue; continue;
// Any script strings, asset refs and assets need to be processed. // Any script strings, asset refs and assets need to be processed.
if (member->m_is_script_string || member->m_asset_ref || member->m_type && StructureComputations(member->m_type).IsAsset()) if (member->m_is_script_string || !member->m_asset_ref.empty() || member->m_type && StructureComputations(member->m_type).IsAsset())
{ {
info->m_requires_marking = true; info->m_requires_marking = true;
return true; return true;

View File

@@ -1,22 +0,0 @@
#include "AssetNameResolverIW3.h"
#include "Game/IW3/GameAssetPoolIW3.h"
#include "Utils/StringUtils.h"
using namespace IW3;
AssetNameResolver::AssetNameResolver()
{
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
AddAssetTypeName(assetType, *GameAssetPoolIW3::AssetTypeNameByType(assetType));
}
GameId AssetNameResolver::GetGameId() const
{
return GameId::IW3;
}
std::optional<const char*> AssetNameResolver::GetAssetTypeName(const asset_type_t assetType) const
{
return GameAssetPoolIW3::AssetTypeNameByType(assetType);
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Zone/AssetNameResolver.h"
namespace IW3
{
class AssetNameResolver final : public HashMapBasedAssetNameResolver
{
public:
AssetNameResolver();
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
};
} // namespace IW3

View File

@@ -3,26 +3,13 @@
#include "Pool/AssetPoolDynamic.h" #include "Pool/AssetPoolDynamic.h"
#include <cassert> #include <cassert>
#include <type_traits>
using namespace IW3; using namespace IW3;
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"xmodelpieces", "physpreset", "xanim", "xmodel", "material", "techniqueset", "image", "sound", "soundcurve", "loadedsound",
"clipmap_unused", "clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents", "gfxworld", "lightdef", "uimap", "font",
"menulist", "menu", "localize", "weapon", "snddriverglobals", "fx", "impactfx", "aitype", "mptype", "character",
"xmodelalias", "rawfile", "stringtable",
};
}
GameAssetPoolIW3::GameAssetPoolIW3(Zone* zone, const zone_priority_t priority) GameAssetPoolIW3::GameAssetPoolIW3(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone), : ZoneAssetPools(zone),
m_priority(priority) m_priority(priority)
{ {
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority) #define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
INIT_POOL(m_phys_preset); INIT_POOL(m_phys_preset);
@@ -151,26 +138,3 @@ XAssetInfoGeneric* GameAssetPoolIW3::GetAsset(const asset_type_t type, const std
#undef CASE_GET_ASSET #undef CASE_GET_ASSET
} }
std::optional<const char*> GameAssetPoolIW3::AssetTypeNameByType(const asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent_v<decltype(ASSET_TYPE_NAMES)>))
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
std::optional<const char*> GameAssetPoolIW3::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}
asset_type_t GameAssetPoolIW3::AssetTypeCount()
{
return ASSET_TYPE_COUNT;
}
asset_type_t GameAssetPoolIW3::GetAssetTypeCount() const
{
return AssetTypeCount();
}

View File

@@ -5,7 +5,6 @@
#include "Pool/ZoneAssetPools.h" #include "Pool/ZoneAssetPools.h"
#include <memory> #include <memory>
#include <optional>
class GameAssetPoolIW3 final : public ZoneAssetPools class GameAssetPoolIW3 final : public ZoneAssetPools
{ {
@@ -41,12 +40,6 @@ public:
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; [[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected: protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override; XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;

View File

@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
{ {
const auto* game = IGame::GetGameById(zone.m_game_id);
const auto* pools = dynamic_cast<GameAssetPoolIW3*>(zone.m_pools.get()); const auto* pools = dynamic_cast<GameAssetPoolIW3*>(zone.m_pools.get());
assert(pools); assert(pools);
@@ -18,7 +19,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
// Localized strings are all collected in one string file. So only add this to the zone file. // Localized strings are all collected in one string file. So only add this to the zone file.
if (!pools->m_localize->m_asset_lookup.empty()) if (!pools->m_localize->m_asset_lookup.empty())
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name); stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
for (const auto& asset : *pools) for (const auto& asset : *pools)
{ {
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
break; break;
default: default:
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name); stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
break; break;
} }
} }

View File

@@ -1,22 +0,0 @@
#include "AssetNameResolverIW4.h"
#include "Game/IW4/GameAssetPoolIW4.h"
#include "Utils/StringUtils.h"
using namespace IW4;
AssetNameResolver::AssetNameResolver()
{
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
AddAssetTypeName(assetType, *GameAssetPoolIW4::AssetTypeNameByType(assetType));
}
GameId AssetNameResolver::GetGameId() const
{
return GameId::IW4;
}
std::optional<const char*> AssetNameResolver::GetAssetTypeName(const asset_type_t assetType) const
{
return GameAssetPoolIW4::AssetTypeNameByType(assetType);
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Zone/AssetNameResolver.h"
namespace IW4
{
class AssetNameResolver final : public HashMapBasedAssetNameResolver
{
public:
AssetNameResolver();
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
};
} // namespace IW4

View File

@@ -3,31 +3,13 @@
#include "Pool/AssetPoolDynamic.h" #include "Pool/AssetPoolDynamic.h"
#include <cassert> #include <cassert>
#include <type_traits>
using namespace IW4; using namespace IW4;
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"physpreset", "physcollmap", "xanim", "xmodelsurfs", "xmodel",
"material", "pixelshader", "vertexshader", "vertexdecl", "techniqueset",
"image", "sound", "soundcurve", "loadedsound", "clipmap_unused",
"clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents",
"fxworld", "gfxworld", "lightdef", "uimap", "font",
"menulist", "menu", "localize", "weapon", "snddriverglobals",
"fx", "impactfx", "aitype", "mptype", "character",
"xmodelalias", "rawfile", "stringtable", "leaderboard", "structureddatadef",
"tracer", "vehicle", "addonmapents",
};
}
GameAssetPoolIW4::GameAssetPoolIW4(Zone* zone, const zone_priority_t priority) GameAssetPoolIW4::GameAssetPoolIW4(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone), : ZoneAssetPools(zone),
m_priority(priority) m_priority(priority)
{ {
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority) #define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
INIT_POOL(m_phys_preset); INIT_POOL(m_phys_preset);
@@ -186,26 +168,3 @@ XAssetInfoGeneric* GameAssetPoolIW4::GetAsset(const asset_type_t type, const std
#undef CASE_GET_ASSET #undef CASE_GET_ASSET
} }
std::optional<const char*> GameAssetPoolIW4::AssetTypeNameByType(const asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent_v<decltype(ASSET_TYPE_NAMES)>))
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
std::optional<const char*> GameAssetPoolIW4::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}
asset_type_t GameAssetPoolIW4::AssetTypeCount()
{
return ASSET_TYPE_COUNT;
}
asset_type_t GameAssetPoolIW4::GetAssetTypeCount() const
{
return AssetTypeCount();
}

View File

@@ -50,12 +50,6 @@ public:
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; [[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected: protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override; XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;

View File

@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
{ {
const auto* game = IGame::GetGameById(zone.m_game_id);
const auto* pools = dynamic_cast<GameAssetPoolIW4*>(zone.m_pools.get()); const auto* pools = dynamic_cast<GameAssetPoolIW4*>(zone.m_pools.get());
assert(pools); assert(pools);
@@ -18,7 +19,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
// Localized strings are all collected in one string file. So only add this to the zone file. // Localized strings are all collected in one string file. So only add this to the zone file.
if (!pools->m_localize->m_asset_lookup.empty()) if (!pools->m_localize->m_asset_lookup.empty())
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name); stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
for (const auto& asset : *pools) for (const auto& asset : *pools)
{ {
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
break; break;
default: default:
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name); stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
break; break;
} }
} }

View File

@@ -1,22 +0,0 @@
#include "AssetNameResolverIW5.h"
#include "Game/IW5/GameAssetPoolIW5.h"
#include "Utils/StringUtils.h"
using namespace IW5;
AssetNameResolver::AssetNameResolver()
{
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
AddAssetTypeName(assetType, *GameAssetPoolIW5::AssetTypeNameByType(assetType));
}
GameId AssetNameResolver::GetGameId() const
{
return GameId::IW5;
}
std::optional<const char*> AssetNameResolver::GetAssetTypeName(const asset_type_t assetType) const
{
return GameAssetPoolIW5::AssetTypeNameByType(assetType);
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Zone/AssetNameResolver.h"
namespace IW5
{
class AssetNameResolver final : public HashMapBasedAssetNameResolver
{
public:
AssetNameResolver();
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
};
} // namespace IW5

View File

@@ -3,68 +3,13 @@
#include "Pool/AssetPoolDynamic.h" #include "Pool/AssetPoolDynamic.h"
#include <cassert> #include <cassert>
#include <type_traits>
using namespace IW5; using namespace IW5;
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"physpreset",
"physcollmap",
"xanim",
"xmodelsurfs",
"xmodel",
"material",
"pixelshader",
"vertexshader",
"vertexdecl",
"techniqueset",
"image",
"sound",
"soundcurve",
"loadedsound",
"clipmap",
"comworld",
"glassworld",
"pathdata",
"vehicletrack",
"mapents",
"fxworld",
"gfxworld",
"lightdef",
"uimap",
"font",
"menulist",
"menu",
"localize",
"attachment",
"weapon",
"snddriverglobals",
"fx",
"impactfx",
"surfacefx",
"aitype",
"mptype",
"character",
"xmodelalias",
"rawfile",
"scriptfile",
"stringtable",
"leaderboard",
"structureddatadef",
"tracer",
"vehicle",
"addonmapents",
};
}
GameAssetPoolIW5::GameAssetPoolIW5(Zone* zone, const zone_priority_t priority) GameAssetPoolIW5::GameAssetPoolIW5(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone), : ZoneAssetPools(zone),
m_priority(priority) m_priority(priority)
{ {
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority) #define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
INIT_POOL(m_phys_preset); INIT_POOL(m_phys_preset);
@@ -236,26 +181,3 @@ XAssetInfoGeneric* GameAssetPoolIW5::GetAsset(const asset_type_t type, const std
#undef CASE_GET_ASSET #undef CASE_GET_ASSET
} }
std::optional<const char*> GameAssetPoolIW5::AssetTypeNameByType(const asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent_v<decltype(ASSET_TYPE_NAMES)>))
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
std::optional<const char*> GameAssetPoolIW5::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}
asset_type_t GameAssetPoolIW5::AssetTypeCount()
{
return ASSET_TYPE_COUNT;
}
asset_type_t GameAssetPoolIW5::GetAssetTypeCount() const
{
return AssetTypeCount();
}

View File

@@ -55,12 +55,6 @@ public:
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; [[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected: protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override; XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;

View File

@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
{ {
const auto* game = IGame::GetGameById(zone.m_game_id);
const auto* pools = dynamic_cast<GameAssetPoolIW5*>(zone.m_pools.get()); const auto* pools = dynamic_cast<GameAssetPoolIW5*>(zone.m_pools.get());
assert(pools); assert(pools);
@@ -18,7 +19,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
// Localized strings are all collected in one string file. So only add this to the zone file. // Localized strings are all collected in one string file. So only add this to the zone file.
if (!pools->m_localize->m_asset_lookup.empty()) if (!pools->m_localize->m_asset_lookup.empty())
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name); stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
for (const auto& asset : *pools) for (const auto& asset : *pools)
{ {
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
break; break;
default: default:
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name); stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
break; break;
} }
} }

View File

@@ -1,22 +0,0 @@
#include "AssetNameResolverT5.h"
#include "Game/T5/GameAssetPoolT5.h"
#include "Utils/StringUtils.h"
using namespace T5;
AssetNameResolver::AssetNameResolver()
{
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
AddAssetTypeName(assetType, *GameAssetPoolT5::AssetTypeNameByType(assetType));
}
GameId AssetNameResolver::GetGameId() const
{
return GameId::T5;
}
std::optional<const char*> AssetNameResolver::GetAssetTypeName(const asset_type_t assetType) const
{
return GameAssetPoolT5::AssetTypeNameByType(assetType);
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Zone/AssetNameResolver.h"
namespace T5
{
class AssetNameResolver final : public HashMapBasedAssetNameResolver
{
public:
AssetNameResolver();
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
};
} // namespace T5

View File

@@ -3,29 +3,13 @@
#include "Pool/AssetPoolDynamic.h" #include "Pool/AssetPoolDynamic.h"
#include <cassert> #include <cassert>
#include <type_traits>
using namespace T5; using namespace T5;
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"xmodelpieces", "physpreset", "physconstraints", "destructibledef", "xanim", "xmodel", "material",
"techniqueset", "image", "soundbank", "soundpatch", "clipmap_unused", "clipmap", "comworld",
"gameworldsp", "gameworldmp", "mapents", "gfxworld", "gfxlightdef", "uimap", "font",
"menulist", "menu", "localize", "weapon", "weapondef", "weaponvariant", "snddriverglobals",
"fx", "fximpacttable", "aitype", "mptype", "mpbody", "mphead", "character",
"xmodelalias", "rawfile", "stringtable", "packindex", "xglobals", "ddl", "glasses",
"emblemset",
};
}
GameAssetPoolT5::GameAssetPoolT5(Zone* zone, const zone_priority_t priority) GameAssetPoolT5::GameAssetPoolT5(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone), : ZoneAssetPools(zone),
m_priority(priority) m_priority(priority)
{ {
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority) #define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
INIT_POOL(m_phys_preset); INIT_POOL(m_phys_preset);
@@ -175,26 +159,3 @@ XAssetInfoGeneric* GameAssetPoolT5::GetAsset(const asset_type_t type, const std:
#undef CASE_GET_ASSET #undef CASE_GET_ASSET
} }
std::optional<const char*> GameAssetPoolT5::AssetTypeNameByType(const asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent_v<decltype(ASSET_TYPE_NAMES)>))
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
std::optional<const char*> GameAssetPoolT5::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}
asset_type_t GameAssetPoolT5::AssetTypeCount()
{
return ASSET_TYPE_COUNT;
}
asset_type_t GameAssetPoolT5::GetAssetTypeCount() const
{
return AssetTypeCount();
}

View File

@@ -47,12 +47,6 @@ public:
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; [[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected: protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override; XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;

View File

@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
{ {
const auto* game = IGame::GetGameById(zone.m_game_id);
const auto* pools = dynamic_cast<GameAssetPoolT5*>(zone.m_pools.get()); const auto* pools = dynamic_cast<GameAssetPoolT5*>(zone.m_pools.get());
assert(pools); assert(pools);
@@ -18,7 +19,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
// Localized strings are all collected in one string file. So only add this to the zone file. // Localized strings are all collected in one string file. So only add this to the zone file.
if (!pools->m_localize->m_asset_lookup.empty()) if (!pools->m_localize->m_asset_lookup.empty())
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name); stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
for (const auto& asset : *pools) for (const auto& asset : *pools)
{ {
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
break; break;
default: default:
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name); stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
break; break;
} }
} }

View File

@@ -1,22 +0,0 @@
#include "AssetNameResolverT6.h"
#include "Game/T6/GameAssetPoolT6.h"
#include "Utils/StringUtils.h"
using namespace T6;
AssetNameResolver::AssetNameResolver()
{
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
AddAssetTypeName(assetType, *GameAssetPoolT6::AssetTypeNameByType(assetType));
}
GameId AssetNameResolver::GetGameId() const
{
return GameId::T6;
}
std::optional<const char*> AssetNameResolver::GetAssetTypeName(const asset_type_t assetType) const
{
return GameAssetPoolT6::AssetTypeNameByType(assetType);
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Zone/AssetNameResolver.h"
namespace T6
{
class AssetNameResolver final : public HashMapBasedAssetNameResolver
{
public:
AssetNameResolver();
[[nodiscard]] GameId GetGameId() const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
};
} // namespace T6

View File

@@ -3,82 +3,13 @@
#include "Pool/AssetPoolDynamic.h" #include "Pool/AssetPoolDynamic.h"
#include <cassert> #include <cassert>
#include <type_traits>
using namespace T6; using namespace T6;
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"xmodelpieces",
"physpreset",
"physconstraints",
"destructibledef",
"xanim",
"xmodel",
"material",
"techniqueset",
"image",
"soundbank",
"soundpatch",
"clipmap_unused",
"clipmap",
"comworld",
"gameworldsp",
"gameworldmp",
"mapents",
"gfxworld",
"gfxlightdef",
"uimap",
"font",
"fonticon",
"menulist",
"menu",
"localize",
"weapon",
"weapondef",
"weaponvariant",
"weaponfull",
"attachment",
"attachmentunique",
"camo",
"snddriverglobals",
"fx",
"fximpacttable",
"aitype",
"mptype",
"mpbody",
"mphead",
"character",
"xmodelalias",
"rawfile",
"stringtable",
"leaderboard",
"xglobals",
"ddl",
"glasses",
"emblemset",
"script",
"keyvaluepairs",
"vehicle",
"memoryblock",
"addonmapents",
"tracer",
"skinnedverts",
"qdb",
"slug",
"footsteptable",
"footstepfxtable",
"zbarrier",
};
} // namespace
GameAssetPoolT6::GameAssetPoolT6(Zone* zone, const zone_priority_t priority) GameAssetPoolT6::GameAssetPoolT6(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone), : ZoneAssetPools(zone),
m_priority(priority) m_priority(priority)
{ {
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority) #define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
INIT_POOL(m_phys_preset); INIT_POOL(m_phys_preset);
@@ -276,26 +207,3 @@ XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, const std:
#undef CASE_GET_ASSET #undef CASE_GET_ASSET
} }
std::optional<const char*> GameAssetPoolT6::AssetTypeNameByType(const asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent_v<decltype(ASSET_TYPE_NAMES)>))
return ASSET_TYPE_NAMES[assetType];
return std::nullopt;
}
std::optional<const char*> GameAssetPoolT6::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}
asset_type_t GameAssetPoolT6::AssetTypeCount()
{
return ASSET_TYPE_COUNT;
}
asset_type_t GameAssetPoolT6::GetAssetTypeCount() const
{
return AssetTypeCount();
}

View File

@@ -63,12 +63,6 @@ public:
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; [[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected: protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override; XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;

View File

@@ -66,6 +66,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
{ {
const auto* game = IGame::GetGameById(zone.m_game_id);
const auto* pools = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get()); const auto* pools = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
assert(pools); assert(pools);
@@ -74,7 +75,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
// Localized strings are all collected in one string file. So only add this to the zone file. // Localized strings are all collected in one string file. So only add this to the zone file.
if (!pools->m_localize->m_asset_lookup.empty()) if (!pools->m_localize->m_asset_lookup.empty())
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name); stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
for (const auto& asset : *pools) for (const auto& asset : *pools)
{ {
@@ -85,7 +86,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
break; break;
default: default:
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name); stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
break; break;
} }
} }

View File

@@ -36,9 +36,6 @@ public:
[[nodiscard]] virtual XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const = 0; [[nodiscard]] virtual XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const = 0;
[[nodiscard]] virtual XAssetInfoGeneric* GetAssetOrAssetReference(asset_type_t type, const std::string& name) const; [[nodiscard]] virtual XAssetInfoGeneric* GetAssetOrAssetReference(asset_type_t type, const std::string& name) const;
[[nodiscard]] virtual asset_type_t GetAssetTypeCount() const = 0;
[[nodiscard]] virtual std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const = 0;
[[nodiscard]] size_t GetTotalAssetCount() const; [[nodiscard]] size_t GetTotalAssetCount() const;
[[nodiscard]] iterator begin() const; [[nodiscard]] iterator begin() const;

View File

@@ -2,13 +2,13 @@
AssetListOutputStream::AssetListOutputStream(std::ostream& stream, const GameId game) AssetListOutputStream::AssetListOutputStream(std::ostream& stream, const GameId game)
: m_stream(stream), : m_stream(stream),
m_asset_name_resolver(IAssetNameResolver::GetResolverForGame(game)) m_game(IGame::GetGameById(game))
{ {
} }
void AssetListOutputStream::WriteEntry(const AssetListEntry& entry) void AssetListOutputStream::WriteEntry(const AssetListEntry& entry)
{ {
m_stream.WriteColumn(*m_asset_name_resolver->GetAssetTypeName(entry.m_type)); m_stream.WriteColumn(*m_game->GetAssetTypeName(entry.m_type));
m_stream.WriteColumn(entry.m_name); m_stream.WriteColumn(entry.m_name);
m_stream.NextRow(); m_stream.NextRow();
} }

View File

@@ -3,7 +3,6 @@
#include "AssetList.h" #include "AssetList.h"
#include "Csv/CsvStream.h" #include "Csv/CsvStream.h"
#include "Game/IGame.h" #include "Game/IGame.h"
#include "Zone/AssetNameResolver.h"
#include <iostream> #include <iostream>
@@ -16,5 +15,5 @@ public:
private: private:
CsvOutputStream m_stream; CsvOutputStream m_stream;
const IAssetNameResolver* m_asset_name_resolver; const IGame* m_game;
}; };

View File

@@ -12,9 +12,9 @@ namespace
class AssetListInputStream class AssetListInputStream
{ {
public: public:
AssetListInputStream(std::istream& stream, GameId game) AssetListInputStream(std::istream& stream, const GameId game)
: m_stream(stream), : m_stream(stream),
m_asset_name_resolver(IAssetNameResolver::GetResolverForGame(game)) m_asset_name_resolver(game)
{ {
} }
@@ -33,7 +33,7 @@ namespace
continue; continue;
const auto& typeName = row[0]; const auto& typeName = row[0];
const auto maybeType = m_asset_name_resolver->GetAssetTypeByName(typeName); const auto maybeType = m_asset_name_resolver.GetAssetTypeByName(typeName);
if (!maybeType) if (!maybeType)
{ {
con::error("Unknown asset type name \"{}\"", typeName); con::error("Unknown asset type name \"{}\"", typeName);
@@ -60,7 +60,7 @@ namespace
private: private:
CsvInputStream m_stream; CsvInputStream m_stream;
const IAssetNameResolver* m_asset_name_resolver; AssetNameResolver m_asset_name_resolver;
}; };
} // namespace } // namespace

View File

@@ -1,38 +1,28 @@
#include "AssetNameResolver.h" #include "AssetNameResolver.h"
#include "Game/IW3/AssetNameResolverIW3.h"
#include "Game/IW4/AssetNameResolverIW4.h"
#include "Game/IW5/AssetNameResolverIW5.h"
#include "Game/T5/AssetNameResolverT5.h"
#include "Game/T6/AssetNameResolverT6.h"
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
#include <cassert> #include <cassert>
const IAssetNameResolver* IAssetNameResolver::GetResolverForGame(GameId game) AssetNameResolver::AssetNameResolver(const GameId gameId)
{ {
static const IAssetNameResolver* assetNameResolvers[static_cast<unsigned>(GameId::COUNT)]{ const auto* game = IGame::GetGameById(gameId);
new IW3::AssetNameResolver(), const auto assetTypeCount = game->GetAssetTypeCount();
new IW4::AssetNameResolver(),
new IW5::AssetNameResolver(),
new T5::AssetNameResolver(),
new T6::AssetNameResolver(),
};
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT)); for (asset_type_t assetType = 0; assetType < assetTypeCount; assetType++)
const auto* result = assetNameResolvers[static_cast<unsigned>(game)]; {
assert(result); auto maybeAssetTypeName = game->GetAssetTypeName(assetType);
assert(maybeAssetTypeName);
if (!maybeAssetTypeName)
continue;
return result; std::string lowerCaseName(*maybeAssetTypeName);
utils::MakeStringLowerCase(lowerCaseName);
m_asset_types_by_name.emplace(lowerCaseName, assetType);
}
} }
void HashMapBasedAssetNameResolver::AddAssetTypeName(asset_type_t assetType, std::string name) std::optional<asset_type_t> AssetNameResolver::GetAssetTypeByName(const std::string& assetTypeName) const
{
utils::MakeStringLowerCase(name);
m_asset_types_by_name.emplace(std::move(name), assetType);
}
std::optional<asset_type_t> HashMapBasedAssetNameResolver::GetAssetTypeByName(const std::string& assetTypeName) const
{ {
std::string lowerCaseName = assetTypeName; std::string lowerCaseName = assetTypeName;
utils::MakeStringLowerCase(lowerCaseName); utils::MakeStringLowerCase(lowerCaseName);

View File

@@ -7,30 +7,13 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
class IAssetNameResolver class AssetNameResolver
{ {
public: public:
IAssetNameResolver() = default; AssetNameResolver() = default;
virtual ~IAssetNameResolver() = default; explicit AssetNameResolver(GameId gameId);
IAssetNameResolver(const IAssetNameResolver& other) = default;
IAssetNameResolver(IAssetNameResolver&& other) noexcept = default;
IAssetNameResolver& operator=(const IAssetNameResolver& other) = default;
IAssetNameResolver& operator=(IAssetNameResolver&& other) noexcept = default;
[[nodiscard]] virtual GameId GetGameId() const = 0; [[nodiscard]] std::optional<asset_type_t> GetAssetTypeByName(const std::string& assetTypeName) const;
[[nodiscard]] virtual std::optional<asset_type_t> GetAssetTypeByName(const std::string& assetTypeName) const = 0;
[[nodiscard]] virtual std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const = 0;
static const IAssetNameResolver* GetResolverForGame(GameId game);
};
class HashMapBasedAssetNameResolver : public IAssetNameResolver
{
public:
[[nodiscard]] std::optional<asset_type_t> GetAssetTypeByName(const std::string& assetTypeName) const override;
protected:
void AddAssetTypeName(asset_type_t assetType, std::string name);
private: private:
std::unordered_map<std::string, asset_type_t> m_asset_types_by_name; std::unordered_map<std::string, asset_type_t> m_asset_types_by_name;

View File

@@ -23,10 +23,7 @@ void SequenceZoneDefinitionEntry::ProcessMatch(ZoneDefinitionParserState* state,
{ {
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE_NAME); const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE_NAME);
if (!state->m_asset_name_resolver) const auto maybeAssetType = state->m_asset_name_resolver.GetAssetTypeByName(typeNameToken.FieldValue());
throw ParsingException(typeNameToken.GetPos(), "Must define game before first asset");
const auto maybeAssetType = state->m_asset_name_resolver->GetAssetTypeByName(typeNameToken.FieldValue());
if (!maybeAssetType) if (!maybeAssetType)
throw ParsingException(typeNameToken.GetPos(), "Unknown asset type"); throw ParsingException(typeNameToken.GetPos(), "Unknown asset type");

View File

@@ -5,7 +5,6 @@
ZoneDefinitionParserState::ZoneDefinitionParserState(std::string targetName, ISearchPath& searchPath, IParserLineStream& underlyingStream) ZoneDefinitionParserState::ZoneDefinitionParserState(std::string targetName, ISearchPath& searchPath, IParserLineStream& underlyingStream)
: m_search_path(searchPath), : m_search_path(searchPath),
m_underlying_stream(underlyingStream), m_underlying_stream(underlyingStream),
m_asset_name_resolver(nullptr),
m_definition(std::make_unique<ZoneDefinition>()) m_definition(std::make_unique<ZoneDefinition>())
{ {
@@ -16,7 +15,7 @@ ZoneDefinitionParserState::ZoneDefinitionParserState(std::string targetName, ISe
void ZoneDefinitionParserState::SetGame(const GameId game) void ZoneDefinitionParserState::SetGame(const GameId game)
{ {
m_definition->m_game = game; m_definition->m_game = game;
m_asset_name_resolver = IAssetNameResolver::GetResolverForGame(game); m_asset_name_resolver = AssetNameResolver(game);
} }
namespace namespace

View File

@@ -26,7 +26,7 @@ public:
IParserLineStream& m_underlying_stream; IParserLineStream& m_underlying_stream;
std::unordered_set<std::string> m_inclusions; std::unordered_set<std::string> m_inclusions;
const IAssetNameResolver* m_asset_name_resolver; AssetNameResolver m_asset_name_resolver;
std::optional<ZoneDefinitionObjContainer> m_current_ipak; std::optional<ZoneDefinitionObjContainer> m_current_ipak;
std::optional<ZoneDefinitionObjContainer> m_current_iwd; std::optional<ZoneDefinitionObjContainer> m_current_iwd;