chore: adjust IW3 asset loaders to fit IW4 format

This commit is contained in:
Jan 2024-12-26 11:18:26 +01:00
parent 7ef944ebd4
commit a5873a301f
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
10 changed files with 246 additions and 201 deletions

View File

@ -12,13 +12,18 @@
using namespace IW3; using namespace IW3;
AssetLoaderImage::AssetLoaderImage(MemoryManager& memory, ISearchPath& searchPath) namespace
{
class ImageLoader final : public AssetCreator<AssetImage>
{
public:
ImageLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory), : m_memory(memory),
m_search_path(searchPath) m_search_path(searchPath)
{ {
} }
AssetCreationResult AssetLoaderImage::CreateAsset(const std::string& assetName, AssetCreationContext& context) AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{ {
// Do not load any GfxImages from raw for now that are not loaded // Do not load any GfxImages from raw for now that are not loaded
// TODO: Load iwis and add streaming info to asset // TODO: Load iwis and add streaming info to asset
@ -110,3 +115,17 @@ AssetCreationResult AssetLoaderImage::CreateAsset(const std::string& assetName,
return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, image)); return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, image));
} }
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace IW3
{
std::unique_ptr<AssetCreator<AssetImage>> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<ImageLoader>(memory, searchPath);
}
} // namespace IW3

View File

@ -5,17 +5,9 @@
#include "SearchPath/ISearchPath.h" #include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h" #include "Utils/MemoryManager.h"
#include <memory>
namespace IW3 namespace IW3
{ {
class AssetLoaderImage final : public AssetCreator<AssetImage> std::unique_ptr<AssetCreator<AssetImage>> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath);
{
public:
AssetLoaderImage(MemoryManager& memory, ISearchPath& searchPath);
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace IW3 } // namespace IW3

View File

@ -1,19 +1,28 @@
#include "AssetLoaderLocalizeIW3.h" #include "AssetLoaderLocalizeIW3.h"
#include "Localize/CommonLocalizeLoader.h"
using namespace IW3; using namespace IW3;
AssetLoaderLocalize::AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) namespace
{
class LocalizeLoader final : public AssetCreator<AssetLocalize>, public CommonLocalizeLoader
{
public:
LocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: CommonLocalizeLoader(searchPath, zone), : CommonLocalizeLoader(searchPath, zone),
m_memory(memory) m_memory(memory)
{ {
} }
AssetCreationResult AssetLoaderLocalize::CreateAsset(const std::string& assetName, AssetCreationContext& context) AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{ {
return CreateLocalizeAsset(assetName, context); return CreateLocalizeAsset(assetName, context);
} }
AssetCreationResult AssetLoaderLocalize::CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) protected:
AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override
{ {
auto* asset = m_memory.Alloc<LocalizeEntry>(); auto* asset = m_memory.Alloc<LocalizeEntry>();
asset->name = m_memory.Dup(localizeEntry.m_key.c_str()); asset->name = m_memory.Dup(localizeEntry.m_key.c_str());
@ -21,3 +30,16 @@ AssetCreationResult AssetLoaderLocalize::CreateAssetFromCommonAsset(const Common
return AssetCreationResult::Success(context.AddAsset<AssetLocalize>(localizeEntry.m_key, asset)); return AssetCreationResult::Success(context.AddAsset<AssetLocalize>(localizeEntry.m_key, asset));
} }
private:
MemoryManager& m_memory;
};
} // namespace
namespace IW3
{
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<LocalizeLoader>(memory, searchPath, zone);
}
} // namespace IW3

View File

