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

124 lines
3.5 KiB
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#include "STDInclude.hpp"
2016-01-22 05:59:43 -05:00
namespace Assets
{
void IMaterialTechniqueSet::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
2016-01-22 05:59:43 -05:00
{
Game::MaterialTechniqueSet* asset = header.techniqueSet;
2016-01-22 05:59:43 -05:00
2016-09-16 18:14:59 -04:00
for (int i = 0; i < ARRAYSIZE(Game::MaterialTechniqueSet::techniques); ++i)
2016-01-22 05:59:43 -05:00
{
Game::MaterialTechnique* technique = asset->techniques[i];
if (!technique) continue;
2017-04-22 15:47:04 -04:00
for (short j = 0; j < technique->passCount; ++j)
2016-01-22 05:59:43 -05:00
{
2017-04-22 15:47:04 -04:00
Game::MaterialPass* pass = &technique->passArray[j];
2016-01-22 05:59:43 -05:00
if (pass->vertexDecl)
{
builder->loadAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl);
2016-01-22 05:59:43 -05:00
}
if (pass->vertexShader)
{
builder->loadAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader);
2016-01-22 05:59:43 -05:00
}
if (pass->pixelShader)
{
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader);
2016-01-22 05:59:43 -05:00
}
}
}
}
void IMaterialTechniqueSet::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
2016-01-22 05:59:43 -05:00
{
AssertSize(Game::MaterialTechniqueSet, 204);
2016-01-22 05:59:43 -05:00
Utils::Stream* buffer = builder->getBuffer();
Game::MaterialTechniqueSet* asset = header.techniqueSet;
Game::MaterialTechniqueSet* dest = buffer->dest<Game::MaterialTechniqueSet>();
buffer->save(asset);
2016-01-22 05:59:43 -05:00
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
2016-01-22 05:59:43 -05:00
if (asset->name)
{
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
2016-01-22 05:59:43 -05:00
}
// Save_MaterialTechniquePtrArray
2016-09-16 18:14:59 -04:00
static_assert(ARRAYSIZE(Game::MaterialTechniqueSet::techniques) == 48, "Techniques array invalid!");
2016-01-22 05:59:43 -05:00
2016-09-16 18:14:59 -04:00
for (int i = 0; i < ARRAYSIZE(Game::MaterialTechniqueSet::techniques); ++i)
2016-01-22 05:59:43 -05:00
{
Game::MaterialTechnique* technique = asset->techniques[i];
if (technique)
{
if (builder->hasPointer(technique))
2016-01-22 07:18:26 -05:00
{
dest->techniques[i] = builder->getPointer(technique);
2016-01-22 07:18:26 -05:00
}
else
2016-01-22 05:59:43 -05:00
{
2016-01-22 07:18:26 -05:00
// Size-check is obsolete, as the structure is dynamic
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(technique);
2016-01-22 05:59:43 -05:00
Game::MaterialTechnique* destTechnique = buffer->dest<Game::MaterialTechnique>();
buffer->save(technique, 8);
2016-01-22 05:59:43 -05:00
2016-01-22 07:18:26 -05:00
// Save_MaterialPassArray
Game::MaterialPass* destPasses = buffer->dest<Game::MaterialPass>();
2017-04-22 15:47:04 -04:00
buffer->saveArray(technique->passArray, technique->passCount);
2017-04-22 15:47:04 -04:00
for (short j = 0; j < technique->passCount; ++j)
2016-01-22 05:59:43 -05:00
{
AssertSize(Game::MaterialPass, 20);
2016-01-22 07:18:26 -05:00
Game::MaterialPass* destPass = &destPasses[j];
2017-04-22 15:47:04 -04:00
Game::MaterialPass* pass = &technique->passArray[j];
2016-01-22 07:18:26 -05:00
if (pass->vertexDecl)
{
destPass->vertexDecl = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl).vertexDecl;
2016-01-22 07:18:26 -05:00
}
if (pass->vertexShader)
{
destPass->vertexShader = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader).vertexShader;
2016-01-22 07:18:26 -05:00
}
if (pass->pixelShader)
{
destPass->pixelShader = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader).pixelShader;
2016-01-22 07:18:26 -05:00
}
2017-04-22 15:47:04 -04:00
if (pass->args)
2016-01-22 07:18:26 -05:00
{
buffer->align(Utils::Stream::ALIGN_4);
2017-04-22 15:47:04 -04:00
buffer->saveArray(pass->args, pass->perPrimArgCount + pass->perObjArgCount + pass->stableArgCount);
Utils::Stream::ClearPointer(&destPass->args);
2016-01-22 07:18:26 -05:00
}
2016-01-22 05:59:43 -05:00
}
2016-01-22 07:18:26 -05:00
if (technique->name)
2016-01-22 05:59:43 -05:00
{
buffer->saveString(technique->name);
Utils::Stream::ClearPointer(&destTechnique->name);
2016-01-22 05:59:43 -05:00
}
Utils::Stream::ClearPointer(&dest->techniques[i]);
2016-01-22 05:59:43 -05:00
}
}
}
buffer->popBlock();
2016-01-22 05:59:43 -05:00
}
}