mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-02 22:08:11 +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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user