mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-02-10 17:43:03 +00:00
refactor: move asset type names to IGame implementations
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
IgnoredAssetLookup::IgnoredAssetLookup() = default;
|
||||
|
||||
@@ -89,7 +88,7 @@ XAssetInfoGeneric* AssetCreationContext::AddAssetGeneric(GenericAssetRegistratio
|
||||
addedAsset = m_zone.m_pools->AddAsset(std::move(xAssetInfo));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ XAssetInfoGeneric* AssetCreationContext::LoadDefaultAssetDependency(const asset_
|
||||
if (result.HasTakenAction() && !result.HasFailed())
|
||||
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;
|
||||
}
|
||||
@@ -129,11 +128,11 @@ XAssetInfoGeneric* AssetCreationContext::LoadDependencyGeneric(const asset_type_
|
||||
if (!result.HasFailed())
|
||||
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)
|
||||
{
|
||||
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;
|
||||
@@ -151,7 +150,8 @@ IndirectAssetReference AssetCreationContext::LoadIndirectAssetReferenceGeneric(c
|
||||
const auto result = m_creators->CreateAsset(assetType, assetName, *this);
|
||||
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);
|
||||
}
|
||||
@@ -187,11 +187,11 @@ XAssetInfoGeneric* AssetCreationContext::ForceLoadDependencyGeneric(const asset_
|
||||
if (!result.HasFailed())
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
class AssetCreatorCollection;
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
AssetCreatorCollection::AssetCreatorCollection(const Zone& zone)
|
||||
{
|
||||
m_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
m_asset_post_processors_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
m_default_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
m_asset_creators_by_type.resize(game->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)
|
||||
|
||||
@@ -18,7 +18,7 @@ void ContentPrinter::PrintContent() const
|
||||
con::info("Content:");
|
||||
|
||||
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("");
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "SearchPath/OutputPathFilesystem.h"
|
||||
#include "UnlinkerArgs.h"
|
||||
#include "UnlinkerPaths.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
#include "Utils/ObjFileStream.h"
|
||||
#include "Zone/AssetNameResolver.h"
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -27,7 +26,7 @@ namespace
|
||||
class UnlinkerImpl : public Unlinker
|
||||
{
|
||||
public:
|
||||
UnlinkerImpl(UnlinkerArgs args)
|
||||
explicit UnlinkerImpl(UnlinkerArgs args)
|
||||
: m_args(std::move(args))
|
||||
{
|
||||
}
|
||||
@@ -96,34 +95,27 @@ namespace
|
||||
|
||||
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());
|
||||
for (auto i = 0u; i < assetTypeCount; i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
const AssetNameResolver assetNameResolver(gameId);
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjWriting::Configuration.AssetTypesToHandleBitfield[*maybeAssetType] = !initialValue;
|
||||
}
|
||||
|
||||
if (anySpecifiedValueInvalid)
|
||||
@@ -134,7 +126,7 @@ namespace
|
||||
std::ostringstream ss;
|
||||
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)
|
||||
first = false;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -3,26 +3,13 @@
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
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)
|
||||
: ZoneAssetPools(zone),
|
||||
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)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
@@ -151,26 +138,3 @@ XAssetInfoGeneric* GameAssetPoolIW3::GetAsset(const asset_type_t type, const std
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
class GameAssetPoolIW3 final : public ZoneAssetPools
|
||||
{
|
||||
@@ -41,12 +40,6 @@ public:
|
||||
|
||||
[[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:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
|
||||
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());
|
||||
|
||||
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.
|
||||
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)
|
||||
{
|
||||
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -3,31 +3,13 @@
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
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)
|
||||
: ZoneAssetPools(zone),
|
||||
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)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
@@ -186,26 +168,3 @@ XAssetInfoGeneric* GameAssetPoolIW4::GetAsset(const asset_type_t type, const std
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -50,12 +50,6 @@ public:
|
||||
|
||||
[[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:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
|
||||
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());
|
||||
|
||||
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.
|
||||
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)
|
||||
{
|
||||
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -3,68 +3,13 @@
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
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)
|
||||
: ZoneAssetPools(zone),
|
||||
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)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
@@ -236,26 +181,3 @@ XAssetInfoGeneric* GameAssetPoolIW5::GetAsset(const asset_type_t type, const std
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -55,12 +55,6 @@ public:
|
||||
|
||||
[[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:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
|
||||
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());
|
||||
|
||||
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.
|
||||
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)
|
||||
{
|
||||
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -3,29 +3,13 @@
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
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)
|
||||
: ZoneAssetPools(zone),
|
||||
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)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
@@ -175,26 +159,3 @@ XAssetInfoGeneric* GameAssetPoolT5::GetAsset(const asset_type_t type, const std:
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -47,12 +47,6 @@ public:
|
||||
|
||||
[[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:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
|
||||
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());
|
||||
|
||||
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.
|
||||
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)
|
||||
{
|
||||
@@ -28,7 +29,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -3,82 +3,13 @@
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
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)
|
||||
: ZoneAssetPools(zone),
|
||||
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)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
@@ -276,26 +207,3 @@ XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, const std:
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -63,12 +63,6 @@ public:
|
||||
|
||||
[[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:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
|
||||
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());
|
||||
|
||||
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.
|
||||
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)
|
||||
{
|
||||
@@ -85,7 +86,7 @@ void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone&
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
stream.WriteEntry(*game->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,6 @@ public:
|
||||
[[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 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]] iterator begin() const;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
AssetListOutputStream::AssetListOutputStream(std::ostream& stream, const GameId game)
|
||||
: m_stream(stream),
|
||||
m_asset_name_resolver(IAssetNameResolver::GetResolverForGame(game))
|
||||
m_game(IGame::GetGameById(game))
|
||||
{
|
||||
}
|
||||
|
||||
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.NextRow();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "AssetList.h"
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Zone/AssetNameResolver.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -16,5 +15,5 @@ public:
|
||||
|
||||
private:
|
||||
CsvOutputStream m_stream;
|
||||
const IAssetNameResolver* m_asset_name_resolver;
|
||||
const IGame* m_game;
|
||||
};
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace
|
||||
class AssetListInputStream
|
||||
{
|
||||
public:
|
||||
AssetListInputStream(std::istream& stream, GameId game)
|
||||
AssetListInputStream(std::istream& stream, const GameId game)
|
||||
: m_stream(stream),
|
||||
m_asset_name_resolver(IAssetNameResolver::GetResolverForGame(game))
|
||||
m_asset_name_resolver(game)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace
|
||||
continue;
|
||||
|
||||
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)
|
||||
{
|
||||
con::error("Unknown asset type name \"{}\"", typeName);
|
||||
@@ -60,7 +60,7 @@ namespace
|
||||
|
||||
private:
|
||||
CsvInputStream m_stream;
|
||||
const IAssetNameResolver* m_asset_name_resolver;
|
||||
AssetNameResolver m_asset_name_resolver;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1,38 +1,28 @@
|
||||
#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 <cassert>
|
||||
|
||||
const IAssetNameResolver* IAssetNameResolver::GetResolverForGame(GameId game)
|
||||
AssetNameResolver::AssetNameResolver(const GameId gameId)
|
||||
{
|
||||
static const IAssetNameResolver* assetNameResolvers[static_cast<unsigned>(GameId::COUNT)]{
|
||||
new IW3::AssetNameResolver(),
|
||||
new IW4::AssetNameResolver(),
|
||||
new IW5::AssetNameResolver(),
|
||||
new T5::AssetNameResolver(),
|
||||
new T6::AssetNameResolver(),
|
||||
};
|
||||
const auto* game = IGame::GetGameById(gameId);
|
||||
const auto assetTypeCount = game->GetAssetTypeCount();
|
||||
|
||||
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
|
||||
const auto* result = assetNameResolvers[static_cast<unsigned>(game)];
|
||||
assert(result);
|
||||
for (asset_type_t assetType = 0; assetType < assetTypeCount; assetType++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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::optional<asset_type_t> AssetNameResolver::GetAssetTypeByName(const std::string& assetTypeName) const
|
||||
{
|
||||
std::string lowerCaseName = assetTypeName;
|
||||
utils::MakeStringLowerCase(lowerCaseName);
|
||||
|
||||
@@ -7,30 +7,13 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class IAssetNameResolver
|
||||
class AssetNameResolver
|
||||
{
|
||||
public:
|
||||
IAssetNameResolver() = default;
|
||||
virtual ~IAssetNameResolver() = default;
|
||||
IAssetNameResolver(const IAssetNameResolver& other) = default;
|
||||
IAssetNameResolver(IAssetNameResolver&& other) noexcept = default;
|
||||
IAssetNameResolver& operator=(const IAssetNameResolver& other) = default;
|
||||
IAssetNameResolver& operator=(IAssetNameResolver&& other) noexcept = default;
|
||||
AssetNameResolver() = default;
|
||||
explicit AssetNameResolver(GameId gameId);
|
||||
|
||||
[[nodiscard]] virtual GameId GetGameId() const = 0;
|
||||
[[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);
|
||||
[[nodiscard]] std::optional<asset_type_t> GetAssetTypeByName(const std::string& assetTypeName) const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, asset_type_t> m_asset_types_by_name;
|
||||
|
||||
@@ -23,10 +23,7 @@ void SequenceZoneDefinitionEntry::ProcessMatch(ZoneDefinitionParserState* state,
|
||||
{
|
||||
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE_NAME);
|
||||
|
||||
if (!state->m_asset_name_resolver)
|
||||
throw ParsingException(typeNameToken.GetPos(), "Must define game before first asset");
|
||||
|
||||
const auto maybeAssetType = state->m_asset_name_resolver->GetAssetTypeByName(typeNameToken.FieldValue());
|
||||
const auto maybeAssetType = state->m_asset_name_resolver.GetAssetTypeByName(typeNameToken.FieldValue());
|
||||
if (!maybeAssetType)
|
||||
throw ParsingException(typeNameToken.GetPos(), "Unknown asset type");
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
ZoneDefinitionParserState::ZoneDefinitionParserState(std::string targetName, ISearchPath& searchPath, IParserLineStream& underlyingStream)
|
||||
: m_search_path(searchPath),
|
||||
m_underlying_stream(underlyingStream),
|
||||
m_asset_name_resolver(nullptr),
|
||||
m_definition(std::make_unique<ZoneDefinition>())
|
||||
|
||||
{
|
||||
@@ -16,7 +15,7 @@ ZoneDefinitionParserState::ZoneDefinitionParserState(std::string targetName, ISe
|
||||
void ZoneDefinitionParserState::SetGame(const GameId game)
|
||||
{
|
||||
m_definition->m_game = game;
|
||||
m_asset_name_resolver = IAssetNameResolver::GetResolverForGame(game);
|
||||
m_asset_name_resolver = AssetNameResolver(game);
|
||||
}
|
||||
|
||||
namespace
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
IParserLineStream& m_underlying_stream;
|
||||
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_iwd;
|
||||
|
||||
Reference in New Issue
Block a user