chore: use generic xmodel loader and dumper code for t5

This commit is contained in:
Jan
2024-09-13 21:51:12 +02:00
parent 28ecee3a1d
commit a2735b4f23
13 changed files with 243 additions and 541 deletions

View File

@ -0,0 +1,42 @@
#include "AssetLoaderXModel.h"
#include "Game/T5/T5.h"
#include "Game/T5/XModel/XModelLoaderT5.h"
#include "Pool/GlobalAssetPool.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T5;
void* AssetLoaderXModel::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{
auto* asset = memory->Alloc<AssetXModel::Type>();
asset->name = memory->Dup(assetName.c_str());
return asset;
}
bool AssetLoaderXModel::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderXModel::LoadFromRaw(
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
const auto file = searchPath->Open(std::format("xmodel/{}.json", assetName));
if (!file.IsOpen())
return false;
auto* xmodel = memory->Alloc<XModel>();
xmodel->name = memory->Dup(assetName.c_str());
std::vector<XAssetInfoGeneric*> dependencies;
if (LoadXModel(*file.m_stream, *xmodel, memory, manager, dependencies))
manager->AddAsset<AssetXModel>(assetName, xmodel, std::move(dependencies));
else
std::cerr << std::format("Failed to load xmodel \"{}\"\n", assetName);
return true;
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "AssetLoading/BasicAssetLoader.h"
#include "AssetLoading/IAssetLoadingManager.h"
#include "Game/T5/T5.h"
#include "SearchPath/ISearchPath.h"
namespace T5
{
class AssetLoaderXModel final : public BasicAssetLoader<AssetXModel>
{
static std::string GetFileNameForAsset(const std::string& assetName);
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 T5

View File

@ -3,6 +3,7 @@
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
#include "AssetLoaders/AssetLoaderRawFile.h"
#include "AssetLoaders/AssetLoaderStringTable.h"
#include "AssetLoaders/AssetLoaderXModel.h"
#include "AssetLoading/AssetLoadingManager.h"
#include "Game/T5/GameAssetPoolT5.h"
#include "Game/T5/GameT5.h"
@ -27,7 +28,7 @@ ObjLoader::ObjLoader()
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetPhysConstraints>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetDestructibleDef>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetXAnim>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetXModel>)
REGISTER_ASSET_LOADER(AssetLoaderXModel)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetMaterial>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetTechniqueSet>)
REGISTER_ASSET_LOADER(BasicAssetLoader<AssetImage>)

View File

@ -0,0 +1,49 @@
#include "XModelLoaderT5.h"
#include "Game/T5/CommonT5.h"
#include "Game/T5/XModel/JsonXModel.h"
#define GAME_NAMESPACE T5
namespace T5
{
const char* HITLOC_NAMES[]{
// clang-format off
"none",
"helmet",
"head",
"neck",
"torso_upper",
"torso_lower",
"right_arm_upper",
"left_arm_upper",
"right_arm_lower",
"left_arm_lower",
"right_hand",
"left_hand",
"right_leg_upper",
"left_leg_upper",
"right_leg_lower",
"left_leg_lower",
"right_foot",
"left_foot",
"gun",
// clang-format on
};
static_assert(std::extent_v<decltype(HITLOC_NAMES)> == HITLOC_COUNT);
} // namespace T5
#include "XModel/GenericXModelLoader.inc.h"
namespace T5
{
bool LoadXModel(std::istream& stream, XModel& xmodel, MemoryManager* memory, IAssetLoadingManager* manager, std::vector<XAssetInfoGeneric*>& dependencies)
{
std::set<XAssetInfoGeneric*> dependenciesSet;
XModelLoader loader(stream, *memory, *manager, dependenciesSet);
dependencies.assign(dependenciesSet.cbegin(), dependenciesSet.cend());
return loader.Load(xmodel);
}
} // namespace T5

View File

@ -0,0 +1,13 @@
#pragma once
#include "AssetLoading/IAssetLoadingManager.h"
#include "Game/T5/T5.h"
#include "Utils/MemoryManager.h"
#include <istream>
#include <vector>
namespace T5
{
bool LoadXModel(std::istream& stream, XModel& xmodel, MemoryManager* memory, IAssetLoadingManager* manager, std::vector<XAssetInfoGeneric*>& dependencies);
}