mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Add ZBarrier loading
This commit is contained in:
parent
7d7fdb16aa
commit
23653e3067
98
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp
Normal file
98
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include "AssetLoaderZBarrier.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "Game/T6/ObjConstantsT6.h"
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
|
||||||
|
#include "Game/T6/InfoString/ZBarrierFields.h"
|
||||||
|
#include "InfoString/InfoString.h"
|
||||||
|
|
||||||
|
using namespace T6;
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
class InfoStringToZBarrierConverter final : public InfoStringToStructConverter
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
InfoStringToZBarrierConverter(const InfoString& infoString, ZBarrierDef* zbarrier, ZoneScriptStrings& zoneScriptStrings, MemoryManager* memory, IAssetLoadingManager* manager,
|
||||||
|
const cspField_t* fields, const size_t fieldCount)
|
||||||
|
: InfoStringToStructConverter(infoString, zbarrier, zoneScriptStrings, memory, manager, fields, fieldCount)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetLoaderZBarrier::CalculateZBarrierFields(ZBarrierDef* zbarrier)
|
||||||
|
{
|
||||||
|
// numBoardsInBarrier
|
||||||
|
{
|
||||||
|
auto foundEnd = false;
|
||||||
|
for (auto i = 0u; i < std::extent<decltype(ZBarrierDef::boards)>::value; i++)
|
||||||
|
{
|
||||||
|
if (zbarrier->boards[i].pBoardModel == nullptr)
|
||||||
|
{
|
||||||
|
foundEnd = true;
|
||||||
|
zbarrier->numBoardsInBarrier = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundEnd)
|
||||||
|
zbarrier->numBoardsInBarrier = std::extent<decltype(ZBarrierDef::boards)>::value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* AssetLoaderZBarrier::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||||
|
{
|
||||||
|
auto* zbarrier = memory->Create<ZBarrierDef>();
|
||||||
|
memset(zbarrier, 0, sizeof(ZBarrierDef));
|
||||||
|
CalculateZBarrierFields(zbarrier);
|
||||||
|
zbarrier->name = memory->Dup(assetName.c_str());
|
||||||
|
return zbarrier;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderZBarrier::CanLoadFromRaw() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderZBarrier::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||||
|
{
|
||||||
|
const auto fileName = "zbarrier/" + assetName;
|
||||||
|
const auto file = searchPath->Open(fileName);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
InfoString infoString;
|
||||||
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *file.m_stream))
|
||||||
|
{
|
||||||
|
std::cout << "Failed to read zbarrier raw file: \"" << fileName << "\"" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* zbarrier = memory->Create<ZBarrierDef>();
|
||||||
|
memset(zbarrier, 0, sizeof(ZBarrierDef));
|
||||||
|
|
||||||
|
InfoStringToZBarrierConverter converter(infoString, zbarrier, zone->m_script_strings, memory, manager, zbarrier_fields, std::extent<decltype(zbarrier_fields)>::value);
|
||||||
|
if (!converter.Convert())
|
||||||
|
{
|
||||||
|
std::cout << "Failed to parse zbarrier raw file: \"" << fileName << "\"" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CalculateZBarrierFields(zbarrier);
|
||||||
|
zbarrier->name = memory->Dup(assetName.c_str());
|
||||||
|
|
||||||
|
manager->AddAsset(ASSET_TYPE_ZBARRIER, assetName, zbarrier, converter.GetDependencies(), converter.GetUsedScriptStrings());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
18
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.h
Normal file
18
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
#include "AssetLoading/BasicAssetLoader.h"
|
||||||
|
#include "AssetLoading/IAssetLoadingManager.h"
|
||||||
|
#include "SearchPath/ISearchPath.h"
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
class AssetLoaderZBarrier final : public BasicAssetLoader<ASSET_TYPE_ZBARRIER, ZBarrierDef>
|
||||||
|
{
|
||||||
|
static void CalculateZBarrierFields(ZBarrierDef* zbarrier);
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
#include "AssetLoaders/AssetLoaderWeapon.h"
|
#include "AssetLoaders/AssetLoaderWeapon.h"
|
||||||
#include "AssetLoaders/AssetLoaderWeaponAttachment.h"
|
#include "AssetLoaders/AssetLoaderWeaponAttachment.h"
|
||||||
#include "AssetLoaders/AssetLoaderWeaponAttachmentUnique.h"
|
#include "AssetLoaders/AssetLoaderWeaponAttachmentUnique.h"
|
||||||
|
#include "AssetLoaders/AssetLoaderZBarrier.h"
|
||||||
#include "AssetLoading/AssetLoadingManager.h"
|
#include "AssetLoading/AssetLoadingManager.h"
|
||||||
#include "Image/Texture.h"
|
#include "Image/Texture.h"
|
||||||
#include "Image/IwiLoader.h"
|
#include "Image/IwiLoader.h"
|
||||||
@ -77,7 +78,7 @@ namespace T6
|
|||||||
REGISTER_ASSET_LOADER(AssetLoaderSlug)
|
REGISTER_ASSET_LOADER(AssetLoaderSlug)
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_ZBARRIER, ZBarrierDef))
|
REGISTER_ASSET_LOADER(AssetLoaderZBarrier)
|
||||||
|
|
||||||
#undef BASIC_LOADER
|
#undef BASIC_LOADER
|
||||||
#undef REGISTER_ASSET_LOADER
|
#undef REGISTER_ASSET_LOADER
|
||||||
|
Loading…
x
Reference in New Issue
Block a user