feat: dump iw5 accuracy graphs

This commit is contained in:
Jan 2024-05-18 23:39:17 +02:00
parent 5c0d1e4d99
commit 36a2e48e5b
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
2 changed files with 49 additions and 0 deletions

View File

@ -4,12 +4,14 @@
#include "Game/IW5/InfoString/InfoStringFromStructConverter.h"
#include "Game/IW5/InfoString/WeaponFields.h"
#include "Game/IW5/ObjConstantsIW5.h"
#include "Weapon/AccuracyGraphWriter.h"
#include <bit>
#include <cassert>
#include <cstring>
#include <sstream>
#include <type_traits>
#include <unordered_set>
using namespace IW5;
@ -532,6 +534,23 @@ namespace IW5
const WeaponFullDef* m_weapon;
};
GenericAccuracyGraph ConvertAccuracyGraph(const char* graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericAccuracyGraph graph;
graph.name = graphName;
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i][0];
knot.y = originalKnots[i][1];
}
return graph;
}
} // namespace IW5
void AssetDumperWeapon::CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef)
@ -681,6 +700,33 @@ InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo<WeaponCompleteDef>* as
return converter.Convert();
}
void AssetDumperWeapon::DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset)
{
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
const auto weapon = asset->Asset();
const auto* weapDef = weapon->weapDef;
if (!weapDef)
return;
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
{
AccuracyGraphWriter::DumpAiVsAiGraph(
context,
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount));
}
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
{
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
weapDef->originalAiVsPlayerAccuracyGraphKnots,
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
}
}
bool AssetDumperWeapon::ShouldDump(XAssetInfo<WeaponCompleteDef>* asset)
{
return true;
@ -710,4 +756,6 @@ void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo<Weapo
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON);
stream.write(stringValue.c_str(), stringValue.size());
}
DumpAccuracyGraphs(context, asset);
}

View File

@ -10,6 +10,7 @@ namespace IW5
{
static void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef);
static InfoString CreateInfoString(XAssetInfo<WeaponCompleteDef>* asset);
static void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset);
protected:
bool ShouldDump(XAssetInfo<WeaponCompleteDef>* asset) override;