chore: use IObjLoader directly instead of indirection of ObjLoading

This commit is contained in:
Jan
2024-10-19 12:07:12 +02:00
parent c034ac790a
commit 4c9a84777f
21 changed files with 62 additions and 136 deletions

View File

@ -48,11 +48,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}
bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameIW3;
}
bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;

View File

@ -19,8 +19,6 @@ namespace IW3
public:
ObjLoader();
[[nodiscard]] bool SupportsZone(const Zone& zone) const override;
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

View File

@ -92,11 +92,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}
bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameIW4;
}
bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;

View File

@ -14,8 +14,6 @@ namespace IW4
public:
ObjLoader();
[[nodiscard]] bool SupportsZone(const Zone& zone) const override;
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

View File

@ -99,11 +99,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}
bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameIW5;
}
bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;

View File

@ -14,8 +14,6 @@ namespace IW5
public:
ObjLoader();
[[nodiscard]] bool SupportsZone(const Zone& zone) const override;
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

View File

@ -56,11 +56,6 @@ ObjLoader::ObjLoader()
#undef REGISTER_ASSET_LOADER
}
bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameT5;
}
bool ObjLoader::IsMpZone(const Zone& zone)
{
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;

View File

@ -14,8 +14,6 @@ namespace T5
public:
ObjLoader();
bool SupportsZone(const Zone& zone) const override;
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

View File

@ -125,11 +125,6 @@ namespace T6
#undef REGISTER_ASSET_LOADER
}
bool ObjLoader::SupportsZone(const Zone& zone) const
{
return zone.m_game == &g_GameT6;
}
bool ObjLoader::VerifySoundBankChecksum(const SoundBank& soundBank, const SndRuntimeAssetBank& sndRuntimeAssetBank)
{
SoundAssetBankChecksum checksum{};

View File

@ -19,8 +19,6 @@ namespace T6
public:
ObjLoader();
[[nodiscard]] bool SupportsZone(const Zone& zone) const override;
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override;

View File

@ -0,0 +1,27 @@
#include "IObjLoader.h"
#include "Game/IW3/ObjLoaderIW3.h"
#include "Game/IW4/ObjLoaderIW4.h"
#include "Game/IW5/ObjLoaderIW5.h"
#include "Game/T5/ObjLoaderT5.h"
#include "Game/T6/ObjLoaderT6.h"
#include <cassert>
const IObjLoader* IObjLoader::GetObjLoaderForGame(GameId game)
{
static const IObjLoader* zoneCreators[static_cast<unsigned>(GameId::COUNT)]{
new IW3::ObjLoader(),
new IW4::ObjLoader(),
new IW5::ObjLoader(),
new T5::ObjLoader(),
new T6::ObjLoader(),
};
static_assert(std::extent_v<decltype(zoneCreators)> == static_cast<unsigned>(GameId::COUNT));
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
const auto* result = zoneCreators[static_cast<unsigned>(game)];
assert(result);
return result;
}

View File

@ -14,13 +14,6 @@ public:
IObjLoader& operator=(const IObjLoader& other) = default;
IObjLoader& operator=(IObjLoader&& other) noexcept = default;
/**
* \brief Checks whether this ObjLoader supports a specified zone.
* \param zone The zone to check.
* \return \c true if the specified zone is supported.
*/
[[nodiscard]] virtual bool SupportsZone(const Zone& zone) const = 0;
/**
* \brief Loads all containers that are referenced by a specified zone.
* \param searchPath The search path object to use to find the referenced containers.
@ -36,4 +29,6 @@ public:
virtual bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const = 0;
virtual void FinalizeAssetsForZone(AssetLoadingContext& context) const = 0;
static const IObjLoader* GetObjLoaderForGame(GameId game);
};

View File

@ -1,10 +1,5 @@
#include "ObjLoading.h"
#include "Game/IW3/ObjLoaderIW3.h"
#include "Game/IW4/ObjLoaderIW4.h"
#include "Game/IW5/ObjLoaderIW5.h"
#include "Game/T5/ObjLoaderT5.h"
#include "Game/T6/ObjLoaderT6.h"
#include "IObjLoader.h"
#include "ObjContainer/IWD/IWD.h"
#include "SearchPath/SearchPaths.h"
@ -14,38 +9,6 @@
ObjLoading::Configuration_t ObjLoading::Configuration;
const IObjLoader* const OBJ_LOADERS[]{
new IW3::ObjLoader(),
new IW4::ObjLoader(),
new IW5::ObjLoader(),
new T5::ObjLoader(),
new T6::ObjLoader(),
};
void ObjLoading::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone)
{
for (const auto* loader : OBJ_LOADERS)
{
if (loader->SupportsZone(zone))
{
loader->LoadReferencedContainersForZone(searchPath, zone);
return;
}
}
}
void ObjLoading::UnloadContainersOfZone(Zone& zone)
{
for (const auto* loader : OBJ_LOADERS)
{
if (loader->SupportsZone(zone))
{
loader->UnloadContainersOfZone(zone);
return;
}
}
}
void ObjLoading::LoadIWDsInSearchPath(ISearchPath& searchPath)
{
searchPath.Find(SearchPathSearchOptions().IncludeSubdirectories(false).FilterExtensions("iwd"),
@ -81,28 +44,3 @@ SearchPaths ObjLoading::GetIWDSearchPaths()
return iwdPaths;
}
bool ObjLoading::LoadAssetForZone(AssetLoadingContext& context, const asset_type_t assetType, const std::string& assetName)
{
for (const auto* loader : OBJ_LOADERS)
{
if (loader->SupportsZone(context.m_zone))
{
return loader->LoadAssetForZone(context, assetType, assetName);
}
}
return false;
}
void ObjLoading::FinalizeAssetsForZone(AssetLoadingContext& context)
{
for (const auto* loader : OBJ_LOADERS)
{
if (loader->SupportsZone(context.m_zone))
{
loader->FinalizeAssetsForZone(context);
return;
}
}
}

View File

@ -1,9 +1,7 @@
#pragma once
#include "AssetLoading/AssetLoadingContext.h"
#include "SearchPath/ISearchPath.h"
#include "SearchPath/SearchPaths.h"
#include "Zone/Zone.h"
class ObjLoading
{
@ -16,19 +14,6 @@ public:
bool MenuNoOptimization = false;
} Configuration;
/**
* \brief Loads all containers that are being referenced by the specified zone.
* \param searchPath The search path to use to find the referenced containers.
* \param zone The zone to load all referenced containers of.
*/
static void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone);
/**
* \brief Unloads all containers that were referenced by a specified zone. If referenced by more than one zone a container will only be unloaded once all
* referencing zones were unloaded the container. \param zone The zone to unload all referenced containers for.
*/
static void UnloadContainersOfZone(Zone& zone);
/**
* \brief Loads all IWDs that can be found in a specified search path.
* \param searchPath The search path that contains IWDs to be loaded.
@ -46,7 +31,4 @@ public:
* \return A \c SearchPaths object containing all IWDs that are currently loaded.
*/
static SearchPaths GetIWDSearchPaths();
static bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName);
static void FinalizeAssetsForZone(AssetLoadingContext& context);
};