diff --git a/src/ObjCommon/LightDef/LightDefCommon.cpp b/src/ObjCommon/LightDef/LightDefCommon.cpp new file mode 100644 index 00000000..b43af370 --- /dev/null +++ b/src/ObjCommon/LightDef/LightDefCommon.cpp @@ -0,0 +1,11 @@ +#include "LightDefCommon.h" + +#include + +namespace light_def +{ + std::string GetFileNameForAsset(const std::string& assetName) + { + return std::format("lights/{}", assetName); + } +} // namespace light_def diff --git a/src/ObjCommon/LightDef/LightDefCommon.h b/src/ObjCommon/LightDef/LightDefCommon.h new file mode 100644 index 00000000..22002431 --- /dev/null +++ b/src/ObjCommon/LightDef/LightDefCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace light_def +{ + std::string GetFileNameForAsset(const std::string& assetName); +} diff --git a/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp similarity index 91% rename from src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp rename to src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp index 0563554e..abf4bf0b 100644 --- a/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.cpp +++ b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.cpp @@ -1,12 +1,15 @@ -#include "LoaderLightDefIW4.h" +#include "LightDefLoaderIW4.h" #include "Game/IW4/IW4.h" +#include "LightDef/LightDefCommon.h" #include #include #include + using namespace IW4; +using namespace ::light_def; namespace { @@ -23,7 +26,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto filename = GetAssetFilename(assetName); + const auto filename = GetFileNameForAsset(assetName); const auto file = m_search_path.Open(filename); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -61,11 +64,6 @@ namespace } private: - std::string GetAssetFilename(const std::string& assetName) - { - return std::format("lights/{}", assetName); - } - MemoryManager& m_memory; ISearchPath& m_search_path; }; diff --git a/src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.h b/src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.h similarity index 100% rename from src/ObjLoading/Game/IW4/LightDef/LoaderLightDefIW4.h rename to src/ObjLoading/Game/IW4/LightDef/LightDefLoaderIW4.h diff --git a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp index f90d1afd..1fc97241 100644 --- a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp @@ -5,7 +5,7 @@ #include "Game/IW4/IW4.h" #include "Game/IW4/XModel/LoaderXModelIW4.h" #include "Leaderboard/LoaderLeaderboardIW4.h" -#include "LightDef/LoaderLightDefIW4.h" +#include "LightDef/LightDefLoaderIW4.h" #include "Localize/LoaderLocalizeIW4.h" #include "Material/LoaderMaterialIW4.h" #include "Menu/LoaderMenuListIW4.h" diff --git a/src/ObjWriting/Game/IW4/LightDef/AssetDumperGfxLightDef.cpp b/src/ObjWriting/Game/IW4/LightDef/AssetDumperGfxLightDef.cpp deleted file mode 100644 index af05c62d..00000000 --- a/src/ObjWriting/Game/IW4/LightDef/AssetDumperGfxLightDef.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "AssetDumperGfxLightDef.h" - -#include - -using namespace IW4; - -std::string AssetDumperGfxLightDef::GetAssetFilename(const std::string& assetName) -{ - std::ostringstream ss; - - ss << "lights/" << assetName; - - return ss.str(); -} - -bool AssetDumperGfxLightDef::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperGfxLightDef::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto* lightDef = asset->Asset(); - const auto assetFile = context.OpenAssetFile(GetAssetFilename(asset->m_name)); - - if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr) - return; - - auto& stream = *assetFile; - - const auto* imageName = lightDef->attenuation.image->name; - if (imageName[0] == ',') - imageName = &imageName[1]; - - stream << lightDef->attenuation.samplerState << imageName << static_cast(lightDef->lmapLookupStart); -} diff --git a/src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.cpp b/src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.cpp new file mode 100644 index 00000000..549da3d1 --- /dev/null +++ b/src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.cpp @@ -0,0 +1,33 @@ +#include "LightDefDumperIW4.h" + +#include "LightDef/LightDefCommon.h" + +#include + +using namespace IW4; +using namespace ::light_def; + +namespace IW4::light_def +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto* lightDef = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetFileNameForAsset(asset->m_name)); + + if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr) + return; + + auto& stream = *assetFile; + + const auto* imageName = lightDef->attenuation.image->name; + if (imageName[0] == ',') + imageName = &imageName[1]; + + stream << lightDef->attenuation.samplerState << imageName << static_cast(lightDef->lmapLookupStart); + } +} // namespace IW4::light_def diff --git a/src/ObjWriting/Game/IW4/LightDef/AssetDumperGfxLightDef.h b/src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.h similarity index 63% rename from src/ObjWriting/Game/IW4/LightDef/AssetDumperGfxLightDef.h rename to src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.h index 275712ef..9b8003c9 100644 --- a/src/ObjWriting/Game/IW4/LightDef/AssetDumperGfxLightDef.h +++ b/src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.h @@ -3,12 +3,10 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/IW4/IW4.h" -namespace IW4 +namespace IW4::light_def { - class AssetDumperGfxLightDef final : public AbstractAssetDumper + class Dumper final : public AbstractAssetDumper { - static std::string GetAssetFilename(const std::string& assetName); - protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; diff --git a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp index 1be58651..40a370b6 100644 --- a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp +++ b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp @@ -4,7 +4,7 @@ #include "Game/IW4/XModel/XModelDumperIW4.h" #include "Image/AssetDumperGfxImage.h" #include "Leaderboard/LeaderboardJsonDumperIW4.h" -#include "LightDef/AssetDumperGfxLightDef.h" +#include "LightDef/LightDefDumperIW4.h" #include "Localize/AssetDumperLocalizeEntry.h" #include "Maps/AssetDumperAddonMapEnts.h" #include "Material/DumperMaterialIW4.h" @@ -57,7 +57,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const // DUMP_ASSET_POOL(AssetDumperMapEnts, m_map_ents, ASSET_TYPE_MAP_ENTS) // DUMP_ASSET_POOL(AssetDumperFxWorld, m_fx_world, ASSET_TYPE_FXWORLD) // DUMP_ASSET_POOL(AssetDumperGfxWorld, m_gfx_world, ASSET_TYPE_GFXWORLD) - DUMP_ASSET_POOL(AssetDumperGfxLightDef, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF) + DUMP_ASSET_POOL(light_def::Dumper, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF) // DUMP_ASSET_POOL(AssetDumperFont_s, m_font, ASSET_TYPE_FONT) DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST) DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU)