mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 00:57:56 -05:00
chore: use method static array for zoneloaderfactory
This commit is contained in:
@ -19,14 +19,9 @@
|
||||
|
||||
using namespace T5;
|
||||
|
||||
class ZoneLoaderFactory::Impl
|
||||
namespace
|
||||
{
|
||||
static GameLanguage GetZoneLanguage(std::string& zoneName)
|
||||
{
|
||||
return GameLanguage::LANGUAGE_NONE;
|
||||
}
|
||||
|
||||
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial)
|
||||
bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial)
|
||||
{
|
||||
assert(isSecure != nullptr);
|
||||
assert(isOfficial != nullptr);
|
||||
@ -46,59 +41,52 @@ class ZoneLoaderFactory::Impl
|
||||
return false;
|
||||
}
|
||||
|
||||
static void SetupBlock(ZoneLoader* zoneLoader)
|
||||
void SetupBlock(ZoneLoader& zoneLoader)
|
||||
{
|
||||
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
|
||||
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
|
||||
#undef XBLOCK_DEF
|
||||
}
|
||||
} // namespace
|
||||
|
||||
public:
|
||||
static ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
|
||||
{
|
||||
bool isSecure;
|
||||
bool isOfficial;
|
||||
|
||||
// Check if this file is a supported IW4 zone.
|
||||
if (!CanLoad(header, &isSecure, &isOfficial))
|
||||
return nullptr;
|
||||
|
||||
// Create new zone
|
||||
auto zone = std::make_unique<Zone>(fileName, 0, &g_GameT5);
|
||||
auto* zonePtr = zone.get();
|
||||
zone->m_pools = std::make_unique<GameAssetPoolT5>(zonePtr, 0);
|
||||
zone->m_language = GetZoneLanguage(fileName);
|
||||
|
||||
// File is supported. Now setup all required steps for loading this file.
|
||||
auto* zoneLoader = new ZoneLoader(std::move(zone));
|
||||
|
||||
SetupBlock(zoneLoader);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>(
|
||||
std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
// Return the fully setup zoneloader
|
||||
return zoneLoader;
|
||||
}
|
||||
};
|
||||
|
||||
ZoneLoader* ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
|
||||
std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
|
||||
{
|
||||
return Impl::CreateLoaderForHeader(header, fileName);
|
||||
bool isSecure;
|
||||
bool isOfficial;
|
||||
|
||||
// Check if this file is a supported IW4 zone.
|
||||
if (!CanLoad(header, &isSecure, &isOfficial))
|
||||
return nullptr;
|
||||
|
||||
// Create new zone
|
||||
auto zone = std::make_unique<Zone>(fileName, 0, IGame::GetGameById(GameId::T5));
|
||||
auto* zonePtr = zone.get();
|
||||
zone->m_pools = std::make_unique<GameAssetPoolT5>(zonePtr, 0);
|
||||
zone->m_language = GameLanguage::LANGUAGE_NONE;
|
||||
|
||||
// File is supported. Now setup all required steps for loading this file.
|
||||
auto zoneLoader = std::make_unique<ZoneLoader>(std::move(zone));
|
||||
|
||||
SetupBlock(*zoneLoader);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
return zoneLoader;
|
||||
}
|
||||
|
Reference in New Issue
Block a user