@ -2,22 +2,13 @@
#include "Asset/IAssetCreator.h" #include "Asset/IAssetCreator.h"
#include "Game/IW3/IW3.h" #include "Game/IW3/IW3.h"
#include "Localize/CommonLocalizeLoader.h"
#include "SearchPath/ISearchPath.h" #include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h" #include "Utils/MemoryManager.h"
#include "Zone/Zone.h"
#include <memory>
namespace IW3 namespace IW3
{ {
class AssetLoaderLocalize final : public AssetCreator<AssetLocalize>, public CommonLocalizeLoader std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
{
public:
AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
protected:
AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override;
private:
MemoryManager& m_memory;
};
} // namespace IW3 } // namespace IW3

View File

@ -92,7 +92,7 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModel>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderXModel>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMaterial>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderMaterial>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
collection.AddAssetCreator(std::make_unique<AssetLoaderImage>(memory, searchPath)); collection.AddAssetCreator(CreateImageLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory));
@ -107,17 +107,17 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderFont>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderFont>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenuList>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderMenuList>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenu>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderMenu>(memory));
collection.AddAssetCreator(std::make_unique<AssetLoaderLocalize>(memory, searchPath, zone)); collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone));
// collection.AddAssetCreator(std::make_unique<AssetLoaderWeapon>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderWeapon>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundDriverGlobals>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderSoundDriverGlobals>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFx>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderFx>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImpactFx>(memory)); // collection.AddAssetCreator(std::make_unique<AssetLoaderImpactFx>(memory));
collection.AddAssetCreator(std::make_unique<AssetLoaderRawFile>(memory, searchPath)); collection.AddAssetCreator(CreateRawFileLoader(memory, searchPath));
collection.AddAssetCreator(std::make_unique<AssetLoaderStringTable>(memory, searchPath)); collection.AddAssetCreator(CreateStringTableLoader(memory, searchPath));
} }
} // namespace } // namespace
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const
{ {
ConfigureDefaultCreators(collection, zone); ConfigureDefaultCreators(collection, zone);
ConfigureLoaders(collection, zone, searchPath); ConfigureLoaders(collection, zone, searchPath);

View File

@ -11,6 +11,6 @@ namespace IW3
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override; void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
void UnloadContainersOfZone(Zone& zone) const override; void UnloadContainersOfZone(Zone& zone) const override;
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const override; void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const override;
}; };
} // namespace IW3 } // namespace IW3

View File

@ -6,13 +6,18 @@
using namespace IW3; using namespace IW3;
AssetLoaderRawFile::AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath) namespace
{
class RawFileLoader final : public AssetCreator<AssetRawFile>
{
public:
RawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory), : m_memory(memory),
m_search_path(searchPath) m_search_path(searchPath)
{ {
} }
AssetCreationResult AssetLoaderRawFile::CreateAsset(const std::string& assetName, AssetCreationContext& context) AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{ {
const auto file = m_search_path.Open(assetName); const auto file = m_search_path.Open(assetName);
if (!file.IsOpen()) if (!file.IsOpen())
@ -32,3 +37,17 @@ AssetCreationResult AssetLoaderRawFile::CreateAsset(const std::string& assetName
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile)); return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
} }
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace IW3
{
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<RawFileLoader>(memory, searchPath);
}
} // namespace IW3

View File

@ -5,17 +5,9 @@
#include "SearchPath/ISearchPath.h" #include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h" #include "Utils/MemoryManager.h"
#include <memory>
namespace IW3 namespace IW3
{ {
class AssetLoaderRawFile final : public AssetCreator<AssetRawFile> std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath);
{
public:
AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath);
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace IW3 } // namespace IW3

View File

@ -1,20 +1,24 @@
#include "AssetLoaderStringTableIW3.h" #include "AssetLoaderStringTableIW3.h"
#include "Game/IW3/IW3.h" #include "Game/IW3/IW3.h"
#include "Pool/GlobalAssetPool.h"
#include "StringTable/StringTableLoader.h" #include "StringTable/StringTableLoader.h"
#include <cstring> #include <cstring>
using namespace IW3; using namespace IW3;
AssetLoaderStringTable::AssetLoaderStringTable(MemoryManager& memory, ISearchPath& searchPath) namespace
{
class StringTableLoader final : public AssetCreator<AssetStringTable>
{
public:
StringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory), : m_memory(memory),
m_search_path(searchPath) m_search_path(searchPath)
{ {
} }
AssetCreationResult AssetLoaderStringTable::CreateAsset(const std::string& assetName, AssetCreationContext& context) AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{ {
const auto file = m_search_path.Open(assetName); const auto file = m_search_path.Open(assetName);
if (!file.IsOpen()) if (!file.IsOpen())
@ -27,3 +31,17 @@ AssetCreationResult AssetLoaderStringTable::CreateAsset(const std::string& asset
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable)); return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
} }
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace IW3
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<StringTableLoader>(memory, searchPath);
}
} // namespace IW3

View File

@ -5,17 +5,9 @@
#include "SearchPath/ISearchPath.h" #include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h" #include "Utils/MemoryManager.h"
#include <memory>
namespace IW3 namespace IW3
{ {
class AssetLoaderStringTable final : public AssetCreator<AssetRawFile> std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath);
{
public:
AssetLoaderStringTable(MemoryManager& memory, ISearchPath& searchPath);
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace IW3 } // namespace IW3