[IGfxImage] Non-streamed image importer
This commit is contained in:
parent
b381fbd238
commit
4f608b3a19
@ -1,5 +1,7 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
|
||||||
|
#define IW4X_IMG_VERSION "0"
|
||||||
|
|
||||||
namespace Assets
|
namespace Assets
|
||||||
{
|
{
|
||||||
void IGfxImage::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
void IGfxImage::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||||
@ -19,13 +21,31 @@ namespace Assets
|
|||||||
image->category = 0;
|
image->category = 0;
|
||||||
image->cardMemory = 0;
|
image->cardMemory = 0;
|
||||||
|
|
||||||
image->loadDef = builder->getAllocator()->allocate<Game::GfxImageLoadDef>();
|
const char* tempName = image->name;
|
||||||
if (!image->loadDef)
|
if (tempName[0] == '*') tempName++;
|
||||||
|
|
||||||
|
Components::FileSystem::File imageFile(fmt::sprintf("images/%s.iw4xImage", tempName));
|
||||||
|
if (imageFile.exists())
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Failed to allocate GfxImageLoadDef structure!");
|
Utils::Stream::Reader reader(builder->getAllocator(), imageFile.getBuffer());
|
||||||
return;
|
|
||||||
|
if (reader.read<__int64>() != *reinterpret_cast<__int64*>("IW4xImg" IW4X_IMG_VERSION))
|
||||||
|
{
|
||||||
|
Components::Logger::Error(0, "Reading image '%s' failed, header is invalid!", name.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AssertSize(Game::MapType, 1);
|
||||||
|
image->mapType = reader.read<Game::MapType>();
|
||||||
|
image->semantic = reader.read<char>();
|
||||||
|
image->category = reader.read<char>();
|
||||||
|
|
||||||
|
image->dataLen1 = reader.read<int>();
|
||||||
|
image->dataLen2 = image->dataLen1;
|
||||||
|
|
||||||
|
image->loadDef = reinterpret_cast<Game::GfxImageLoadDef*>(reader.readArray<char>(image->dataLen1 + 16));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
char nameBuffer[MAX_PATH] = { 0 };
|
char nameBuffer[MAX_PATH] = { 0 };
|
||||||
Components::Materials::FormatImagePath(nameBuffer, sizeof(nameBuffer), 0, 0, name.data());
|
Components::Materials::FormatImagePath(nameBuffer, sizeof(nameBuffer), 0, 0, name.data());
|
||||||
Components::FileSystem::File iwi(nameBuffer);
|
Components::FileSystem::File iwi(nameBuffer);
|
||||||
@ -44,7 +64,7 @@ namespace Assets
|
|||||||
image->dataLen1 = iwiHeader->fileSizeForPicmip[0] - 32;
|
image->dataLen1 = iwiHeader->fileSizeForPicmip[0] - 32;
|
||||||
image->dataLen2 = iwiHeader->fileSizeForPicmip[0] - 32;
|
image->dataLen2 = iwiHeader->fileSizeForPicmip[0] - 32;
|
||||||
|
|
||||||
if (std::memcmp(iwiHeader->tag, "IWi", 3))
|
if (std::memcmp(iwiHeader->tag, "IWi", 3) && iwiHeader->version == 8)
|
||||||
{
|
{
|
||||||
Components::Logger::Error("Image is not a valid IWi!");
|
Components::Logger::Error("Image is not a valid IWi!");
|
||||||
return;
|
return;
|
||||||
@ -86,6 +106,7 @@ namespace Assets
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
header->image = image;
|
header->image = image;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user