mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 08:05:45 +00:00
Add physconstraints loading
This commit is contained in:
parent
0dd7de3a0d
commit
7d4029b21f
@ -0,0 +1,119 @@
|
|||||||
|
#include "AssetLoaderPhysConstraints.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "Game/T6/ObjConstantsT6.h"
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
#include "Game/T6/InfoString/EnumStrings.h"
|
||||||
|
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
|
||||||
|
#include "Game/T6/InfoString/PhysConstraintsFields.h"
|
||||||
|
#include "InfoString/InfoString.h"
|
||||||
|
|
||||||
|
using namespace T6;
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
class InfoStringToPhysConstraintsConverter final : public InfoStringToStructConverter
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||||
|
{
|
||||||
|
switch (static_cast<constraintsFieldType_t>(field.iFieldType))
|
||||||
|
{
|
||||||
|
case CFT_TYPE:
|
||||||
|
return ConvertEnumInt(value, field.iOffset, s_constraintTypeNames, std::extent<decltype(s_constraintTypeNames)>::value);
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
InfoStringToPhysConstraintsConverter(const InfoString& infoString, PhysConstraints* physConstraints, ZoneScriptStrings& zoneScriptStrings, MemoryManager* memory, IAssetLoadingManager* manager,
|
||||||
|
const cspField_t* fields, const size_t fieldCount)
|
||||||
|
: InfoStringToStructConverter(infoString, physConstraints, zoneScriptStrings, memory, manager, fields, fieldCount)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetLoaderPhysConstraints::CalculatePhysConstraintsFields(PhysConstraints* physConstraints, Zone* zone)
|
||||||
|
{
|
||||||
|
for(auto& constraint : physConstraints->data)
|
||||||
|
{
|
||||||
|
constraint.targetname = zone->m_script_strings.AddOrGetScriptString("");
|
||||||
|
constraint.target_ent1 = zone->m_script_strings.AddOrGetScriptString("");
|
||||||
|
constraint.target_ent2 = zone->m_script_strings.AddOrGetScriptString("");
|
||||||
|
constraint.attach_point_type1 = ATTACH_POINT_BONE;
|
||||||
|
constraint.attach_point_type2 = ATTACH_POINT_BONE;
|
||||||
|
constraint.target_bone1 = "";
|
||||||
|
constraint.target_bone2 = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// count
|
||||||
|
{
|
||||||
|
auto foundEnd = false;
|
||||||
|
for (auto i = 0u; i < std::extent<decltype(PhysConstraints::data)>::value; i++)
|
||||||
|
{
|
||||||
|
if (physConstraints->data[i].type == CONSTRAINT_NONE)
|
||||||
|
{
|
||||||
|
foundEnd = true;
|
||||||
|
physConstraints->count = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundEnd)
|
||||||
|
physConstraints->count = std::extent<decltype(PhysConstraints::data)>::value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* AssetLoaderPhysConstraints::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||||
|
{
|
||||||
|
auto* physConstraints = memory->Create<PhysConstraints>();
|
||||||
|
memset(physConstraints, 0, sizeof(PhysConstraints));
|
||||||
|
physConstraints->name = memory->Dup(assetName.c_str());
|
||||||
|
return physConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderPhysConstraints::CanLoadFromRaw() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetLoaderPhysConstraints::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||||
|
{
|
||||||
|
const auto fileName = "physconstraints/" + assetName;
|
||||||
|
const auto file = searchPath->Open(fileName);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
InfoString infoString;
|
||||||
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *file.m_stream))
|
||||||
|
{
|
||||||
|
std::cout << "Failed to read phys constraints raw file: \"" << fileName << "\"" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* physConstraints = memory->Create<PhysConstraints>();
|
||||||
|
memset(physConstraints, 0, sizeof(PhysConstraints));
|
||||||
|
|
||||||
|
InfoStringToPhysConstraintsConverter converter(infoString, physConstraints, zone->m_script_strings, memory, manager, phys_constraints_fields, std::extent<decltype(phys_constraints_fields)>::value);
|
||||||
|
if (!converter.Convert())
|
||||||
|
{
|
||||||
|
std::cout << "Failed to parse phys constraints raw file: \"" << fileName << "\"" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CalculatePhysConstraintsFields(physConstraints, zone);
|
||||||
|
physConstraints->name = memory->Dup(assetName.c_str());
|
||||||
|
|
||||||
|
auto scrStrings = converter.GetUsedScriptStrings();
|
||||||
|
scrStrings.push_back(zone->m_script_strings.AddOrGetScriptString(""));
|
||||||
|
manager->AddAsset(ASSET_TYPE_PHYSCONSTRAINTS, assetName, physConstraints, converter.GetDependencies(), scrStrings);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
@ -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 AssetLoaderPhysConstraints final : public BasicAssetLoader<ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints>
|
||||||
|
{
|
||||||
|
static void CalculatePhysConstraintsFields(PhysConstraints* physConstraints, Zone* zone);
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
@ -6,6 +6,7 @@
|
|||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
#include "AssetLoaders/AssetLoaderFontIcon.h"
|
#include "AssetLoaders/AssetLoaderFontIcon.h"
|
||||||
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
||||||
|
#include "AssetLoaders/AssetLoaderPhysConstraints.h"
|
||||||
#include "AssetLoaders/AssetLoaderPhysPreset.h"
|
#include "AssetLoaders/AssetLoaderPhysPreset.h"
|
||||||
#include "AssetLoaders/AssetLoaderQdb.h"
|
#include "AssetLoaders/AssetLoaderQdb.h"
|
||||||
#include "AssetLoaders/AssetLoaderRawFile.h"
|
#include "AssetLoaders/AssetLoaderRawFile.h"
|
||||||
@ -34,7 +35,7 @@ namespace T6
|
|||||||
#define BASIC_LOADER(assetType, assetClass) BasicAssetLoader<assetType, assetClass>
|
#define BASIC_LOADER(assetType, assetClass) BasicAssetLoader<assetType, assetClass>
|
||||||
|
|
||||||
REGISTER_ASSET_LOADER(AssetLoaderPhysPreset)
|
REGISTER_ASSET_LOADER(AssetLoaderPhysPreset)
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints))
|
REGISTER_ASSET_LOADER(AssetLoaderPhysConstraints)
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XANIMPARTS, XAnimParts))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XANIMPARTS, XAnimParts))
|
||||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XMODEL, XModel))
|
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XMODEL, XModel))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user