refactor: accuracy graph subassets (#847)

* refactor: use subassets to load accuracy graphs for iw4,iw5,t5,t6

* fix: not dumping anim names for t5 weapons and t6 attachment unique

* refactor: dump accuracy graphs like a subasset

* refactor: use shared method for accuracy graph filenames
This commit is contained in:
Jan
2026-06-20 17:16:37 +02:00
committed by GitHub
parent b5acacf680
commit b4477ac1a9
29 changed files with 464 additions and 354 deletions
+3
View File
@@ -8,6 +8,7 @@
#include "Game/IW4/Image/ImageLoaderExternalIW4.h"
#include "Game/IW4/Techset/PixelShaderLoaderIW4.h"
#include "Game/IW4/Techset/VertexShaderLoaderIW4.h"
#include "Game/IW4/Weapon/AccuracyGraphLoaderIW4.h"
#include "Game/IW4/XAnim/XAnimLoaderIW4.h"
#include "Game/IW4/XModel/LoaderXModelIW4.h"
#include "Leaderboard/LoaderLeaderboardIW4.h"
@@ -160,6 +161,8 @@ namespace
// collection.AddAssetCreator(std::make_unique<AssetLoaderTracer>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderVehicle>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderAddonMapEnts>(memory));
collection.AddSubAssetCreator(weapon::CreateAccuracyGraphLoaderIW4(memory, searchPath));
}
} // namespace
@@ -5,7 +5,7 @@
#include "Game/IW4/InfoString/InfoStringToStructConverter.h"
#include "Game/IW4/Weapon/WeaponFields.h"
#include "Utils/Logging/Log.h"
#include "Weapon/AccuracyGraphLoader.h"
#include "Weapon/WeaponCommon.h"
#include <cassert>
#include <cstring>
@@ -367,57 +367,58 @@ namespace
}
}
void ConvertAccuracyGraph(const GenericGraph2D& graph,
vec2_t*& originalGraphKnots,
uint16_t& originalGraphKnotCount,
vec2_t*& graphKnots,
uint16_t& graphKnotCount,
MemoryManager& memory)
bool LoadAccuracyGraph(const std::string& graphName,
vec2_t*& originalGraphKnots,
uint16_t& originalGraphKnotCount,
vec2_t*& graphKnots,
uint16_t& graphKnotCount,
AssetCreationContext& context)
{
originalGraphKnotCount = static_cast<uint16_t>(graph.knots.size());
originalGraphKnots = memory.Alloc<vec2_t>(originalGraphKnotCount);
auto* accuracyGraphAsset = context.LoadSubAsset<SubAssetAccuracyGraph>(graphName);
if (!accuracyGraphAsset)
return false;
for (auto i = 0u; 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);
}
const auto* accuracyGraph = accuracyGraphAsset->Asset();
graphKnots = originalGraphKnots;
graphKnotCount = originalGraphKnotCount;
assert(accuracyGraphAsset->m_dependencies.empty());
assert(accuracyGraphAsset->m_used_script_strings.empty());
assert(accuracyGraphAsset->m_indirect_asset_references.empty());
originalGraphKnots = accuracyGraph->graphKnots;
originalGraphKnotCount = static_cast<uint16_t>(accuracyGraph->graphKnotCount);
graphKnots = accuracyGraph->graphKnots;
graphKnotCount = static_cast<uint16_t>(accuracyGraph->graphKnotCount);
return true;
}
bool LoadAccuracyGraphs(WeaponFullDef& weaponFullDef, MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context)
{
auto& accuracyGraphLoader = context.GetZoneAssetCreationState<AccuracyGraphLoader>();
if (weaponFullDef.weapDef.aiVsAiAccuracyGraphName && weaponFullDef.weapDef.aiVsAiAccuracyGraphName[0])
{
const auto* graph = accuracyGraphLoader.LoadAiVsAiGraph(searchPath, weaponFullDef.weapDef.aiVsAiAccuracyGraphName);
if (!graph)
if (!LoadAccuracyGraph(weapon::GetAssetNameForAiVsAiAccuracyGraph(weaponFullDef.weapDef.aiVsAiAccuracyGraphName),
weaponFullDef.weapDef.originalAiVsAiAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsAiAccuracyGraphKnotCount,
weaponFullDef.weapCompleteDef.aiVsAiAccuracyGraphKnots,
weaponFullDef.weapCompleteDef.aiVsAiAccuracyGraphKnotCount,
context))
{
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(searchPath, weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName);
if (!graph)
if (!LoadAccuracyGraph(weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName),
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
weaponFullDef.weapCompleteDef.aiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapCompleteDef.aiVsPlayerAccuracyGraphKnotCount,
context))
{
return false;
ConvertAccuracyGraph(*graph,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
weaponFullDef.weapCompleteDef.aiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapCompleteDef.aiVsPlayerAccuracyGraphKnotCount,
memory);
}
}
return true;