mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 16:51:56 +00:00
chore: implement obj loading skeleton with localize asset
This commit is contained in:
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderGfxImage final : public BasicAssetLoader<AssetImage>
|
||||
{
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool
|
||||
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
@ -1,36 +0,0 @@
|
||||
#include "AssetLoaderLocalizeEntry.h"
|
||||
|
||||
#include "Localize/LocalizeCommonAssetLoader.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
XAssetInfoGeneric* AssetLoaderLocalizeEntry::LoadFromGlobalAssetPools(const std::string& assetName) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* AssetLoaderLocalizeEntry::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AssetLoaderLocalizeEntry::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderLocalizeEntry::LoadFromRaw(
|
||||
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const LocalizeCommonAssetLoader commonLoader(
|
||||
[memory, manager](const CommonLocalizeEntry& entry)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
|
||||
manager->AddAsset<AssetLocalize>(entry.m_key, localizeEntry);
|
||||
});
|
||||
|
||||
return commonLoader.LoadLocalizeAsset(assetName, searchPath, manager, zone);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderLocalizeEntry final : public BasicAssetLoader<AssetLocalize>
|
||||
{
|
||||
public:
|
||||
_NODISCARD XAssetInfoGeneric* LoadFromGlobalAssetPools(const std::string& assetName) const override;
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool
|
||||
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
@ -1,44 +0,0 @@
|
||||
#include "AssetLoaderRawFile.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
void* AssetLoaderRawFile::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* rawFile = memory->Create<RawFile>();
|
||||
memset(rawFile, 0, sizeof(RawFile));
|
||||
rawFile->name = memory->Dup(assetName.c_str());
|
||||
return rawFile;
|
||||
}
|
||||
|
||||
bool AssetLoaderRawFile::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderRawFile::LoadFromRaw(
|
||||
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto file = searchPath->Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
auto* rawFile = memory->Create<RawFile>();
|
||||
rawFile->name = memory->Dup(assetName.c_str());
|
||||
rawFile->len = static_cast<int>(file.m_length);
|
||||
|
||||
auto* fileBuffer = 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 false;
|
||||
fileBuffer[rawFile->len] = '\0';
|
||||
|
||||
rawFile->buffer = fileBuffer;
|
||||
manager->AddAsset<AssetRawFile>(assetName, rawFile);
|
||||
|
||||
return true;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderRawFile final : public BasicAssetLoader<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool
|
||||
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
@ -1,4 +1,4 @@
|
||||
#include "AssetLoaderGfxImage.h"
|
||||
#include "AssetLoaderImageIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/DdsLoader.h"
|
||||
@ -12,43 +12,35 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
void* AssetLoaderGfxImage::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
AssetLoaderImage::AssetLoaderImage(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
auto* image = memory->Create<GfxImage>();
|
||||
memset(image, 0, sizeof(GfxImage));
|
||||
image->name = memory->Dup(assetName.c_str());
|
||||
return image;
|
||||
}
|
||||
|
||||
bool AssetLoaderGfxImage::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderGfxImage::LoadFromRaw(
|
||||
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
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 false;
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
std::string safeAssetName = assetName;
|
||||
std::ranges::replace(safeAssetName, '*', '_');
|
||||
|
||||
const auto file = searchPath->Open(std::format("images/{}.dds", safeAssetName));
|
||||
const auto file = m_search_path.Open(std::format("images/{}.dds", safeAssetName));
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
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 false;
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
auto* image = memory->Create<GfxImage>();
|
||||
image->name = memory->Dup(assetName.c_str());
|
||||
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();
|
||||
@ -88,7 +80,7 @@ bool AssetLoaderGfxImage::LoadFromRaw(
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
dataSize += texture->GetSizeOfMipLevel(mipLevel) * faceCount;
|
||||
|
||||
auto* loadDef = static_cast<GfxImageLoadDef*>(zone->GetMemory()->AllocRaw(offsetof(GfxImageLoadDef, data) + dataSize));
|
||||
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;
|
||||
@ -116,7 +108,5 @@ bool AssetLoaderGfxImage::LoadFromRaw(
|
||||
}
|
||||
}
|
||||
|
||||
manager->AddAsset<AssetImage>(assetName, image);
|
||||
|
||||
return true;
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, image));
|
||||
}
|
21
src/ObjLoading/Game/IW3/Image/AssetLoaderImageIW3.h
Normal file
21
src/ObjLoading/Game/IW3/Image/AssetLoaderImageIW3.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
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;
|
||||
};
|
||||
} // namespace IW3
|
16
src/ObjLoading/Game/IW3/Image/DefaultCreatorImageIW3.cpp
Normal file
16
src/ObjLoading/Game/IW3/Image/DefaultCreatorImageIW3.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "DefaultCreatorImageIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
DefaultCreatorImage::DefaultCreatorImage(MemoryManager& memory)
|
||||
: m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult DefaultCreatorImage::CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const
|
||||
{
|
||||
auto* asset = m_memory.Alloc<GfxImage>();
|
||||
asset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, asset));
|
||||
}
|
18
src/ObjLoading/Game/IW3/Image/DefaultCreatorImageIW3.h
Normal file
18
src/ObjLoading/Game/IW3/Image/DefaultCreatorImageIW3.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IDefaultAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class DefaultCreatorImage : public DefaultAssetCreator<AssetImage>
|
||||
{
|
||||
public:
|
||||
explicit DefaultCreatorImage(MemoryManager& memory);
|
||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace IW3
|
23
src/ObjLoading/Game/IW3/Localize/AssetLoaderLocalizeIW3.cpp
Normal file
23
src/ObjLoading/Game/IW3/Localize/AssetLoaderLocalizeIW3.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "AssetLoaderLocalizeIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderLocalize::AssetLoaderLocalize(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: CommonLocalizeLoader(searchPath, zone),
|
||||
m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult AssetLoaderLocalize::CreateAsset(const std::string& assetName, AssetCreationContext& context)
|
||||
{
|
||||
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));
|
||||
}
|
23
src/ObjLoading/Game/IW3/Localize/AssetLoaderLocalizeIW3.h
Normal file
23
src/ObjLoading/Game/IW3/Localize/AssetLoaderLocalizeIW3.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Localize/CommonLocalizeLoader.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
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;
|
||||
};
|
||||
} // namespace IW3
|
@ -1,77 +1,123 @@
|
||||
#include "ObjLoaderIW3.h"
|
||||
|
||||
#include "AssetLoaders/AssetLoaderGfxImage.h"
|
||||
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
||||
#include "AssetLoaders/AssetLoaderRawFile.h"
|
||||
#include "AssetLoading/AssetLoadingManager.h"
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "Game/IW3/GameIW3.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/AssetLoaderImageIW3.h"
|
||||
#include "Image/DefaultCreatorImageIW3.h"
|
||||
#include "Localize/AssetLoaderLocalizeIW3.h"
|
||||
#include "ObjLoading.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
ObjLoader::ObjLoader()
|
||||
{
|
||||
#define REGISTER_ASSET_LOADER(t) \
|
||||
{ \
|
||||
auto l = std::make_unique<t>(); \
|
||||
m_asset_loaders_by_type[l->GetHandlingAssetType()] = std::move(l); \
|
||||
}
|
||||
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetPhysPreset>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetXAnim>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetXModel>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetMaterial>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetTechniqueSet>)
|
||||
REGISTER_ASSET_LOADER(AssetLoaderGfxImage)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetSound>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetSoundCurve>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetLoadedSound>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetClipMap>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetClipMapPvs>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetComWorld>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetGameWorldSp>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetGameWorldMp>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetMapEnts>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetGfxWorld>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetLightDef>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetFont>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetMenuList>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetMenu>)
|
||||
REGISTER_ASSET_LOADER(AssetLoaderLocalizeEntry)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetWeapon>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetSoundDriverGlobals>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetFx>)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetImpactFx>)
|
||||
REGISTER_ASSET_LOADER(AssetLoaderRawFile)
|
||||
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetStringTable>)
|
||||
|
||||
#undef REGISTER_ASSET_LOADER
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool ObjLoader::IsZmZone(const Zone& zone)
|
||||
{
|
||||
return zone.m_name.compare(0, 3, "zm_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_zm") == 0;
|
||||
}
|
||||
|
||||
void ObjLoader::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const {}
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone& zone) const {}
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection) const {}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, const asset_type_t assetType, const std::string& assetName) const
|
||||
namespace
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
return assetLoadingManager.LoadAssetFromLoader(assetType, assetName);
|
||||
}
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
void ObjLoader::FinalizeAssetsForZone(AssetLoadingContext& context) const
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorPhysPreset>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorXAnim>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorXModel>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMaterial>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorTechniqueSet>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorImage>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSound>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSoundCurve>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorLoadedSound>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorClipMap>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorClipMapPvs>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorComWorld>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGameWorldSp>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGameWorldMp>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMapEnts>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGfxWorld>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorLightDef>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorFont>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMenuList>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorMenu>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorLocalize>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorWeapon>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSoundDriverGlobals>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorFx>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorImpactFx>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorRawFile>(memory));
|
||||
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorStringTable>(memory));
|
||||
}
|
||||
|
||||
void ConfigureGlobalAssetPoolsLoaders(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPhysPreset>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXAnim>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXModel>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetMaterial>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetTechniqueSet>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetImage>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSound>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundCurve>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetLoadedSound>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMap>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetClipMapPvs>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetComWorld>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGameWorldSp>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGameWorldMp>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetMapEnts>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGfxWorld>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetLightDef>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFont>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetMenuList>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetMenu>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetLocalize>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetWeapon>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundDriverGlobals>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFx>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetImpactFx>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetRawFile>>(zone));
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetStringTable>>(zone));
|
||||
}
|
||||
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||
// 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(std::make_unique<AssetLoaderSound>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderClipMap>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderClipMapPvs>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderComWorld>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderGameWorldSp>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderGameWorldMp>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderMapEnts>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderGfxWorld>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderLightDef>(memory));
|
||||
// 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(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));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderStringTable>(memory));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const
|
||||
{
|
||||
for (const auto& [type, loader] : m_asset_loaders_by_type)
|
||||
loader->FinalizeAssetsForZone(context);
|
||||
ConfigureDefaultCreators(collection, zone, searchPath);
|
||||
ConfigureGlobalAssetPoolsLoaders(collection, zone);
|
||||
}
|
||||
|
@ -1,30 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/IAssetLoader.h"
|
||||
#include "IObjLoader.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class ObjLoader final : public IObjLoader
|
||||
{
|
||||
std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>> m_asset_loaders_by_type;
|
||||
|
||||
static bool IsMpZone(const Zone& zone);
|
||||
static bool IsZmZone(const Zone& zone);
|
||||
|
||||
public:
|
||||
ObjLoader();
|
||||
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
35
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp
Normal file
35
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "AssetLoaderRawFileIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderRawFile::AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult AssetLoaderRawFile::CreateAsset(const std::string& assetName, AssetCreationContext& context)
|
||||
{
|
||||
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));
|
||||
}
|
21
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.h
Normal file
21
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
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;
|
||||
};
|
||||
} // namespace IW3
|
16
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.cpp
Normal file
16
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "DefaultCreatorRawFileIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
DefaultCreatorRawFile::DefaultCreatorRawFile(MemoryManager& memory)
|
||||
: m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult DefaultCreatorRawFile::CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const
|
||||
{
|
||||
auto* asset = m_memory.Alloc<RawFile>();
|
||||
asset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, asset));
|
||||
}
|
18
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.h
Normal file
18
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IDefaultAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class DefaultCreatorRawFile : public DefaultAssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
explicit DefaultCreatorRawFile(MemoryManager& memory);
|
||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace IW3
|
Reference in New Issue
Block a user