Dump iw4 sound curves

This commit is contained in:
Jan 2022-01-02 11:21:45 +01:00
parent 0e076bf47c
commit 2a6ed376d2
5 changed files with 121 additions and 1 deletions

View File

@ -0,0 +1,44 @@
#include "SndCurveDumper.h"
#include <cassert>
#include <iomanip>
SndCurveDumper::SndCurveDumper(std::ostream& stream)
: SndCurveDumper(stream, DEFAULT_PRECISION)
{
}
SndCurveDumper::SndCurveDumper(std::ostream& stream, const size_t precision)
: m_stream(stream),
m_precision(precision),
m_current_knot(0u),
m_total_knots(0u)
{
}
void SndCurveDumper::Init(const size_t totalKnots)
{
m_total_knots = totalKnots;
m_current_knot = 0;
m_stream << "SNDCURVE\n\n";
m_stream << totalKnots;
}
void SndCurveDumper::WriteKnot(const float x, const float y)
{
assert(m_current_knot >= m_total_knots);
m_stream << "\n" << std::fixed << std::setprecision(m_precision) << x << " " << y;
m_current_knot++;
}
void SndCurveDumper::WriteKnot(const double x, const double y)
{
assert(m_current_knot >= m_total_knots);
m_stream << x << " " << y << "\n";
m_current_knot++;
}

View File

@ -0,0 +1,20 @@
#pragma once
#include <ostream>
class SndCurveDumper
{
static constexpr auto DEFAULT_PRECISION = 4;
std::ostream& m_stream;
size_t m_precision;
size_t m_current_knot;
size_t m_total_knots;
public:
explicit SndCurveDumper(std::ostream& stream);
SndCurveDumper(std::ostream& stream, size_t precision);
void Init(size_t totalKnots);
void WriteKnot(float x, float y);
void WriteKnot(double x, double y);
};

View File

@ -0,0 +1,39 @@
#include "AssetDumperSndCurve.h"
#include <sstream>
#include "Dumping/SndCurve/SndCurveDumper.h"
using namespace IW4;
std::string AssetDumperSndCurve::GetAssetFilename(const std::string& assetName)
{
std::ostringstream ss;
ss << "soundaliases/" << assetName << ".vfcurve";
return ss.str();
}
bool AssetDumperSndCurve::ShouldDump(XAssetInfo<SndCurve>* asset)
{
return true;
}
void AssetDumperSndCurve::DumpAsset(AssetDumpingContext& context, XAssetInfo<SndCurve>* asset)
{
const auto* sndCurve = asset->Asset();
const auto assetFile = context.OpenAssetFile(GetAssetFilename(sndCurve->filename));
if (!assetFile)
return;
SndCurveDumper dumper(*assetFile);
const auto knotCount = std::min(static_cast<size_t>(sndCurve->knotCount), std::extent_v<decltype(SndCurve::knots)>);
dumper.Init(knotCount);
for (auto i = 0u; i < knotCount; i++)
dumper.WriteKnot(sndCurve->knots[i][0], sndCurve->knots[i][1]);
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW4/IW4.h"
namespace IW4
{
class AssetDumperSndCurve final : public AbstractAssetDumper<SndCurve>
{
static std::string GetAssetFilename(const std::string& assetName);
protected:
bool ShouldDump(XAssetInfo<SndCurve>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<SndCurve>* asset) override;
};
}

View File

@ -12,6 +12,7 @@
#include "AssetDumpers/AssetDumperMenuList.h"
#include "AssetDumpers/AssetDumperPhysPreset.h"
#include "AssetDumpers/AssetDumperRawFile.h"
#include "AssetDumpers/AssetDumperSndCurve.h"
#include "AssetDumpers/AssetDumperStringTable.h"
#include "AssetDumpers/AssetDumperVehicle.h"
#include "AssetDumpers/AssetDumperWeapon.h"
@ -46,7 +47,7 @@ bool ZoneDumper::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperMaterialTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(AssetDumperGfxImage, m_image, ASSET_TYPE_IMAGE)
// DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND)
// DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE)
DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE)
DUMP_ASSET_POOL(AssetDumperLoadedSound, m_loaded_sound, ASSET_TYPE_LOADED_SOUND)
// DUMP_ASSET_POOL(AssetDumperclipMap_t, m_clip_map, ASSET_TYPE_CLIPMAP_MP)
// DUMP_ASSET_POOL(AssetDumperComWorld, m_com_world, ASSET_TYPE_COMWORLD)