chore: add writer for accuracy graphs

This commit is contained in:
Jan 2024-05-18 23:38:57 +02:00
parent 3201cefd5b
commit 5c0d1e4d99
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
3 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#pragma once
#include <string>
#include <vector>
class GenericAccuracyGraphKnot
{
public:
float x;
float y;
};
class GenericAccuracyGraph
{
public:
std::string name;
std::vector<GenericAccuracyGraphKnot> knots;
};

View File

@ -0,0 +1,57 @@
#include "AccuracyGraphWriter.h"
#include <format>
namespace
{
bool ShouldDumpAccuracyGraph(std::unordered_set<std::string>& dumpedGraphs, const std::string& graphName)
{
if (graphName.empty())
return false;
const auto existingEntry = dumpedGraphs.find(graphName);
if (existingEntry == dumpedGraphs.end())
{
dumpedGraphs.emplace(graphName);
return true;
}
return false;
}
void DumpAccuracyGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& graph, const std::string& subFolder)
{
const auto file = context.OpenAssetFile(std::format("accuracy/{}/{}", subFolder, graph.name));
if (!file)
{
std::cerr << "Failed to open file for accuracy graph: " << subFolder << "/" << graph.name << "\n";
return;
}
*file << "WEAPONACCUFILE\n\n";
*file << graph.knots.size() << "\n";
for (const auto& knot : graph.knots)
*file << std::format("{:.4f} {:.4f}\n", knot.x, knot.y);
}
} // namespace
bool AccuracyGraphWriter::ShouldDumpAiVsAiGraph(const std::string& graphName)
{
return ShouldDumpAccuracyGraph(m_dumped_ai_vs_ai_graphs, graphName);
}
bool AccuracyGraphWriter::ShouldDumpAiVsPlayerGraph(const std::string& graphName)
{
return ShouldDumpAccuracyGraph(m_dumped_ai_vs_player_graphs, graphName);
}
void AccuracyGraphWriter::DumpAiVsAiGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsAiGraph)
{
DumpAccuracyGraph(context, aiVsAiGraph, "aivsai");
}
void AccuracyGraphWriter::DumpAiVsPlayerGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsPlayerGraph)
{
DumpAccuracyGraph(context, aiVsPlayerGraph, "aivsplayer");
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "Dumping/AssetDumpingContext.h"
#include "Dumping/IZoneAssetDumperState.h"
#include "Weapon/GenericAccuracyGraph.h"
#include <string>
#include <unordered_set>
class AccuracyGraphWriter final : public IZoneAssetDumperState
{
public:
bool ShouldDumpAiVsAiGraph(const std::string& graphName);
bool ShouldDumpAiVsPlayerGraph(const std::string& graphName);
static void DumpAiVsAiGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsAiGraph);
static void DumpAiVsPlayerGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsPlayerGraph);
private:
std::unordered_set<std::string> m_dumped_ai_vs_ai_graphs;
std::unordered_set<std::string> m_dumped_ai_vs_player_graphs;
};