iw4x-client/src/Components/Modules/AssetInterfaces/IRawFile.cpp

61 lines
1.5 KiB
C++
Raw Normal View History

2016-07-11 11:37:36 -04:00
#include <STDInclude.hpp>
namespace Assets
{
void IRawFile::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
2016-07-11 11:37:36 -04:00
{
Components::FileSystem::File rawFile(name);
if (rawFile.exists())
2016-07-11 11:37:36 -04:00
{
Game::RawFile* asset = builder->getAllocator()->allocate<Game::RawFile>();
2016-07-11 11:37:36 -04:00
if (asset)
{
//std::string data = Utils::Compression::ZLib::Compress(rawFile.getBuffer());
2016-07-11 11:37:36 -04:00
asset->name = builder->getAllocator()->duplicateString(name);
asset->compressedData = builder->getAllocator()->duplicateString(rawFile.getBuffer());
2016-07-11 11:37:36 -04:00
asset->sizeCompressed = 0;//data.size();
asset->sizeUnCompressed = rawFile.getBuffer().size();
2016-07-11 11:37:36 -04:00
header->rawfile = asset;
}
}
}
void IRawFile::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
2016-07-11 11:37:36 -04:00
{
AssertSize(Game::RawFile, 16);
2016-07-11 11:37:36 -04:00
Utils::Stream* buffer = builder->getBuffer();
2016-07-11 11:37:36 -04:00
Game::RawFile* asset = header.rawfile;
Game::RawFile* dest = buffer->dest<Game::RawFile>();
buffer->save(asset);
2016-07-11 11:37:36 -04:00
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
2016-07-11 11:37:36 -04:00
if (asset->name)
{
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
2016-07-11 11:37:36 -04:00
Utils::Stream::ClearPointer(&dest->name);
}
if (asset->compressedData)
{
if (asset->sizeCompressed)
{
buffer->save(asset->compressedData, asset->sizeCompressed);
2016-07-11 11:37:36 -04:00
}
else
{
buffer->save(asset->compressedData, asset->sizeUnCompressed + 1);
2016-07-11 11:37:36 -04:00
}
Utils::Stream::ClearPointer(&dest->compressedData);
}
buffer->popBlock();
2016-07-11 11:37:36 -04:00
}
}