mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
chore: adjust IW3 asset loaders to fit IW4 format
This commit is contained in:
parent
7ef944ebd4
commit
a5873a301f
@ -12,101 +12,120 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderImage::AssetLoaderImage(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult AssetLoaderImage::CreateAsset(const std::string& assetName, AssetCreationContext& context)
|
||||
{
|
||||
// Do not load any GfxImages from raw for now that are not loaded
|
||||
// TODO: Load iwis and add streaming info to asset
|
||||
if (assetName.empty() || assetName[0] != '*')
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
std::string safeAssetName = assetName;
|
||||
std::ranges::replace(safeAssetName, '*', '_');
|
||||
|
||||
const auto file = m_search_path.Open(std::format("images/{}.dds", safeAssetName));
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
const auto texture = dds::LoadDds(*file.m_stream);
|
||||
if (!texture)
|
||||
class ImageLoader final : public AssetCreator<AssetImage>
|
||||
{
|
||||
std::cerr << std::format("Failed to load dds file for image asset \"{}\"\n", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
auto* image = m_memory.Alloc<GfxImage>();
|
||||
image->name = m_memory.Dup(assetName.c_str());
|
||||
image->picmip.platform[0] = 0;
|
||||
image->picmip.platform[1] = 0;
|
||||
image->noPicmip = !texture->HasMipMaps();
|
||||
image->semantic = TS_FUNCTION;
|
||||
image->track = 0;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
image->cardMemory.platform[1] = 0;
|
||||
image->width = static_cast<uint16_t>(texture->GetWidth());
|
||||
image->height = static_cast<uint16_t>(texture->GetHeight());
|
||||
image->depth = static_cast<uint16_t>(texture->GetDepth());
|
||||
image->category = IMG_CATEGORY_AUTO_GENERATED;
|
||||
image->delayLoadPixels = false;
|
||||
|
||||
switch (texture->GetTextureType())
|
||||
{
|
||||
case TextureType::T_2D:
|
||||
image->mapType = MAPTYPE_2D;
|
||||
break;
|
||||
|
||||
case TextureType::T_3D:
|
||||
image->mapType = MAPTYPE_3D;
|
||||
break;
|
||||
|
||||
case TextureType::T_CUBE:
|
||||
image->mapType = MAPTYPE_CUBE;
|
||||
break;
|
||||
|
||||
default:
|
||||
image->mapType = MAPTYPE_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
const auto mipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
const auto faceCount = texture->GetFaceCount();
|
||||
|
||||
size_t dataSize = 0;
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
dataSize += texture->GetSizeOfMipLevel(mipLevel) * faceCount;
|
||||
|
||||
auto* loadDef = static_cast<GfxImageLoadDef*>(m_memory.AllocRaw(offsetof(GfxImageLoadDef, data) + dataSize));
|
||||
image->texture.loadDef = loadDef;
|
||||
loadDef->levelCount = static_cast<char>(mipCount);
|
||||
loadDef->flags = 0;
|
||||
if (!texture->HasMipMaps())
|
||||
loadDef->flags |= iwi6::IMG_FLAG_NOMIPMAPS;
|
||||
if (texture->GetTextureType() == TextureType::T_CUBE)
|
||||
loadDef->flags |= iwi6::IMG_FLAG_CUBEMAP;
|
||||
if (texture->GetTextureType() == TextureType::T_3D)
|
||||
loadDef->flags |= iwi6::IMG_FLAG_VOLMAP;
|
||||
loadDef->dimensions[0] = image->width;
|
||||
loadDef->dimensions[1] = image->height;
|
||||
loadDef->dimensions[2] = image->depth;
|
||||
loadDef->format = static_cast<int>(texture->GetFormat()->GetD3DFormat());
|
||||
loadDef->resourceSize = dataSize;
|
||||
|
||||
char* currentDataBuffer = loadDef->data;
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
{
|
||||
const auto mipSize = texture->GetSizeOfMipLevel(mipLevel);
|
||||
|
||||
for (auto face = 0; face < faceCount; face++)
|
||||
public:
|
||||
ImageLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
memcpy(currentDataBuffer, texture->GetBufferForMipLevel(mipLevel, face), mipSize);
|
||||
currentDataBuffer += mipSize;
|
||||
}
|
||||
}
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, image));
|
||||
}
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
// Do not load any GfxImages from raw for now that are not loaded
|
||||
// TODO: Load iwis and add streaming info to asset
|
||||
if (assetName.empty() || assetName[0] != '*')
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
std::string safeAssetName = assetName;
|
||||
std::ranges::replace(safeAssetName, '*', '_');
|
||||
|
||||
const auto file = m_search_path.Open(std::format("images/{}.dds", safeAssetName));
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
const auto texture = dds::LoadDds(*file.m_stream);
|
||||
if (!texture)
|
||||
{
|
||||
std::cerr << std::format("Failed to load dds file for image asset \"{}\"\n", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
auto* image = m_memory.Alloc<GfxImage>();
|
||||
image->name = m_memory.Dup(assetName.c_str());
|
||||
image->picmip.platform[0] = 0;
|
||||
image->picmip.platform[1] = 0;
|
||||
image->noPicmip = !texture->HasMipMaps();
|
||||
image->semantic = TS_FUNCTION;
|
||||
image->track = 0;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
image->cardMemory.platform[1] = 0;
|
||||
image->width = static_cast<uint16_t>(texture->GetWidth());
|
||||
image->height = static_cast<uint16_t>(texture->GetHeight());
|
||||
image->depth = static_cast<uint16_t>(texture->GetDepth());
|
||||
image->category = IMG_CATEGORY_AUTO_GENERATED;
|
||||
image->delayLoadPixels = false;
|
||||
|
||||
switch (texture->GetTextureType())
|
||||
{
|
||||
case TextureType::T_2D:
|
||||
image->mapType = MAPTYPE_2D;
|
||||
break;
|
||||
|
||||
case TextureType::T_3D:
|
||||
image->mapType = MAPTYPE_3D;
|
||||
break;
|
||||
|
||||
case TextureType::T_CUBE:
|
||||
image->mapType = MAPTYPE_CUBE;
|
||||
break;
|
||||
|
||||
default:
|
||||
image->mapType = MAPTYPE_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
const auto mipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
const auto faceCount = texture->GetFaceCount();
|
||||
|
||||
size_t dataSize = 0;
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
dataSize += texture->GetSizeOfMipLevel(mipLevel) * faceCount;
|
||||
|
||||
auto* loadDef = static_cast<GfxImageLoadDef*>(m_memory.AllocRaw(offsetof(GfxImageLoadDef, data) + dataSize));
|
||||
image->texture.loadDef = loadDef;
|
||||
loadDef->levelCount = static_cast<char>(mipCount);
|
||||
loadDef->flags = 0;
|
||||
if (!texture->HasMipMaps())
|
||||
loadDef->flags |= iwi6::IMG_FLAG_NOMIPMAPS;
|
||||
if (texture->GetTextureType() == TextureType::T_CUBE)
|
||||
loadDef->flags |= iwi6::IMG_FLAG_CUBEMAP;
|
||||
if (texture->GetTextureType() == TextureType::T_3D)
|
||||
loadDef->flags |= iwi6::IMG_FLAG_VOLMAP;
|
||||
loadDef->dimensions[0] = image->width;
|
||||
loadDef->dimensions[1] = image->height;
|
||||
loadDef->dimensions[2] = image->depth;
|
||||
loadDef->format = static_cast<int>(texture->GetFormat()->GetD3DFormat());
|
||||
loadDef->resourceSize = dataSize;
|
||||
|
||||
char* currentDataBuffer = loadDef->data;
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
{
|
||||
const auto mipSize = texture->GetSizeOfMipLevel(mipLevel);
|
||||
|
||||
for (auto face = 0; face < faceCount; face++)
|
||||
{
|
||||
memcpy(currentDataBuffer, texture->GetBufferForMipLevel(mipLevel, face), mipSize);
|
||||
currentDataBuffer += mipSize;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -5,17 +5,9 @@
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderImage final : public AssetCreator<AssetImage>
|
||||
{
|
||||
public:
|
||||
AssetLoaderImage(MemoryManager& memory, ISearchPath& searchPath);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
std::unique_ptr<AssetCreator<AssetImage>> CreateImageLoader(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace IW3
|
||||
|
@ -1,23 +1,45 @@
|
||||
#include "AssetLoaderLocalizeIW3.h"
|
||||
|
||||
#include "Localize/CommonLocalizeLoader.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderLocalize::AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: CommonLocalizeLoader(searchPath, zone),
|
||||
m_memory(memory)
|
||||
namespace
|
||||
{
|
||||
}
|
||||
class LocalizeLoader final : public AssetCreator<AssetLocalize>, public CommonLocalizeLoader
|
||||
{
|
||||
public:
|
||||
LocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: CommonLocalizeLoader(searchPath, zone),
|
||||
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);
|
||||
}
|
||||
|
||||
protected:
|
||||
AssetCreationResult CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context) override
|
||||
|
||||
{
|
||||
auto* asset = m_memory.Alloc<LocalizeEntry>();
|
||||
asset->name = m_memory.Dup(localizeEntry.m_key.c_str());
|
||||
asset->value = m_memory.Dup(localizeEntry.m_value.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetLocalize>(localizeEntry.m_key, asset));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
return CreateLocalizeAsset(assetName, context);
|
||||
}
|
||||
|
||||
AssetCreationResult AssetLoaderLocalize::CreateAssetFromCommonAsset(const CommonLocalizeEntry& localizeEntry, AssetCreationContext& context)
|
||||
{
|
||||
auto* asset = m_memory.Alloc<LocalizeEntry>();
|
||||
asset->name = m_memory.Dup(localizeEntry.m_key.c_str());
|
||||
asset->value = m_memory.Dup(localizeEntry.m_value.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetLocalize>(localizeEntry.m_key, asset));
|
||||
}
|
||||
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<LocalizeLoader>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace IW3
|
||||
|
@ -2,22 +2,13 @@
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Localize/CommonLocalizeLoader.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderLocalize final : public AssetCreator<AssetLocalize>, public CommonLocalizeLoader
|
||||
{
|
||||
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;
|
||||
};
|
||||
std::unique_ptr<AssetCreator<AssetLocalize>> CreateLocalizeLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace IW3
|
||||
|
@ -92,7 +92,7 @@ namespace
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModel>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderMaterial>(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<AssetLoaderSoundCurve>(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<AssetLoaderMenuList>(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<AssetLoaderSoundDriverGlobals>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderFx>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderImpactFx>(memory));
|
||||
collection.AddAssetCreator(std::make_unique<AssetLoaderRawFile>(memory, searchPath));
|
||||
collection.AddAssetCreator(std::make_unique<AssetLoaderStringTable>(memory, searchPath));
|
||||
collection.AddAssetCreator(CreateRawFileLoader(memory, searchPath));
|
||||
collection.AddAssetCreator(CreateStringTableLoader(memory, searchPath));
|
||||
}
|
||||
} // 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);
|
||||
ConfigureLoaders(collection, zone, searchPath);
|
||||
|
@ -11,6 +11,6 @@ namespace IW3
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, 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
|
||||
|
@ -6,29 +6,48 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderRawFile::AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
namespace
|
||||
{
|
||||
}
|
||||
class RawFileLoader final : public AssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
RawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
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);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
auto* rawFile = m_memory.Alloc<RawFile>();
|
||||
rawFile->name = m_memory.Dup(assetName.c_str());
|
||||
rawFile->len = static_cast<int>(file.m_length);
|
||||
|
||||
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(file.m_length + 1));
|
||||
file.m_stream->read(fileBuffer, file.m_length);
|
||||
if (file.m_stream->gcount() != file.m_length)
|
||||
return AssetCreationResult::Failure();
|
||||
fileBuffer[rawFile->len] = '\0';
|
||||
|
||||
rawFile->buffer = fileBuffer;
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
const auto file = m_search_path.Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
auto* rawFile = m_memory.Alloc<RawFile>();
|
||||
rawFile->name = m_memory.Dup(assetName.c_str());
|
||||
rawFile->len = static_cast<int>(file.m_length);
|
||||
|
||||
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(file.m_length + 1));
|
||||
file.m_stream->read(fileBuffer, file.m_length);
|
||||
if (file.m_stream->gcount() != file.m_length)
|
||||
return AssetCreationResult::Failure();
|
||||
fileBuffer[rawFile->len] = '\0';
|
||||
|
||||
rawFile->buffer = fileBuffer;
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
|
||||
}
|
||||
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<RawFileLoader>(memory, searchPath);
|
||||
}
|
||||
} // namespace IW3
|
||||
|
@ -5,17 +5,9 @@
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderRawFile final : public AssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
std::unique_ptr<AssetCreator<AssetRawFile>> CreateRawFileLoader(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace IW3
|
||||
|
@ -1,29 +1,47 @@
|
||||
#include "AssetLoaderStringTableIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "StringTable/StringTableLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderStringTable::AssetLoaderStringTable(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
namespace
|
||||
{
|
||||
}
|
||||
class StringTableLoader final : public AssetCreator<AssetStringTable>
|
||||
{
|
||||
public:
|
||||
StringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
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);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
string_table::StringTableLoaderV1<StringTable> loader;
|
||||
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
|
||||
if (!stringTable)
|
||||
return AssetCreationResult::Failure();
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
const auto file = m_search_path.Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
string_table::StringTableLoaderV1<StringTable> loader;
|
||||
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
|
||||
if (!stringTable)
|
||||
return AssetCreationResult::Failure();
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
|
||||
}
|
||||
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<StringTableLoader>(memory, searchPath);
|
||||
}
|
||||
} // namespace IW3
|
||||
|
@ -5,17 +5,9 @@
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderStringTable final : public AssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
AssetLoaderStringTable(MemoryManager& memory, ISearchPath& searchPath);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace IW3
|
||||
|
Loading…
x
Reference in New Issue
Block a user