mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-06 00:37:26 +00:00
refactor: streamline sound dumping
This commit is contained in:
45
src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp
Normal file
45
src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "SndCurveDumperIW4.h"
|
||||
|
||||
#include "Dumping/SndCurve/SndCurveDumper.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "soundaliases/" << assetName << ".vfcurve";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace IW4::sound
|
||||
{
|
||||
bool SndCurveDumper::ShouldDump(XAssetInfo<SndCurve>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void SndCurveDumper::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]);
|
||||
}
|
||||
} // namespace IW4::sound
|
Reference in New Issue
Block a user