2016-07-11 11:37:36 -04:00
|
|
|
#include <STDInclude.hpp>
|
|
|
|
|
|
|
|
namespace Assets
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
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);
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
if (rawFile.exists())
|
2016-07-11 11:37:36 -04:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::RawFile* asset = builder->getAllocator()->allocate<Game::RawFile>();
|
2016-07-11 11:37:36 -04:00
|
|
|
|
|
|
|
if (asset)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
//std::string data = Utils::Compression::ZLib::Compress(rawFile.getBuffer());
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05: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();
|
2016-11-20 08:09:07 -05:00
|
|
|
asset->sizeUnCompressed = rawFile.getBuffer().size();
|
2016-07-11 11:37:36 -04:00
|
|
|
|
|
|
|
header->rawfile = asset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IRawFile::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
2016-07-11 11:37:36 -04:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::RawFile, 16);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-07-11 11:37:36 -04:00
|
|
|
Game::RawFile* asset = header.rawfile;
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::RawFile* dest = buffer->dest<Game::RawFile>();
|
|
|
|
buffer->save(asset);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
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)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->save(asset->compressedData, asset->sizeCompressed);
|
2016-07-11 11:37:36 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->save(asset->compressedData, asset->sizeUnCompressed + 1);
|
2016-07-11 11:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils::Stream::ClearPointer(&dest->compressedData);
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-07-11 11:37:36 -04:00
|
|
|
}
|
|
|
|
}
|