mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-12 21:31:43 +00:00
Add IW5 SndCurve dumper.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "Game/IW5/IW5.h"
|
#include "Game/IW5/IW5.h"
|
||||||
#include "Game/IW5/Image/ImageLoaderEmbeddedIW5.h"
|
#include "Game/IW5/Image/ImageLoaderEmbeddedIW5.h"
|
||||||
#include "Game/IW5/Image/ImageLoaderExternalIW5.h"
|
#include "Game/IW5/Image/ImageLoaderExternalIW5.h"
|
||||||
|
#include "Sound/LoaderSoundCurveIW5.h"
|
||||||
#include "Game/IW5/Techset/PixelShaderLoaderIW5.h"
|
#include "Game/IW5/Techset/PixelShaderLoaderIW5.h"
|
||||||
#include "Game/IW5/Techset/VertexShaderLoaderIW5.h"
|
#include "Game/IW5/Techset/VertexShaderLoaderIW5.h"
|
||||||
#include "Game/IW5/XModel/LoaderXModelIW5.h"
|
#include "Game/IW5/XModel/LoaderXModelIW5.h"
|
||||||
@@ -140,7 +141,7 @@ namespace
|
|||||||
collection.AddAssetCreator(image::CreateLoaderEmbeddedIW5(memory, searchPath));
|
collection.AddAssetCreator(image::CreateLoaderEmbeddedIW5(memory, searchPath));
|
||||||
collection.AddAssetCreator(image::CreateLoaderExternalIW5(memory, searchPath));
|
collection.AddAssetCreator(image::CreateLoaderExternalIW5(memory, searchPath));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
|
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory));
|
collection.AddAssetCreator(sound_curve::CreateLoaderIW5(memory, searchPath));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory));
|
// collection.AddAssetCreator(std::make_unique<AssetLoaderLoadedSound>(memory));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderClipMap>(memory));
|
// collection.AddAssetCreator(std::make_unique<AssetLoaderClipMap>(memory));
|
||||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderComWorld>(memory));
|
// collection.AddAssetCreator(std::make_unique<AssetLoaderComWorld>(memory));
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#include "LoaderSoundCurveIW5.h"
|
||||||
|
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
#include "ObjLoading.h"
|
||||||
|
#include "Parsing/Graph2D/Graph2DReader.h"
|
||||||
|
#include "Pool/GlobalAssetPool.h"
|
||||||
|
#include "Sound/SoundCurveCommon.h"
|
||||||
|
#include "Utils/Logging/Log.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <format>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace IW5;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class LoaderSoundCurve final : public AssetCreator<AssetSoundCurve>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LoaderSoundCurve(MemoryManager& memory, ISearchPath& searchPath)
|
||||||
|
: m_memory(memory),
|
||||||
|
m_search_path(searchPath)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||||
|
{
|
||||||
|
const auto fileName = sound_curve::GetFileNameForAssetName(assetName);
|
||||||
|
const auto file = m_search_path.Open(fileName);
|
||||||
|
if (!file.IsOpen())
|
||||||
|
return AssetCreationResult::NoAction();
|
||||||
|
|
||||||
|
const auto sndCurveData = graph2d::Read("sound curve", "SNDCURVE", *file.m_stream, fileName, assetName);
|
||||||
|
|
||||||
|
if (!sndCurveData)
|
||||||
|
return AssetCreationResult::Failure();
|
||||||
|
|
||||||
|
if (sndCurveData->knots.size() > std::extent_v<decltype(SndCurve::knots)>)
|
||||||
|
{
|
||||||
|
con::error("Failed to load SndCurve \"{}\": Too many knots ({})", assetName, sndCurveData->knots.size());
|
||||||
|
return AssetCreationResult::Failure();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* sndCurve = m_memory.Alloc<SndCurve>();
|
||||||
|
sndCurve->filename = m_memory.Dup(assetName.c_str());
|
||||||
|
sndCurve->knotCount = static_cast<uint16_t>(sndCurveData->knots.size());
|
||||||
|
|
||||||
|
for (auto i = 0u; i < std::extent_v<decltype(SndCurve::knots)>; i++)
|
||||||
|
{
|
||||||
|
if (i < sndCurveData->knots.size())
|
||||||
|
{
|
||||||
|
const auto& [x, y] = sndCurveData->knots[i];
|
||||||
|
sndCurve->knots[i][0] = static_cast<float>(x);
|
||||||
|
sndCurve->knots[i][1] = static_cast<float>(y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sndCurve->knots[i][0] = 0;
|
||||||
|
sndCurve->knots[i][1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return AssetCreationResult::Success(context.AddAsset<AssetSoundCurve>(assetName, sndCurve));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
MemoryManager& m_memory;
|
||||||
|
ISearchPath& m_search_path;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace sound_curve
|
||||||
|
{
|
||||||
|
std::unique_ptr<AssetCreator<AssetSoundCurve>> CreateLoaderIW5(MemoryManager& memory, ISearchPath& searchPath)
|
||||||
|
{
|
||||||
|
return std::make_unique<LoaderSoundCurve>(memory, searchPath);
|
||||||
|
}
|
||||||
|
} // namespace sound_curve
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Asset/IAssetCreator.h"
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
#include "SearchPath/ISearchPath.h"
|
||||||
|
#include "Utils/MemoryManager.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace sound_curve
|
||||||
|
{
|
||||||
|
std::unique_ptr<AssetCreator<IW5::AssetSoundCurve>> CreateLoaderIW5(MemoryManager& memory, ISearchPath& searchPath);
|
||||||
|
} // namespace sound_curve
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Game/IW5/Techset/VertexShaderDumperIW5.h"
|
#include "Game/IW5/Techset/VertexShaderDumperIW5.h"
|
||||||
#include "Game/IW5/XModel/XModelDumperIW5.h"
|
#include "Game/IW5/XModel/XModelDumperIW5.h"
|
||||||
#include "Image/ImageDumperIW5.h"
|
#include "Image/ImageDumperIW5.h"
|
||||||
|
#include "Sound/SndCurveDumperIW5.h"
|
||||||
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
|
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
|
||||||
#include "Localize/LocalizeDumperIW5.h"
|
#include "Localize/LocalizeDumperIW5.h"
|
||||||
#include "Maps/AddonMapEntsDumperIW5.h"
|
#include "Maps/AddonMapEntsDumperIW5.h"
|
||||||
@@ -40,7 +41,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
|
|||||||
));
|
));
|
||||||
RegisterAssetDumper(std::make_unique<image::DumperIW5>());
|
RegisterAssetDumper(std::make_unique<image::DumperIW5>());
|
||||||
// REGISTER_DUMPER(AssetDumpersnd_alias_list_t)
|
// REGISTER_DUMPER(AssetDumpersnd_alias_list_t)
|
||||||
// REGISTER_DUMPER(AssetDumperSndCurve)
|
RegisterAssetDumper(std::make_unique<sound_curve::DumperIW5>());
|
||||||
RegisterAssetDumper(std::make_unique<sound::LoadedSoundDumperIW5>());
|
RegisterAssetDumper(std::make_unique<sound::LoadedSoundDumperIW5>());
|
||||||
// REGISTER_DUMPER(AssetDumperclipMap_t)
|
// REGISTER_DUMPER(AssetDumperclipMap_t)
|
||||||
// REGISTER_DUMPER(AssetDumperComWorld)
|
// REGISTER_DUMPER(AssetDumperComWorld)
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include "SndCurveDumperIW5.h"
|
||||||
|
|
||||||
|
#include "Sound/SndCurveDumper.h"
|
||||||
|
#include "Sound/SoundCurveCommon.h"
|
||||||
|
|
||||||
|
using namespace IW5;
|
||||||
|
|
||||||
|
namespace sound_curve
|
||||||
|
{
|
||||||
|
void DumperIW5::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetSoundCurve::Type>& asset)
|
||||||
|
{
|
||||||
|
const auto* sndCurve = asset.Asset();
|
||||||
|
|
||||||
|
const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(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 sound_curve
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Dumping/AbstractAssetDumper.h"
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
|
||||||
|
namespace sound_curve
|
||||||
|
{
|
||||||
|
class DumperIW5 final : public AbstractAssetDumper<IW5::AssetSoundCurve>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW5::AssetSoundCurve::Type>& asset) override;
|
||||||
|
};
|
||||||
|
} // namespace sound_curve
|
||||||
Reference in New Issue
Block a user