mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-18 10:47:57 -05:00
feat: load accuracy graphs using generic 2d graph loader
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
#include "ObjLoading.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Weapon/AccuracyGraphLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
@ -370,6 +371,62 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertAccuracyGraph(const GenericGraph2D& graph,
|
||||
vec2_t*& originalGraphKnots,
|
||||
uint16_t& originalGraphKnotCount,
|
||||
vec2_t*& graphKnots,
|
||||
uint16_t& graphKnotCount,
|
||||
MemoryManager* memory)
|
||||
{
|
||||
originalGraphKnotCount = static_cast<uint16_t>(graph.knots.size());
|
||||
originalGraphKnots = memory->Alloc<vec2_t>(originalGraphKnotCount);
|
||||
|
||||
for (auto i = 0u; i < originalGraphKnotCount; i++)
|
||||
{
|
||||
const auto& commonKnot = graph.knots[i];
|
||||
originalGraphKnots[i][0] = static_cast<float>(commonKnot.x);
|
||||
originalGraphKnots[i][1] = static_cast<float>(commonKnot.y);
|
||||
}
|
||||
|
||||
graphKnots = originalGraphKnots;
|
||||
graphKnotCount = originalGraphKnotCount;
|
||||
}
|
||||
|
||||
bool LoadAccuracyGraphs(WeaponFullDef* weaponFullDef, MemoryManager* memory, const IAssetLoadingManager* manager)
|
||||
{
|
||||
auto* accuracyGraphLoader = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<AccuracyGraphLoader>();
|
||||
|
||||
if (weaponFullDef->weapDef.aiVsAiAccuracyGraphName && weaponFullDef->weapDef.aiVsAiAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsAiGraph(manager, weaponFullDef->weapDef.aiVsAiAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
ConvertAccuracyGraph(*graph,
|
||||
weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnotCount,
|
||||
weaponFullDef->weapCompleteDef.aiVsAiAccuracyGraphKnots,
|
||||
weaponFullDef->weapCompleteDef.aiVsAiAccuracyGraphKnotCount,
|
||||
memory);
|
||||
}
|
||||
|
||||
if (weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName && weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsPlayerGraph(manager, weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
ConvertAccuracyGraph(*graph,
|
||||
weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
|
||||
weaponFullDef->weapCompleteDef.aiVsPlayerAccuracyGraphKnots,
|
||||
weaponFullDef->weapCompleteDef.aiVsPlayerAccuracyGraphKnotCount,
|
||||
memory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone)
|
||||
{
|
||||
auto* weaponFullDef = memory->Create<WeaponFullDef>();
|
||||
@ -387,6 +444,8 @@ namespace
|
||||
|
||||
CalculateWeaponFields(weaponFullDef, memory);
|
||||
|
||||
LoadAccuracyGraphs(weaponFullDef, memory, manager);
|
||||
|
||||
manager->AddAsset<AssetWeapon>(
|
||||
assetName, &weaponFullDef->weapCompleteDef, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences());
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "ObjLoading.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Weapon/AccuracyGraphLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
@ -800,6 +801,62 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertAccuracyGraph(const GenericGraph2D& graph,
|
||||
vec2_t*& originalGraphKnots,
|
||||
uint16_t& originalGraphKnotCount,
|
||||
vec2_t*& graphKnots,
|
||||
uint16_t& graphKnotCount,
|
||||
MemoryManager* memory)
|
||||
{
|
||||
originalGraphKnotCount = static_cast<uint16_t>(graph.knots.size());
|
||||
originalGraphKnots = memory->Alloc<vec2_t>(originalGraphKnotCount);
|
||||
|
||||
for (auto i = 0u; i < originalGraphKnotCount; i++)
|
||||
{
|
||||
const auto& commonKnot = graph.knots[i];
|
||||
originalGraphKnots[i][0] = static_cast<float>(commonKnot.x);
|
||||
originalGraphKnots[i][1] = static_cast<float>(commonKnot.y);
|
||||
}
|
||||
|
||||
graphKnots = originalGraphKnots;
|
||||
graphKnotCount = originalGraphKnotCount;
|
||||
}
|
||||
|
||||
bool LoadAccuracyGraphs(WeaponFullDef* weaponFullDef, MemoryManager* memory, const IAssetLoadingManager* manager)
|
||||
{
|
||||
auto* accuracyGraphLoader = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<AccuracyGraphLoader>();
|
||||
|
||||
if (weaponFullDef->weapDef.aiVsAiAccuracyGraphName && weaponFullDef->weapDef.aiVsAiAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsAiGraph(manager, weaponFullDef->weapDef.aiVsAiAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
ConvertAccuracyGraph(*graph,
|
||||
weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnotCount,
|
||||
weaponFullDef->weapCompleteDef.aiVsAiAccuracyGraphKnots,
|
||||
weaponFullDef->weapCompleteDef.aiVsAiAccuracyGraphKnotCount,
|
||||
memory);
|
||||
}
|
||||
|
||||
if (weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName && weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsPlayerGraph(manager, weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
ConvertAccuracyGraph(*graph,
|
||||
weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
|
||||
weaponFullDef->weapCompleteDef.aiVsPlayerAccuracyGraphKnots,
|
||||
weaponFullDef->weapCompleteDef.aiVsPlayerAccuracyGraphKnotCount,
|
||||
memory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone)
|
||||
{
|
||||
auto* weaponFullDef = memory->Create<WeaponFullDef>();
|
||||
@ -817,6 +874,8 @@ namespace
|
||||
|
||||
CalculateWeaponFields(weaponFullDef, memory);
|
||||
|
||||
LoadAccuracyGraphs(weaponFullDef, memory, manager);
|
||||
|
||||
manager->AddAsset<AssetWeapon>(
|
||||
assetName, &weaponFullDef->weapCompleteDef, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences());
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Weapon/AccuracyGraphLoader.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
@ -385,6 +386,58 @@ namespace T6
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void ConvertAccuracyGraph(
|
||||
const GenericGraph2D& graph, vec2_t*& originalGraphKnots, int& originalGraphKnotCount, vec2_t*& graphKnots, int& graphKnotCount, MemoryManager* memory)
|
||||
{
|
||||
originalGraphKnotCount = static_cast<int>(graph.knots.size());
|
||||
originalGraphKnots = memory->Alloc<vec2_t>(originalGraphKnotCount);
|
||||
|
||||
for (auto i = 0; i < originalGraphKnotCount; i++)
|
||||
{
|
||||
const auto& commonKnot = graph.knots[i];
|
||||
originalGraphKnots[i].x = static_cast<float>(commonKnot.x);
|
||||
originalGraphKnots[i].y = static_cast<float>(commonKnot.y);
|
||||
}
|
||||
|
||||
graphKnots = originalGraphKnots;
|
||||
graphKnotCount = originalGraphKnotCount;
|
||||
}
|
||||
|
||||
bool LoadAccuracyGraphs(WeaponFullDef* weaponFullDef, MemoryManager* memory, const IAssetLoadingManager* manager)
|
||||
{
|
||||
auto* accuracyGraphLoader = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<AccuracyGraphLoader>();
|
||||
|
||||
if (weaponFullDef->weapDef.aiVsAiAccuracyGraphName && weaponFullDef->weapDef.aiVsAiAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsAiGraph(manager, weaponFullDef->weapDef.aiVsAiAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
ConvertAccuracyGraph(*graph,
|
||||
weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.originalAiVsAiAccuracyGraphKnotCount,
|
||||
weaponFullDef->weapDef.aiVsAiAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.aiVsAiAccuracyGraphKnotCount,
|
||||
memory);
|
||||
}
|
||||
|
||||
if (weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName && weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsPlayerGraph(manager, weaponFullDef->weapDef.aiVsPlayerAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
ConvertAccuracyGraph(*graph,
|
||||
weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
|
||||
weaponFullDef->weapDef.aiVsPlayerAccuracyGraphKnots,
|
||||
weaponFullDef->weapDef.aiVsPlayerAccuracyGraphKnotCount,
|
||||
memory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace T6
|
||||
|
||||
void AssetLoaderWeapon::LinkWeaponFullDefSubStructs(WeaponFullDef* weapon)
|
||||
@ -563,10 +616,12 @@ bool AssetLoaderWeapon::LoadFromInfoString(
|
||||
|
||||
weaponFullDef->weapVariantDef.szInternalName = memory->Dup(assetName.c_str());
|
||||
|
||||
// TODO: Load accuracy graph and flametable
|
||||
// TODO: Load flametable
|
||||
CalculateWeaponFields(weaponFullDef);
|
||||
CalculateAttachmentFields(weaponFullDef);
|
||||
|
||||
LoadAccuracyGraphs(weaponFullDef, memory, manager);
|
||||
|
||||
manager->AddAsset<AssetWeapon>(
|
||||
assetName, &weaponFullDef->weapVariantDef, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences());
|
||||
|
||||
|
Reference in New Issue
Block a user