2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-06-26 10:58:04 +00:00

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
+1
View File
@@ -23,6 +23,7 @@ namespace
constexpr const char* SUB_ASSET_TYPE_NAMES[]{
"technique",
"accuracygraph",
};
static_assert(std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)> == SUB_ASSET_TYPE_COUNT);
} // namespace
+8
View File
@@ -63,6 +63,7 @@ namespace IW4
enum SubAssetType
{
SUB_ASSET_TYPE_TECHNIQUE,
SUB_ASSET_TYPE_ACCURACY_GRAPH,
SUB_ASSET_TYPE_COUNT
};
@@ -186,6 +187,12 @@ namespace IW4
VFT_NUM,
};
struct AccuracyGraph
{
vec2_t* graphKnots;
int graphKnotCount;
};
using AssetPhysPreset = Asset<ASSET_TYPE_PHYSPRESET, PhysPreset>;
using AssetPhysCollMap = Asset<ASSET_TYPE_PHYSCOLLMAP, PhysCollmap>;
using AssetXAnim = Asset<ASSET_TYPE_XANIMPARTS, XAnimParts>;
@@ -225,6 +232,7 @@ namespace IW4
using AssetAddonMapEnts = Asset<ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts>;
using SubAssetTechnique = SubAsset<SUB_ASSET_TYPE_TECHNIQUE, MaterialTechnique>;
using SubAssetAccuracyGraph = SubAsset<SUB_ASSET_TYPE_ACCURACY_GRAPH, AccuracyGraph>;
} // namespace IW4
DEFINE_ASSET_NAME_ACCESSOR(IW4::AssetPhysPreset, name);
+1
View File
@@ -60,6 +60,7 @@ namespace
constexpr const char* SUB_ASSET_TYPE_NAMES[]{
"technique",
"accuracygraph",
};
static_assert(std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)> == SUB_ASSET_TYPE_COUNT);
} // namespace
+8
View File
@@ -66,6 +66,7 @@ namespace IW5
enum SubAssetType
{
SUB_ASSET_TYPE_TECHNIQUE,
SUB_ASSET_TYPE_ACCURACY_GRAPH,
SUB_ASSET_TYPE_COUNT
};
@@ -204,6 +205,12 @@ namespace IW5
PPFT_NUM_FIELD_TYPES,
};
struct AccuracyGraph
{
vec2_t* graphKnots;
int graphKnotCount;
};
using AssetPhysPreset = Asset<ASSET_TYPE_PHYSPRESET, PhysPreset>;
using AssetPhysCollMap = Asset<ASSET_TYPE_PHYSCOLLMAP, PhysCollmap>;
using AssetXAnim = Asset<ASSET_TYPE_XANIMPARTS, XAnimParts>;
@@ -246,6 +253,7 @@ namespace IW5
using AssetAddonMapEnts = Asset<ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts>;
using SubAssetTechnique = SubAsset<SUB_ASSET_TYPE_TECHNIQUE, MaterialTechnique>;
using SubAssetAccuracyGraph = SubAsset<SUB_ASSET_TYPE_ACCURACY_GRAPH, AccuracyGraph>;
} // namespace IW5
DEFINE_ASSET_NAME_ACCESSOR(IW5::AssetPhysPreset, name);
+1
View File
@@ -24,6 +24,7 @@ namespace
"vertexdecl",
"vertexshader",
"pixelshader",
"accuracygraph",
"flametable",
};
static_assert(std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)> == SUB_ASSET_TYPE_COUNT);
+8
View File
@@ -66,6 +66,7 @@ namespace T5
SUB_ASSET_TYPE_VERTEX_DECL,
SUB_ASSET_TYPE_VERTEX_SHADER,
SUB_ASSET_TYPE_PIXEL_SHADER,
SUB_ASSET_TYPE_ACCURACY_GRAPH,
SUB_ASSET_TYPE_FLAME_TABLE,
SUB_ASSET_TYPE_COUNT
@@ -176,6 +177,12 @@ namespace T5
CFT_NUM_FIELD_TYPES
};
struct AccuracyGraph
{
vec2_t* graphKnots;
int graphKnotCount;
};
using AssetPhysPreset = Asset<ASSET_TYPE_PHYSPRESET, PhysPreset>;
using AssetPhysConstraints = Asset<ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints>;
using AssetDestructibleDef = Asset<ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef>;
@@ -214,6 +221,7 @@ namespace T5
using SubAssetVertexDecl = SubAsset<SUB_ASSET_TYPE_VERTEX_DECL, MaterialVertexDeclaration>;
using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialVertexShader>;
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialPixelShader>;
using SubAssetAccuracyGraph = SubAsset<SUB_ASSET_TYPE_ACCURACY_GRAPH, AccuracyGraph>;
using SubAssetFlameTable = SubAsset<SUB_ASSET_TYPE_FLAME_TABLE, FlameTable>;
} // namespace T5
+1
View File
@@ -77,6 +77,7 @@ namespace
"vertexdecl",
"vertexshader",
"pixelshader",
"accuracygraph",
"flametable",
};
static_assert(std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)> == SUB_ASSET_TYPE_COUNT);
+8
View File
@@ -86,6 +86,7 @@ namespace T6
SUB_ASSET_TYPE_VERTEX_DECL,
SUB_ASSET_TYPE_VERTEX_SHADER,
SUB_ASSET_TYPE_PIXEL_SHADER,
SUB_ASSET_TYPE_ACCURACY_GRAPH,
SUB_ASSET_TYPE_FLAME_TABLE,
SUB_ASSET_TYPE_COUNT
@@ -239,6 +240,12 @@ namespace T6
AUFT_NUM_FIELD_TYPES,
};
struct AccuracyGraph
{
vec2_t* graphKnots;
int graphKnotCount;
};
using AssetPhysPreset = Asset<ASSET_TYPE_PHYSPRESET, PhysPreset>;
using AssetPhysConstraints = Asset<ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints>;
using AssetDestructibleDef = Asset<ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef>;
@@ -293,6 +300,7 @@ namespace T6
using SubAssetVertexDecl = SubAsset<SUB_ASSET_TYPE_VERTEX_DECL, MaterialVertexDeclaration>;
using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialVertexShader>;
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialPixelShader>;
using SubAssetAccuracyGraph = SubAsset<SUB_ASSET_TYPE_ACCURACY_GRAPH, AccuracyGraph>;
using SubAssetFlameTable = SubAsset<SUB_ASSET_TYPE_FLAME_TABLE, FlameTable>;
} // namespace T6
+15
View File
@@ -9,6 +9,21 @@ namespace weapon
return std::format("weapons/{}", assetName);
}
std::string GetFileNameForAccuracyGraph(const std::string& assetName)
{
return std::format("accuracy/{}", assetName);
}
std::string GetAssetNameForAiVsAiAccuracyGraph(const std::string& graphName)
{
return std::format("aivsai/{}", graphName);
}
std::string GetAssetNameForAiVsPlayerAccuracyGraph(const std::string& graphName)
{
return std::format("aivsplayer/{}", graphName);
}
std::string GetFileNameForFlameTable(const std::string& flameTableName)
{
return std::format("weapons/{}", flameTableName);
+5
View File
@@ -5,5 +5,10 @@
namespace weapon
{
std::string GetFileNameForAssetName(const std::string& assetName);
std::string GetFileNameForAccuracyGraph(const std::string& assetName);
std::string GetAssetNameForAiVsAiAccuracyGraph(const std::string& graphName);
std::string GetAssetNameForAiVsPlayerAccuracyGraph(const std::string& graphName);
std::string GetFileNameForFlameTable(const std::string& flameTableName);
} // namespace weapon
+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;
+3
View File
@@ -8,6 +8,7 @@
#include "Game/IW5/Image/ImageLoaderExternalIW5.h"
#include "Game/IW5/Techset/PixelShaderLoaderIW5.h"
#include "Game/IW5/Techset/VertexShaderLoaderIW5.h"
#include "Game/IW5/Weapon/AccuracyGraphLoaderIW5.h"
#include "Game/IW5/XAnim/XAnimLoaderIW5.h"
#include "Game/IW5/XModel/LoaderXModelIW5.h"
#include "Leaderboard/LoaderLeaderboardIW5.h"
@@ -171,6 +172,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::CreateAccuracyGraphLoaderIW5(memory, searchPath));
}
} // namespace
@@ -4,7 +4,7 @@
#include "Game/IW5/InfoString/InfoStringToStructConverter.h"
#include "Game/IW5/Weapon/WeaponFields.h"
#include "Utils/Logging/Log.h"
#include "Weapon/AccuracyGraphLoader.h"
#include "Weapon/WeaponCommon.h"
#include <cassert>
#include <cstring>
@@ -797,57 +797,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;
+2
View File
@@ -8,6 +8,7 @@
#include "Game/T5/T5.h"
#include "Game/T5/Techset/PixelShaderLoaderT5.h"
#include "Game/T5/Techset/VertexShaderLoaderT5.h"
#include "Game/T5/Weapon/AccuracyGraphLoaderT5.h"
#include "Game/T5/XAnim/XAnimLoaderT5.h"
#include "Game/T5/XModel/LoaderXModelT5.h"
#include "LightDef/LightDefLoaderT5.h"
@@ -150,6 +151,7 @@ namespace
collection.AddSubAssetCreator(techset::CreateVertexShaderLoaderT5(memory, searchPath));
collection.AddSubAssetCreator(techset::CreatePixelShaderLoaderT5(memory, searchPath));
collection.AddSubAssetCreator(weapon::CreateAccuracyGraphLoaderT5(memory, searchPath));
collection.AddSubAssetCreator(weapon::CreateFlameTableLoaderT5(memory, searchPath, zone));
}
} // namespace
@@ -6,7 +6,7 @@
#include "Game/T5/Weapon/WeaponStrings.h"
#include "Utils/Logging/Log.h"
#include "Utils/StringUtils.h"
#include "Weapon/AccuracyGraphLoader.h"
#include "Weapon/WeaponCommon.h"
#include <cassert>
#include <cstring>
@@ -242,53 +242,58 @@ namespace
}
};
void ConvertAccuracyGraph(
const GenericGraph2D& graph, vec2_t*& originalGraphKnots, int& originalGraphKnotCount, vec2_t*& graphKnots, int& graphKnotCount, MemoryManager& memory)
bool LoadAccuracyGraph(const std::string& graphName,
vec2_t*& originalGraphKnots,
int& originalGraphKnotCount,
vec2_t*& graphKnots,
int& graphKnotCount,
AssetCreationContext& context)
{
originalGraphKnotCount = static_cast<int>(graph.knots.size());
originalGraphKnots = memory.Alloc<vec2_t>(originalGraphKnotCount);
auto* accuracyGraphAsset = context.LoadSubAsset<SubAssetAccuracyGraph>(graphName);
if (!accuracyGraphAsset)
return false;
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);
}
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 = accuracyGraph->graphKnotCount;
graphKnots = accuracyGraph->graphKnots;
graphKnotCount = 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.weapDef.aiVsAiAccuracyGraphKnots,
weaponFullDef.weapDef.aiVsAiAccuracyGraphKnotCount,
context))
{
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(searchPath, weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName);
if (!graph)
if (!LoadAccuracyGraph(weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName),
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnotCount,
context))
{
return false;
ConvertAccuracyGraph(*graph,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnotCount,
memory);
}
}
return true;
+2
View File
@@ -11,6 +11,7 @@
#include "Game/T6/T6.h"
#include "Game/T6/Techset/PixelShaderLoaderT6.h"
#include "Game/T6/Techset/VertexShaderLoaderT6.h"
#include "Game/T6/Weapon/AccuracyGraphLoaderT6.h"
#include "Game/T6/XAnim/XAnimLoaderT6.h"
#include "Game/T6/XModel/LoaderXModelT6.h"
#include "Image/Dx12TextureLoader.h"
@@ -442,6 +443,7 @@ namespace T6
collection.AddSubAssetCreator(techset::CreateVertexShaderLoaderT6(memory, searchPath));
collection.AddSubAssetCreator(techset::CreatePixelShaderLoaderT6(memory, searchPath));
collection.AddSubAssetCreator(weapon::CreateAccuracyGraphLoaderT6(memory, searchPath));
collection.AddSubAssetCreator(weapon::CreateFlameTableLoaderT6(memory, searchPath, zone));
}
} // namespace
@@ -7,7 +7,7 @@
#include "Game/T6/Weapon/WeaponStrings.h"
#include "Utils/Logging/Log.h"
#include "Utils/StringUtils.h"
#include "Weapon/AccuracyGraphLoader.h"
#include "Weapon/WeaponCommon.h"
#include <cassert>
#include <cstring>
@@ -391,53 +391,58 @@ namespace
}
};
void ConvertAccuracyGraph(
const GenericGraph2D& graph, vec2_t*& originalGraphKnots, int& originalGraphKnotCount, vec2_t*& graphKnots, int& graphKnotCount, MemoryManager& memory)
bool LoadAccuracyGraph(const std::string& graphName,
vec2_t*& originalGraphKnots,
int& originalGraphKnotCount,
vec2_t*& graphKnots,
int& graphKnotCount,
AssetCreationContext& context)
{
originalGraphKnotCount = static_cast<int>(graph.knots.size());
originalGraphKnots = memory.Alloc<vec2_t>(originalGraphKnotCount);
auto* accuracyGraphAsset = context.LoadSubAsset<SubAssetAccuracyGraph>(graphName);
if (!accuracyGraphAsset)
return false;
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);
}
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 = accuracyGraph->graphKnotCount;
graphKnots = accuracyGraph->graphKnots;
graphKnotCount = 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.weapDef.aiVsAiAccuracyGraphKnots,
weaponFullDef.weapDef.aiVsAiAccuracyGraphKnotCount,
context))
{
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(searchPath, weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName);
if (!graph)
if (!LoadAccuracyGraph(weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName),
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnotCount,
context))
{
return false;
ConvertAccuracyGraph(*graph,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.originalAiVsPlayerAccuracyGraphKnotCount,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnots,
weaponFullDef.weapDef.aiVsPlayerAccuracyGraphKnotCount,
memory);
}
}
return true;
@@ -1,55 +0,0 @@
#include "AccuracyGraphLoader.h"
#include "Parsing/Graph2D/Graph2DReader.h"
#include "Utils/Logging/Log.h"
#include <format>
#include <iostream>
namespace
{
std::unique_ptr<GenericGraph2D> LoadAccuracyGraph(ISearchPath& searchPath, const std::string& graphName, const std::string& subFolder)
{
const auto fileName = std::format("accuracy/{}/{}", subFolder, graphName);
const auto file = searchPath.Open(fileName);
if (!file.IsOpen())
{
con::error("Failed to open file for accuracy graph: {}/{}", subFolder, graphName);
return nullptr;
}
return graph2d::Read("accuracy graph", "WEAPONACCUFILE", *file.m_stream, fileName, graphName);
}
} // namespace
const GenericGraph2D* AccuracyGraphLoader::LoadAiVsAiGraph(ISearchPath& searchPath, const std::string& graphName)
{
const auto alreadyLoadedGraph = m_loaded_ai_vs_ai_graphs.find(graphName);
if (alreadyLoadedGraph != m_loaded_ai_vs_ai_graphs.end())
return alreadyLoadedGraph->second.get();
auto graph = LoadAccuracyGraph(searchPath, graphName, "aivsai");
if (!graph)
return nullptr;
const auto* graphPtr = graph.get();
m_loaded_ai_vs_ai_graphs.emplace(graphName, std::move(graph));
return graphPtr;
}
const GenericGraph2D* AccuracyGraphLoader::LoadAiVsPlayerGraph(ISearchPath& searchPath, const std::string& graphName)
{
const auto alreadyLoadedGraph = m_loaded_ai_vs_player_graphs.find(graphName);
if (alreadyLoadedGraph != m_loaded_ai_vs_player_graphs.end())
return alreadyLoadedGraph->second.get();
auto graph = LoadAccuracyGraph(searchPath, graphName, "aivsplayer");
if (!graph)
return nullptr;
const auto* graphPtr = graph.get();
m_loaded_ai_vs_player_graphs.emplace(graphName, std::move(graph));
return graphPtr;
}
@@ -0,0 +1,71 @@
#options GAME(IW4, IW5, T5, T6)
#filename "Game/" + GAME + "/Weapon/AccuracyGraphLoader" + GAME + ".cpp"
#set LOADER_HEADER "\"AccuracyGraphLoader" + GAME + ".h\""
#include LOADER_HEADER
#include "Parsing/Graph2D/Graph2DReader.h"
#include "Utils/Logging/Log.h"
#include "Weapon/WeaponCommon.h"
#include <format>
#include <iostream>
using namespace GAME;
namespace
{
class AccuracyGraphLoader final : public SubAssetCreator<SubAssetAccuracyGraph>
{
public:
AccuracyGraphLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateSubAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = weapon::GetFileNameForAccuracyGraph(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* accuracyGraph = m_memory.Alloc<AccuracyGraph>();
const auto commonAccuracyGraph = graph2d::Read("accuracy graph", "WEAPONACCUFILE", *file.m_stream, fileName, assetName);
if (!commonAccuracyGraph)
{
con::error("Failed to load accuracy graph \"{}\"", assetName);
return AssetCreationResult::Failure();
}
accuracyGraph->graphKnotCount = static_cast<int>(commonAccuracyGraph->knots.size());
accuracyGraph->graphKnots = m_memory.Alloc<vec2_t>(accuracyGraph->graphKnotCount);
for (auto i = 0; i < accuracyGraph->graphKnotCount; i++)
{
const auto& commonKnot = commonAccuracyGraph->knots[i];
accuracyGraph->graphKnots[i].x = static_cast<float>(commonKnot.x);
accuracyGraph->graphKnots[i].y = static_cast<float>(commonKnot.y);
}
return AssetCreationResult::Success(context.AddSubAsset<SubAssetAccuracyGraph>(assetName, accuracyGraph));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
#set CREATE_LOADER_METHOD "CreateAccuracyGraphLoader" + GAME
namespace weapon
{
std::unique_ptr<SubAssetCreator<SubAssetAccuracyGraph>> CREATE_LOADER_METHOD (MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<AccuracyGraphLoader>(memory, searchPath);
}
}
@@ -1,20 +0,0 @@
#pragma once
#include "Asset/IZoneAssetCreationState.h"
#include "Parsing/GenericGraph2D.h"
#include "SearchPath/ISearchPath.h"
#include <memory>
#include <string>
#include <unordered_map>
class AccuracyGraphLoader final : public IZoneAssetCreationState
{
public:
const GenericGraph2D* LoadAiVsAiGraph(ISearchPath& searchPath, const std::string& graphName);
const GenericGraph2D* LoadAiVsPlayerGraph(ISearchPath& searchPath, const std::string& graphName);
private:
std::unordered_map<std::string, std::unique_ptr<GenericGraph2D>> m_loaded_ai_vs_ai_graphs;
std::unordered_map<std::string, std::unique_ptr<GenericGraph2D>> m_loaded_ai_vs_player_graphs;
};
@@ -0,0 +1,21 @@
#options GAME (IW3, IW4, IW5, T5, T6)
#filename "Game/" + GAME + "/Weapon/AccuracyGraphLoader" + GAME + ".h"
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#pragma once
#include "Asset/IAssetCreator.h"
#include GAME_HEADER
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
#set CREATE_LOADER_METHOD "CreateAccuracyGraphLoader" + GAME
namespace weapon
{
std::unique_ptr<SubAssetCreator<GAME::SubAssetAccuracyGraph>> CREATE_LOADER_METHOD (MemoryManager& memory, ISearchPath& searchPath);
} // namespace GAME
@@ -222,23 +222,6 @@ namespace
}
};
GenericGraph2D ConvertAccuracyGraph(const char* graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = graphName;
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef)
{
fullDef->weapCompleteDef = *weapon;
@@ -374,6 +357,23 @@ namespace
return converter.Convert();
}
GenericGraph2D ConvertAccuracyGraph(std::string graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = std::move(graphName);
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void DumpAccuracyGraphs(AssetDumpingContext& context, const XAssetInfo<WeaponCompleteDef>& asset)
{
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
@@ -383,22 +383,26 @@ namespace
if (!weapDef)
return;
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsAiGraph(context,
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName,
weapDef->originalAiVsAiAccuracyGraphKnots,
weapDef->originalAiVsAiAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsAiAccuracyGraph(weapDef->aiVsAiAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph =
ConvertAccuracyGraph(std::move(graphName), weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
weapDef->originalAiVsPlayerAccuracyGraphKnots,
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph = ConvertAccuracyGraph(
std::move(graphName), weapDef->originalAiVsPlayerAccuracyGraphKnots, weapDef->originalAiVsPlayerAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
}
} // namespace
@@ -536,23 +536,6 @@ namespace
const WeaponFullDef* m_weapon;
};
GenericGraph2D ConvertAccuracyGraph(const char* graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = graphName;
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef)
{
fullDef->weapCompleteDef = *weapon;
@@ -702,6 +685,23 @@ namespace
return converter.Convert();
}
GenericGraph2D ConvertAccuracyGraph(std::string graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = std::move(graphName);
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void DumpAccuracyGraphs(AssetDumpingContext& context, const XAssetInfo<WeaponCompleteDef>& asset)
{
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
@@ -711,22 +711,26 @@ namespace
if (!weapDef)
return;
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsAiGraph(context,
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName,
weapDef->originalAiVsAiAccuracyGraphKnots,
weapDef->originalAiVsAiAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsAiAccuracyGraph(weapDef->aiVsAiAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph =
ConvertAccuracyGraph(std::move(graphName), weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
weapDef->originalAiVsPlayerAccuracyGraphKnots,
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph = ConvertAccuracyGraph(
std::move(graphName), weapDef->originalAiVsPlayerAccuracyGraphKnots, weapDef->originalAiVsPlayerAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
}
} // namespace
@@ -190,6 +190,10 @@ namespace
break;
}
case WFT_ANIM_NAME:
FillFromString(std::string(field.szName), field.iOffset);
break;
case WFT_NUM_FIELD_TYPES:
default:
assert(false);
@@ -225,23 +229,6 @@ namespace
}
};
GenericGraph2D ConvertAccuracyGraph(const char* graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = graphName;
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef)
{
fullDef->weapVariantDef = *weapon;
@@ -341,6 +328,23 @@ namespace
return converter.Convert();
}
GenericGraph2D ConvertAccuracyGraph(std::string graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = std::move(graphName);
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void DumpAccuracyGraphs(AssetDumpingContext& context, const XAssetInfo<WeaponVariantDef>& asset)
{
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
@@ -350,22 +354,26 @@ namespace
if (!weapDef)
return;
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsAiGraph(context,
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName,
weapDef->originalAiVsAiAccuracyGraphKnots,
weapDef->originalAiVsAiAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsAiAccuracyGraph(weapDef->aiVsAiAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph =
ConvertAccuracyGraph(std::move(graphName), weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
weapDef->originalAiVsPlayerAccuracyGraphKnots,
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph = ConvertAccuracyGraph(
std::move(graphName), weapDef->originalAiVsPlayerAccuracyGraphKnots, weapDef->originalAiVsPlayerAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
}
@@ -65,9 +65,14 @@ namespace
break;
}
case AUFT_NUM_FIELD_TYPES:
default:
assert(false);
break;
case AUFT_ANIM_NAME:
FillFromString(std::string(field.szName), field.iOffset);
break;
}
}
@@ -287,23 +287,6 @@ namespace
}
};
GenericGraph2D ConvertAccuracyGraph(const char* graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = graphName;
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef)
{
fullDef->weapVariantDef = *weapon;
@@ -450,6 +433,23 @@ namespace
return converter.Convert();
}
GenericGraph2D ConvertAccuracyGraph(std::string graphName, const vec2_t* originalKnots, const unsigned originalKnotCount)
{
GenericGraph2D graph;
graph.name = std::move(graphName);
graph.knots.resize(originalKnotCount);
for (auto i = 0u; i < originalKnotCount; i++)
{
auto& knot = graph.knots[i];
knot.x = originalKnots[i].x;
knot.y = originalKnots[i].y;
}
return graph;
}
void DumpAccuracyGraphs(AssetDumpingContext& context, const XAssetInfo<WeaponVariantDef>& asset)
{
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
@@ -459,22 +459,26 @@ namespace
if (!weapDef)
return;
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsAiGraph(context,
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName,
weapDef->originalAiVsAiAccuracyGraphKnots,
weapDef->originalAiVsAiAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsAiAccuracyGraph(weapDef->aiVsAiAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph =
ConvertAccuracyGraph(std::move(graphName), weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots)
{
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
weapDef->originalAiVsPlayerAccuracyGraphKnots,
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
auto graphName = weapon::GetAssetNameForAiVsPlayerAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName);
if (accuracyGraphWriter->ShouldDumpGraph(graphName))
{
const auto graph = ConvertAccuracyGraph(
std::move(graphName), weapDef->originalAiVsPlayerAccuracyGraphKnots, weapDef->originalAiVsPlayerAccuracyGraphKnotCount);
AccuracyGraphWriter::DumpGraph(context, graph);
}
}
}
+9 -17
View File
@@ -1,6 +1,8 @@
#include "AccuracyGraphWriter.h"
#include "Game/IW4/Weapon/WeaponDumperIW4.h"
#include "Utils/Logging/Log.h"
#include "Weapon/WeaponCommon.h"
#include <format>
@@ -21,12 +23,12 @@ namespace
return false;
}
void DumpAccuracyGraph(const AssetDumpingContext& context, const GenericGraph2D& graph, const std::string& subFolder)
void DumpAccuracyGraph(const AssetDumpingContext& context, const GenericGraph2D& graph)
{
const auto file = context.OpenAssetFile(std::format("accuracy/{}/{}", subFolder, graph.name));
const auto file = context.OpenAssetFile(weapon::GetFileNameForAccuracyGraph(graph.name));
if (!file)
{
con::error("Failed to open file for accuracy graph: {}/{}", subFolder, graph.name);
con::error("Failed to open file for accuracy graph: {}", graph.name);
return;
}
@@ -38,22 +40,12 @@ namespace
}
} // namespace
bool AccuracyGraphWriter::ShouldDumpAiVsAiGraph(const std::string& graphName)
bool AccuracyGraphWriter::ShouldDumpGraph(const std::string& graphName)
{
return ShouldDumpAccuracyGraph(m_dumped_ai_vs_ai_graphs, graphName);
return ShouldDumpAccuracyGraph(m_dumped_graphs, graphName);
}
bool AccuracyGraphWriter::ShouldDumpAiVsPlayerGraph(const std::string& graphName)
void AccuracyGraphWriter::DumpGraph(const AssetDumpingContext& context, const GenericGraph2D& aiVsAiGraph)
{
return ShouldDumpAccuracyGraph(m_dumped_ai_vs_player_graphs, graphName);
}
void AccuracyGraphWriter::DumpAiVsAiGraph(const AssetDumpingContext& context, const GenericGraph2D& aiVsAiGraph)
{
DumpAccuracyGraph(context, aiVsAiGraph, "aivsai");
}
void AccuracyGraphWriter::DumpAiVsPlayerGraph(const AssetDumpingContext& context, const GenericGraph2D& aiVsPlayerGraph)
{
DumpAccuracyGraph(context, aiVsPlayerGraph, "aivsplayer");
DumpAccuracyGraph(context, aiVsAiGraph);
}
+4 -6
View File
@@ -1,4 +1,5 @@
#pragma once
#include "Dumping/AssetDumpingContext.h"
#include "Dumping/IZoneAssetDumperState.h"
#include "Parsing/GenericGraph2D.h"
@@ -9,13 +10,10 @@
class AccuracyGraphWriter final : public IZoneAssetDumperState
{
public:
bool ShouldDumpAiVsAiGraph(const std::string& graphName);
bool ShouldDumpAiVsPlayerGraph(const std::string& graphName);
bool ShouldDumpGraph(const std::string& graphName);
static void DumpAiVsAiGraph(const AssetDumpingContext& context, const GenericGraph2D& aiVsAiGraph);
static void DumpAiVsPlayerGraph(const AssetDumpingContext& context, const GenericGraph2D& aiVsPlayerGraph);
static void DumpGraph(const AssetDumpingContext& context, const GenericGraph2D& graph);
private:
std::unordered_set<std::string> m_dumped_ai_vs_ai_graphs;
std::unordered_set<std::string> m_dumped_ai_vs_player_graphs;
std::unordered_set<std::string> m_dumped_graphs;
};