mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-13 05:41:43 +00:00
Merge pull request #753 from pagingred/iw5_physpreset_dumper
feat: phys presets dumping and loading for IW3, IW5, T5
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
#include "InfoStringToStructConverter.h"
|
||||
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
InfoStringToStructConverter::InfoStringToStructConverter(const InfoString& infoString,
|
||||
void* structure,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
GenericAssetRegistration& registration,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount)
|
||||
: InfoStringToStructConverterBase(infoString, structure, zoneScriptStrings, memory, context, registration),
|
||||
m_fields(fields),
|
||||
m_field_count(fieldCount)
|
||||
{
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, const std::string& value)
|
||||
{
|
||||
switch (static_cast<csParseFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case CSPFT_STRING:
|
||||
return ConvertString(value, field.iOffset);
|
||||
|
||||
case CSPFT_STRING_MAX_STRING_CHARS:
|
||||
return ConvertStringBuffer(value, field.iOffset, 1024);
|
||||
|
||||
case CSPFT_STRING_MAX_QPATH:
|
||||
return ConvertStringBuffer(value, field.iOffset, 64);
|
||||
|
||||
case CSPFT_STRING_MAX_OSPATH:
|
||||
return ConvertStringBuffer(value, field.iOffset, 256);
|
||||
|
||||
case CSPFT_INT:
|
||||
return ConvertInt(value, field.iOffset);
|
||||
|
||||
case CSPFT_QBOOLEAN:
|
||||
return ConvertQBoolean(value, field.iOffset);
|
||||
|
||||
case CSPFT_FLOAT:
|
||||
return ConvertFloat(value, field.iOffset);
|
||||
|
||||
case CSPFT_MILLISECONDS:
|
||||
return ConvertMilliseconds(value, field.iOffset);
|
||||
|
||||
case CSPFT_FX:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<FxEffectDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* fx = m_context.LoadDependency<AssetFx>(value);
|
||||
|
||||
if (fx == nullptr)
|
||||
{
|
||||
con::error("Failed to load fx asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(fx);
|
||||
*reinterpret_cast<FxEffectDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = fx->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_XMODEL:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* xmodel = m_context.LoadDependency<AssetXModel>(value);
|
||||
|
||||
if (xmodel == nullptr)
|
||||
{
|
||||
con::error("Failed to load xmodel asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(xmodel);
|
||||
*reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = xmodel->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_MATERIAL:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* material = m_context.LoadDependency<AssetMaterial>(value);
|
||||
|
||||
if (material == nullptr)
|
||||
{
|
||||
con::error("Failed to load material asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(material);
|
||||
*reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = material->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_SOUND:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
reinterpret_cast<SndAliasCustom*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset)->name = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* name = m_memory.Alloc<snd_alias_list_name>();
|
||||
name->soundName = m_memory.Dup(value.c_str());
|
||||
|
||||
reinterpret_cast<SndAliasCustom*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset)->name = name;
|
||||
|
||||
m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference<AssetSound>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_NUM_BASE_FIELD_TYPES:
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverter::Convert()
|
||||
{
|
||||
for (auto fieldIndex = 0u; fieldIndex < m_field_count; fieldIndex++)
|
||||
{
|
||||
const auto& field = m_fields[fieldIndex];
|
||||
assert(field.iFieldType >= 0);
|
||||
|
||||
auto foundValue = false;
|
||||
const auto& value = m_info_string.GetValueForKey(std::string(field.szName), &foundValue);
|
||||
|
||||
if (foundValue)
|
||||
{
|
||||
if (field.iFieldType < CSPFT_NUM_BASE_FIELD_TYPES)
|
||||
{
|
||||
if (!ConvertBaseField(field, value))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ConvertExtensionField(field, value))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "InfoString/InfoStringToStructConverterBase.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class InfoStringToStructConverter : public InfoStringToStructConverterBase
|
||||
{
|
||||
public:
|
||||
InfoStringToStructConverter(const InfoString& infoString,
|
||||
void* structure,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
GenericAssetRegistration& registration,
|
||||
const cspField_t* fields,
|
||||
size_t fieldCount);
|
||||
bool Convert() override;
|
||||
|
||||
protected:
|
||||
virtual bool ConvertExtensionField(const cspField_t& field, const std::string& value) = 0;
|
||||
bool ConvertBaseField(const cspField_t& field, const std::string& value);
|
||||
|
||||
const cspField_t* m_fields;
|
||||
size_t m_field_count;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "Localize/AssetLoaderLocalizeIW3.h"
|
||||
#include "Material/LoaderMaterialIW3.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "PhysPreset/GdtLoaderPhysPresetIW3.h"
|
||||
#include "PhysPreset/RawLoaderPhysPresetIW3.h"
|
||||
#include "RawFile/AssetLoaderRawFileIW3.h"
|
||||
#include "StringTable/AssetLoaderStringTableIW3.h"
|
||||
|
||||
@@ -89,11 +91,12 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetStringTable>>(zone));
|
||||
}
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
||||
{
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
collection.AddAssetCreator(phys_preset::CreateRawLoaderIW3(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(phys_preset::CreateGdtLoaderIW3(memory, gdt, zone));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||
collection.AddAssetCreator(xmodel::CreateLoaderIW3(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(material::CreateLoaderIW3(memory, searchPath));
|
||||
@@ -129,6 +132,6 @@ namespace
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const
|
||||
{
|
||||
ConfigureDefaultCreators(collection, zone);
|
||||
ConfigureLoaders(collection, zone, searchPath);
|
||||
ConfigureLoaders(collection, zone, searchPath, gdt);
|
||||
ConfigureGlobalAssetPoolsLoaders(collection, zone);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "GdtLoaderPhysPresetIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/ObjConstantsIW3.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysPresetIW3.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
namespace
|
||||
{
|
||||
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
: m_gdt(gdt),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(GDF_FILENAME_PHYS_PRESET, assetName);
|
||||
if (gdtEntry == nullptr)
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromGdtProperties(*gdtEntry))
|
||||
{
|
||||
con::error("Failed to read phys preset gdt entry: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
IGdtQueryable& m_gdt;
|
||||
phys_preset::InfoStringLoaderIW3 m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW3::AssetPhysPreset>> CreateGdtLoaderIW3(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
{
|
||||
return std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone);
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW3::AssetPhysPreset>> CreateGdtLoaderIW3(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,90 @@
|
||||
#include "InfoStringLoaderPhysPresetIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/InfoString/InfoStringToStructConverter.h"
|
||||
#include "Game/IW3/PhysPreset/PhysPresetFields.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
namespace
|
||||
{
|
||||
class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter
|
||||
{
|
||||
public:
|
||||
InfoStringToPhysPresetConverter(const InfoString& infoString,
|
||||
void* structure,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
GenericAssetRegistration& registration,
|
||||
const cspField_t* fields,
|
||||
size_t fieldCount)
|
||||
: InfoStringToStructConverter(infoString, structure, zoneScriptStrings, memory, context, registration, fields, fieldCount)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||
{
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void CopyFromPhysPresetInfo(const PhysPresetInfo& physPresetInfo, PhysPreset& physPreset)
|
||||
{
|
||||
physPreset.mass = physPresetInfo.mass;
|
||||
physPreset.bounce = physPresetInfo.bounce;
|
||||
|
||||
if (physPresetInfo.isFrictionInfinity != 0)
|
||||
physPreset.friction = std::numeric_limits<float>::max();
|
||||
else
|
||||
physPreset.friction = physPresetInfo.friction;
|
||||
|
||||
physPreset.bulletForceScale = physPresetInfo.bulletForceScale;
|
||||
physPreset.explosiveForceScale = physPresetInfo.explosiveForceScale;
|
||||
physPreset.sndAliasPrefix = physPresetInfo.sndAliasPrefix;
|
||||
physPreset.piecesSpreadFraction = physPresetInfo.piecesSpreadFraction;
|
||||
physPreset.piecesUpwardVelocity = physPresetInfo.piecesUpwardVelocity;
|
||||
physPreset.tempDefaultToCylinder = physPresetInfo.tempDefaultToCylinder != 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
InfoStringLoaderIW3::InfoStringLoaderIW3(MemoryManager& memory, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult InfoStringLoaderIW3::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
PhysPresetInfo presetInfo;
|
||||
std::memset(&presetInfo, 0, sizeof(presetInfo));
|
||||
|
||||
auto* physPreset = m_memory.Alloc<PhysPreset>();
|
||||
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
|
||||
|
||||
InfoStringToPhysPresetConverter converter(
|
||||
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
|
||||
if (!converter.Convert())
|
||||
{
|
||||
con::error("Failed to parse phys preset: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
CopyFromPhysPresetInfo(presetInfo, *physPreset);
|
||||
physPreset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreationContext.h"
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
class InfoStringLoaderIW3
|
||||
{
|
||||
public:
|
||||
InfoStringLoaderIW3(MemoryManager& memory, Zone& zone);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
Zone& m_zone;
|
||||
};
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "RawLoaderPhysPresetIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/ObjConstantsIW3.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysPresetIW3.h"
|
||||
#include "PhysPreset/PhysPresetCommon.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
namespace
|
||||
{
|
||||
class RawLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_search_path(searchPath),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = phys_preset::GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
||||
{
|
||||
con::error("Could not parse as info string file: \"{}\"", fileName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
phys_preset::InfoStringLoaderIW3 m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawLoaderIW3(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW3::AssetPhysPreset>> CreateRawLoaderIW3(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace phys_preset
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "Material/LoaderMaterialIW5.h"
|
||||
#include "Menu/LoaderMenuListIW5.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "PhysPreset/GdtLoaderPhysPresetIW5.h"
|
||||
#include "PhysPreset/RawLoaderPhysPresetIW5.h"
|
||||
#include "RawFile/LoaderRawFileIW5.h"
|
||||
#include "Script/LoaderScriptFileIW5.h"
|
||||
#include "StringTable/LoaderStringTableIW5.h"
|
||||
@@ -125,7 +127,8 @@ namespace
|
||||
{
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
collection.AddAssetCreator(phys_preset::CreateRawLoaderIW5(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(phys_preset::CreateGdtLoaderIW5(memory, gdt, zone));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXModelSurfs>(memory));
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "GdtLoaderPhysPresetIW5.h"
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/ObjConstantsIW5.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysPresetIW5.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
: m_gdt(gdt),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(GDF_FILENAME_PHYS_PRESET, assetName);
|
||||
if (gdtEntry == nullptr)
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromGdtProperties(*gdtEntry))
|
||||
{
|
||||
con::error("Failed to read phys preset gdt entry: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
IGdtQueryable& m_gdt;
|
||||
phys_preset::InfoStringLoaderIW5 m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW5::AssetPhysPreset>> CreateGdtLoaderIW5(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
{
|
||||
return std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone);
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW5::AssetPhysPreset>> CreateGdtLoaderIW5(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "InfoStringLoaderPhysPresetIW5.h"
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/InfoString/EnumStrings.h"
|
||||
#include "Game/IW5/InfoString/InfoStringToStructConverter.h"
|
||||
#include "Game/IW5/PhysPreset/PhysPresetFields.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter
|
||||
{
|
||||
public:
|
||||
InfoStringToPhysPresetConverter(const InfoString& infoString,
|
||||
void* structure,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
GenericAssetRegistration& registration,
|
||||
const cspField_t* fields,
|
||||
size_t fieldCount)
|
||||
: InfoStringToStructConverter(infoString, structure, zoneScriptStrings, memory, context, registration, fields, fieldCount)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||
{
|
||||
switch (static_cast<physPresetFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case PPFT_SCALING:
|
||||
return ConvertEnumInt(field.szName, value, field.iOffset, szPhysPresetScalingNames, std::extent_v<decltype(szPhysPresetScalingNames)>);
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void CopyFromPhysPresetInfo(const PhysPresetInfo& physPresetInfo, PhysPreset& physPreset)
|
||||
{
|
||||
physPreset.mass = physPresetInfo.mass;
|
||||
physPreset.bounce = physPresetInfo.bounce;
|
||||
physPreset.friction = physPresetInfo.friction;
|
||||
physPreset.bulletForceScale = physPresetInfo.bulletForceScale;
|
||||
physPreset.explosiveForceScale = physPresetInfo.explosiveForceScale;
|
||||
physPreset.sndAliasPrefix = physPresetInfo.sndAliasPrefix;
|
||||
physPreset.piecesSpreadFraction = physPresetInfo.piecesSpreadFraction;
|
||||
physPreset.piecesUpwardVelocity = physPresetInfo.piecesUpwardVelocity;
|
||||
physPreset.minMomentum = physPresetInfo.minMomentum;
|
||||
physPreset.maxMomentum = physPresetInfo.maxMomentum;
|
||||
physPreset.minPitch = physPresetInfo.minPitch;
|
||||
physPreset.maxPitch = physPresetInfo.maxPitch;
|
||||
physPreset.volumeType = physPresetInfo.volumeType;
|
||||
physPreset.pitchType = physPresetInfo.pitchType;
|
||||
physPreset.tempDefaultToCylinder = physPresetInfo.tempDefaultToCylinder != 0;
|
||||
physPreset.perSurfaceSndAlias = physPresetInfo.perSurfaceSndAlias != 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
InfoStringLoaderIW5::InfoStringLoaderIW5(MemoryManager& memory, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult InfoStringLoaderIW5::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
PhysPresetInfo presetInfo;
|
||||
std::memset(&presetInfo, 0, sizeof(presetInfo));
|
||||
|
||||
auto* physPreset = m_memory.Alloc<PhysPreset>();
|
||||
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
|
||||
|
||||
InfoStringToPhysPresetConverter converter(
|
||||
infoString, &presetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
|
||||
if (!converter.Convert())
|
||||
{
|
||||
con::error("Failed to parse phys preset: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
CopyFromPhysPresetInfo(presetInfo, *physPreset);
|
||||
physPreset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreationContext.h"
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
class InfoStringLoaderIW5
|
||||
{
|
||||
public:
|
||||
InfoStringLoaderIW5(MemoryManager& memory, Zone& zone);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
Zone& m_zone;
|
||||
};
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "RawLoaderPhysPresetIW5.h"
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/ObjConstantsIW5.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysPresetIW5.h"
|
||||
#include "PhysPreset/PhysPresetCommon.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class RawLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_search_path(searchPath),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = phys_preset::GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
||||
{
|
||||
con::error("Could not parse as info string file: \"{}\"", fileName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
phys_preset::InfoStringLoaderIW5 m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawLoaderIW5(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW5::AssetPhysPreset>> CreateRawLoaderIW5(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,181 @@
|
||||
#include "InfoStringToStructConverter.h"
|
||||
|
||||
#include "Game/T5/CommonT5.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
InfoStringToStructConverter::InfoStringToStructConverter(const InfoString& infoString,
|
||||
void* structure,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
GenericAssetRegistration& registration,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount)
|
||||
: InfoStringToStructConverterBase(infoString, structure, zoneScriptStrings, memory, context, registration),
|
||||
m_fields(fields),
|
||||
m_field_count(fieldCount)
|
||||
{
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverter::ConvertBaseField(const cspField_t& field, const std::string& value)
|
||||
{
|
||||
switch (static_cast<csParseFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case CSPFT_STRING:
|
||||
return ConvertString(value, field.iOffset);
|
||||
|
||||
case CSPFT_STRING_MAX_STRING_CHARS:
|
||||
return ConvertStringBuffer(value, field.iOffset, 1024);
|
||||
|
||||
case CSPFT_STRING_MAX_QPATH:
|
||||
return ConvertStringBuffer(value, field.iOffset, 64);
|
||||
|
||||
case CSPFT_STRING_MAX_OSPATH:
|
||||
return ConvertStringBuffer(value, field.iOffset, 256);
|
||||
|
||||
case CSPFT_INT:
|
||||
return ConvertInt(value, field.iOffset);
|
||||
|
||||
case CSPFT_BOOL:
|
||||
return ConvertBool(value, field.iOffset);
|
||||
|
||||
case CSPFT_QBOOLEAN:
|
||||
return ConvertQBoolean(value, field.iOffset);
|
||||
|
||||
case CSPFT_FLOAT:
|
||||
return ConvertFloat(value, field.iOffset);
|
||||
|
||||
case CSPFT_MILLISECONDS:
|
||||
return ConvertMilliseconds(value, field.iOffset);
|
||||
|
||||
case CSPFT_FX:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<FxEffectDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* fx = m_context.LoadDependency<AssetFx>(value);
|
||||
|
||||
if (fx == nullptr)
|
||||
{
|
||||
con::error("Failed to load fx asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(fx);
|
||||
*reinterpret_cast<FxEffectDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = fx->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_XMODEL:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* xmodel = m_context.LoadDependency<AssetXModel>(value);
|
||||
|
||||
if (xmodel == nullptr)
|
||||
{
|
||||
con::error("Failed to load xmodel asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(xmodel);
|
||||
*reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = xmodel->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_MATERIAL:
|
||||
case CSPFT_MATERIAL_STREAM:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* material = m_context.LoadDependency<AssetMaterial>(value);
|
||||
|
||||
if (material == nullptr)
|
||||
{
|
||||
con::error("Failed to load material asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(material);
|
||||
*reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = material->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_PHYS_PRESET:
|
||||
{
|
||||
if (value.empty())
|
||||
{
|
||||
*reinterpret_cast<PhysPreset**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* physPreset = m_context.LoadDependency<AssetPhysPreset>(value);
|
||||
|
||||
if (physPreset == nullptr)
|
||||
{
|
||||
con::error("Failed to load physpreset asset \"{}\"", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_registration.AddDependency(physPreset);
|
||||
*reinterpret_cast<PhysPreset**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset) = physPreset->Asset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case CSPFT_SCRIPT_STRING:
|
||||
return ConvertScriptString(value, field.iOffset);
|
||||
|
||||
case CSPFT_NUM_BASE_FIELD_TYPES:
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverter::Convert()
|
||||
{
|
||||
for (auto fieldIndex = 0u; fieldIndex < m_field_count; fieldIndex++)
|
||||
{
|
||||
const auto& field = m_fields[fieldIndex];
|
||||
assert(field.iFieldType >= 0);
|
||||
|
||||
auto foundValue = false;
|
||||
const auto& value = m_info_string.GetValueForKey(std::string(field.szName), &foundValue);
|
||||
|
||||
if (foundValue)
|
||||
{
|
||||
if (field.iFieldType < CSPFT_NUM_BASE_FIELD_TYPES)
|
||||
{
|
||||
if (!ConvertBaseField(field, value))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ConvertExtensionField(field, value))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/T5/T5.h"
|
||||
#include "InfoString/InfoStringToStructConverterBase.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class InfoStringToStructConverter : public InfoStringToStructConverterBase
|
||||
{
|
||||
public:
|
||||
InfoStringToStructConverter(const InfoString& infoString,
|
||||
void* structure,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
GenericAssetRegistration& registration,
|
||||
const cspField_t* fields,
|
||||
size_t fieldCount);
|
||||
bool Convert() override;
|
||||
|
||||
protected:
|
||||
virtual bool ConvertExtensionField(const cspField_t& field, const std::string& value) = 0;
|
||||
bool ConvertBaseField(const cspField_t& field, const std::string& value);
|
||||
|
||||
const cspField_t* m_fields;
|
||||
size_t m_field_count;
|
||||
};
|
||||
} // namespace T5
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "Localize/LoaderLocalizeT5.h"
|
||||
#include "Material/LoaderMaterialT5.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "PhysPreset/GdtLoaderPhysPresetT5.h"
|
||||
#include "PhysPreset/RawLoaderPhysPresetT5.h"
|
||||
#include "RawFile/LoaderRawFileT5.h"
|
||||
#include "StringTable/LoaderStringTableT5.h"
|
||||
|
||||
@@ -101,11 +103,12 @@ namespace
|
||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetEmblemSet>>(zone));
|
||||
}
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
||||
{
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
collection.AddAssetCreator(phys_preset::CreateRawLoaderT5(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(phys_preset::CreateGdtLoaderT5(memory, gdt, zone));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysConstraints>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderDestructibleDef>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||
@@ -147,6 +150,6 @@ namespace
|
||||
void ObjLoader::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) const
|
||||
{
|
||||
ConfigureDefaultCreators(collection, zone);
|
||||
ConfigureLoaders(collection, zone, searchPath);
|
||||
ConfigureLoaders(collection, zone, searchPath, gdt);
|
||||
ConfigureGlobalAssetPoolsLoaders(collection, zone);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "GdtLoaderPhysPresetT5.h"
|
||||
|
||||
#include "Game/T5/ObjConstantsT5.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysPresetT5.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
: m_gdt(gdt),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(GDF_FILENAME_PHYS_PRESET, assetName);
|
||||
if (gdtEntry == nullptr)
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromGdtProperties(*gdtEntry))
|
||||
{
|
||||
con::error("Failed to read phys preset gdt entry: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
IGdtQueryable& m_gdt;
|
||||
phys_preset::InfoStringLoaderT5 m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateGdtLoaderT5(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
{
|
||||
return std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone);
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<T5::AssetPhysPreset>> CreateGdtLoaderT5(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,100 @@
|
||||
#include "InfoStringLoaderPhysPresetT5.h"
|
||||
|
||||
#include "Game/T5/InfoString/InfoStringToStructConverter.h"
|
||||
#include "Game/T5/ObjConstantsT5.h"
|
||||
#include "Game/T5/PhysPreset/PhysPresetFields.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class InfoStringToPhysPresetConverter final : public InfoStringToStructConverter
|
||||
{
|
||||
protected:
|
||||
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||
{
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringToPhysPresetConverter(const InfoString& infoString,
|
||||
PhysPresetInfo& physPreset,
|
||||
ZoneScriptStrings& zoneScriptStrings,
|
||||
MemoryManager& memory,
|
||||
AssetCreationContext& context,
|
||||
AssetRegistration<AssetPhysPreset>& registration,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount)
|
||||
: InfoStringToStructConverter(infoString, &physPreset, zoneScriptStrings, memory, context, registration, fields, fieldCount)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void CopyFromPhysPresetInfo(const PhysPresetInfo& physPresetInfo, PhysPreset& physPreset)
|
||||
{
|
||||
physPreset.mass = std::clamp(physPresetInfo.mass, 1.0f, 2000.0f) * 0.001f;
|
||||
physPreset.bounce = physPresetInfo.bounce;
|
||||
|
||||
if (physPresetInfo.isFrictionInfinity != 0)
|
||||
physPreset.friction = MAX_FRICTION;
|
||||
else
|
||||
physPreset.friction = physPresetInfo.friction;
|
||||
|
||||
physPreset.bulletForceScale = physPresetInfo.bulletForceScale;
|
||||
physPreset.explosiveForceScale = physPresetInfo.explosiveForceScale;
|
||||
physPreset.piecesSpreadFraction = physPresetInfo.piecesSpreadFraction;
|
||||
physPreset.piecesUpwardVelocity = physPresetInfo.piecesUpwardVelocity;
|
||||
physPreset.canFloat = physPresetInfo.canFloat;
|
||||
physPreset.gravityScale = std::clamp(physPresetInfo.gravityScale, 0.01f, 10.0f);
|
||||
physPreset.centerOfMassOffset = physPresetInfo.centerOfMassOffset;
|
||||
physPreset.buoyancyBoxMin = physPresetInfo.buoyancyBoxMin;
|
||||
physPreset.buoyancyBoxMax = physPresetInfo.buoyancyBoxMax;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
InfoStringLoaderT5::InfoStringLoaderT5(MemoryManager& memory, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult InfoStringLoaderT5::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
auto* physPreset = m_memory.Alloc<PhysPreset>();
|
||||
physPreset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
|
||||
|
||||
PhysPresetInfo physPresetInfo;
|
||||
memset(&physPresetInfo, 0, sizeof(physPresetInfo));
|
||||
InfoStringToPhysPresetConverter converter(infoString,
|
||||
physPresetInfo,
|
||||
m_zone.m_script_strings,
|
||||
m_memory,
|
||||
context,
|
||||
registration,
|
||||
phys_preset_fields,
|
||||
std::extent_v<decltype(phys_preset_fields)>);
|
||||
if (!converter.Convert())
|
||||
{
|
||||
con::error("Failed to parse phys preset: \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
CopyFromPhysPresetInfo(physPresetInfo, *physPreset);
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreationContext.h"
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
class InfoStringLoaderT5
|
||||
{
|
||||
public:
|
||||
InfoStringLoaderT5(MemoryManager& memory, Zone& zone);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
Zone& m_zone;
|
||||
};
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "RawLoaderPhysPresetT5.h"
|
||||
|
||||
#include "Game/T5/ObjConstantsT5.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysPresetT5.h"
|
||||
#include "PhysPreset/PhysPresetCommon.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class RawLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_search_path(searchPath),
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = phys_preset::GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
InfoString infoString;
|
||||
if (!infoString.FromStream(INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
||||
{
|
||||
con::error("Could not parse as info string file: \"{}\"", fileName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
return m_info_string_loader.CreateAsset(assetName, infoString, context);
|
||||
}
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
phys_preset::InfoStringLoaderT5 m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawLoaderT5(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace phys_preset
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<T5::AssetPhysPreset>> CreateRawLoaderT5(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace phys_preset
|
||||
Reference in New Issue
Block a user