#include "LightDefLoaderIW3.h" #include "Game/IW3/IW3.h" #include "Game/IW3/LightDef/LightDefAssetCreationStateIW3.h" #include "LightDef/LightDefCommon.h" #include "Utils/Logging/Log.h" #include #include #include using namespace IW3; namespace { class LoaderLightDef final : public AssetCreator { public: LoaderLightDef(MemoryManager& memory, ISearchPath& searchPath) : m_memory(memory), m_search_path(searchPath) { } AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { const auto filename = light_def::GetFileNameForAsset(assetName); const auto file = m_search_path.Open(filename); if (!file.IsOpen()) return AssetCreationResult::NoAction(); auto* lightDef = m_memory.Alloc(); lightDef->name = m_memory.Dup(assetName.c_str()); AssetRegistration registration(assetName, lightDef); std::string imageName; int8_t samplerState; file.m_stream->read(reinterpret_cast(&samplerState), sizeof(int8_t)); std::getline(*file.m_stream, imageName, '\0'); auto* imageDependency = context.LoadDependency(imageName); if (!imageDependency) { con::error("Could not load GfxLightDef \"{}\" due to missing image \"{}\"", assetName, imageName); return AssetCreationResult::Failure(); } registration.AddDependency(imageDependency); lightDef->attenuation.samplerState = samplerState; lightDef->attenuation.image = imageDependency->Asset(); context.GetZoneAssetCreationState().SetLightDefLookupStart(lightDef, context); return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } private: MemoryManager& m_memory; ISearchPath& m_search_path; }; } // namespace namespace light_def { std::unique_ptr> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } } // namespace light_def