2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-05 16:27:27 +00:00

chore: implement obj loading skeleton with localize asset

This commit is contained in:
Jan
2024-12-23 22:55:58 +01:00
parent 673db0592f
commit c524cb007a
64 changed files with 1238 additions and 1038 deletions

View File

@@ -1,36 +0,0 @@
#include "AssetLoaderLocalizeEntry.h"
#include "Localize/LocalizeCommonAssetLoader.h"
using namespace T5;
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);
}

View File

@@ -1,19 +0,0 @@
#pragma once
#include "AssetLoading/BasicAssetLoader.h"
#include "AssetLoading/IAssetLoadingManager.h"
#include "Game/T5/T5.h"
#include "SearchPath/ISearchPath.h"
namespace T5
{
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 T5

View File

@@ -0,0 +1,23 @@
#include "AssetLoaderLocalizeT5.h"
using namespace T5;
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));
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include "Asset/AssetCreationContext.h"
#include "Asset/IAssetCreator.h"
#include "Game/T5/T5.h"
#include "Localize/CommonLocalizeLoader.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include "Zone/Zone.h"
namespace T5
{
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 T5

View File

@@ -1,85 +1,137 @@
#include "ObjLoaderT5.h"
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
#include "AssetLoaders/AssetLoaderRawFile.h"
#include "AssetLoaders/AssetLoaderStringTable.h"
#include "AssetLoaders/AssetLoaderXModel.h"
#include "AssetLoading/AssetLoadingManager.h"
#include "Asset/GlobalAssetPoolsLoader.h"
#include "Game/T5/GameT5.h"
#include "Image/IwiLoader.h"
#include "ObjContainer/IPak/IPak.h"
#include "Game/T5/T5.h"
#include "Localize/AssetLoaderLocalizeT5.h"
#include "ObjLoading.h"
#include <memory>
using namespace T5;
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<AssetPhysConstraints>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetDestructibleDef>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetXAnim>)
REGISTER_ASSET_LOADER(AssetLoaderXModel)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetMaterial>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetTechniqueSet>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetImage>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetSoundBank>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetSoundPatch>)
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(AssetLoaderStringTable)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetPackIndex>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetXGlobals>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetDDL>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetGlasses>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetEmblemSet>)
#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, 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();
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorPhysPreset>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorPhysConstraints>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorDestructibleDef>(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<DefaultCreatorSoundBank>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorSoundPatch>(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));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorPackIndex>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorXGlobals>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorDDL>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorGlasses>(memory));
// collection.AddDefaultAssetCreator(std::make_unique<DefaultCreatorEmblemSet>(memory));
}
void ObjLoader::FinalizeAssetsForZone(AssetLoadingContext& context) const
void ConfigureGlobalAssetPoolsLoaders(AssetCreatorCollection& collection, Zone& zone)
{
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPhysPreset>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPhysConstraints>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetDestructibleDef>>(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<AssetSoundBank>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetSoundPatch>>(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));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetPackIndex>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetXGlobals>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetDDL>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetGlasses>>(zone));
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetEmblemSet>>(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<AssetLoaderPhysConstraints>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(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));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundBank>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundPatch>(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));
// 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));
// collection.AddAssetCreator(std::make_unique<AssetLoaderPackIndex>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderXGlobals>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderDDL>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderGlasses>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderEmblemSet>(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);
}

View File

@@ -4,28 +4,14 @@
#include "IObjLoader.h"
#include "SearchPath/ISearchPath.h"
#include <memory>
#include <unordered_map>
namespace T5
{
class ObjLoader final : public IObjLoader
{
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;
private:
static bool IsMpZone(const Zone& zone);
static bool IsZmZone(const Zone& zone);
std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>> m_asset_loaders_by_type;
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) const override;
};
} // namespace T5