#include "AssetLoaderGfxLightDef.h" #include #include #include #include "ObjLoading.h" #include "Game/IW4/IW4.h" #include "Pool/GlobalAssetPool.h" using namespace IW4; std::string AssetLoaderGfxLightDef::GetAssetFilename(const std::string& assetName) { std::ostringstream ss; ss << "lights/" << assetName; return ss.str(); } void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) { auto* lightDef = memory->Create(); memset(lightDef, 0, sizeof(GfxLightDef)); lightDef->name = memory->Dup(assetName.c_str()); return lightDef; } bool AssetLoaderGfxLightDef::CanLoadFromRaw() const { return true; } bool AssetLoaderGfxLightDef::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const { const auto filename = GetAssetFilename(assetName); const auto file = searchPath->Open(filename); if (!file.IsOpen()) return false; const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char); if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE) return false; std::string imageName(static_cast(imageNameSize), '\0'); int8_t samplerState; int8_t lmapLookupStart; file.m_stream->read(reinterpret_cast(&samplerState), sizeof(int8_t)); file.m_stream->read(&imageName[0], static_cast(imageNameSize)); file.m_stream->read(reinterpret_cast(&lmapLookupStart), sizeof(int8_t)); auto* imageDependency = reinterpret_cast*>(manager->LoadDependency(ASSET_TYPE_IMAGE, imageName)); if(!imageDependency) { std::cerr << "Could not load GfxLightDef \"" << assetName << "\" due to missing image \"" << imageName << "\"\n"; return false; } auto* lightDef = memory->Create(); lightDef->name = memory->Dup(assetName.c_str()); lightDef->attenuation.samplerState = samplerState; lightDef->attenuation.image = imageDependency->Asset(); lightDef->lmapLookupStart = static_cast(static_cast(lmapLookupStart)); manager->AddAsset(ASSET_TYPE_LIGHT_DEF, assetName, lightDef); return true; }