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

131 lines
3.2 KiB
C++
Raw Normal View History

2016-01-25 17:47:50 -05:00
#include <STDInclude.hpp>
namespace Assets
{
void IPhysCollmap::saveBrushWrapper(Components::ZoneBuilder::Zone* builder, Game::BrushWrapper* brush)
2016-01-25 17:47:50 -05:00
{
AssertSize(Game::BrushWrapper, 68);
2016-01-25 17:47:50 -05:00
Utils::Stream* buffer = builder->getBuffer();
2016-01-25 17:47:50 -05:00
Game::BrushWrapper* destBrush = buffer->dest<Game::BrushWrapper>();
buffer->save(brush);
2016-01-25 17:47:50 -05:00
// Save_cbrushWrapper_t
{
AssertSize(Game::cbrushWrapper_t, 36);
2016-01-25 17:47:50 -05:00
if (brush->brush.brushSide)
{
AssertSize(Game::cbrushside_t, 8);
2016-01-25 17:47:50 -05:00
buffer->align(Utils::Stream::ALIGN_4);
2016-01-25 17:47:50 -05:00
Game::cbrushside_t* destBrushSide = buffer->dest<Game::cbrushside_t>();
buffer->saveArray(brush->brush.brushSide, brush->brush.count);
2016-01-25 17:47:50 -05:00
// Save_cbrushside_tArray
for (short i = 0; i < brush->brush.count; ++i)
{
Game::cbrushside_t* destSide = &destBrushSide[i];
Game::cbrushside_t* side = &brush->brush.brushSide[i];
if (side->plane)
2016-01-25 17:47:50 -05:00
{
if (builder->hasPointer(side->plane))
2016-01-25 17:47:50 -05:00
{
destSide->plane = builder->getPointer(side->plane);
2016-01-25 17:47:50 -05:00
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(side->plane);
buffer->save(side->plane, sizeof(Game::cplane_t));
Utils::Stream::ClearPointer(&destSide->plane);
2016-01-25 17:47:50 -05:00
}
}
}
Utils::Stream::ClearPointer(&destBrush->brush.brushSide);
2016-01-25 17:47:50 -05:00
}
if (brush->brush.brushEdge)
{
buffer->save(brush->brush.brushEdge, brush->totalEdgeCount);
Utils::Stream::ClearPointer(&destBrush->brush.brushEdge);
2016-01-25 17:47:50 -05:00
}
}
if (brush->planes)
{
AssertSize(Game::cplane_t, 20);
2016-01-25 17:47:50 -05:00
if (builder->hasPointer(brush->planes))
2016-01-25 17:47:50 -05:00
{
destBrush->planes = builder->getPointer(brush->planes);
2016-01-25 17:47:50 -05:00
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brush->planes);
2016-01-25 17:47:50 -05:00
buffer->save(brush->planes, sizeof(Game::cplane_t));
Utils::Stream::ClearPointer(&destBrush->planes);
2016-01-25 17:47:50 -05:00
}
}
}
void IPhysCollmap::savePhysGeomInfoArray(Components::ZoneBuilder::Zone* builder, Game::PhysGeomInfo* geoms, unsigned int count)
2016-01-25 17:47:50 -05:00
{
AssertSize(Game::PhysGeomInfo, 68);
2016-01-25 17:47:50 -05:00
Utils::Stream* buffer = builder->getBuffer();
2016-01-25 17:47:50 -05:00
Game::PhysGeomInfo* destGeoms = buffer->dest<Game::PhysGeomInfo>();
buffer->saveArray(geoms, count);
2016-01-25 17:47:50 -05:00
for (unsigned int i = 0; i < count; ++i)
{
Game::PhysGeomInfo* destGeom = &destGeoms[i];
Game::PhysGeomInfo* geom = &geoms[i];
if (geom->brush)
{
buffer->align(Utils::Stream::ALIGN_4);
2016-01-25 17:47:50 -05:00
this->saveBrushWrapper(builder, geom->brush);
Utils::Stream::ClearPointer(&destGeom->brush);
2016-01-25 17:47:50 -05:00
}
}
}
void IPhysCollmap::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
2016-01-25 17:47:50 -05:00
{
AssertSize(Game::XModel, 304);
2016-01-25 17:47:50 -05:00
Utils::Stream* buffer = builder->getBuffer();
2016-01-25 17:47:50 -05:00
Game::PhysCollmap* asset = header.physCollmap;
Game::PhysCollmap* dest = buffer->dest<Game::PhysCollmap>();
buffer->save(asset, sizeof(Game::PhysCollmap));
2016-01-25 17:47:50 -05:00
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
2016-01-25 17:47:50 -05:00
if (asset->name)
{
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
Utils::Stream::ClearPointer(&dest->name);
2016-01-25 17:47:50 -05:00
}
if (asset->geoms)
{
buffer->align(Utils::Stream::ALIGN_4);
2016-01-25 17:47:50 -05:00
this->savePhysGeomInfoArray(builder, asset->geoms, asset->count);
Utils::Stream::ClearPointer(&dest->geoms);
2016-01-25 17:47:50 -05:00
}
buffer->popBlock();
2016-01-25 17:47:50 -05:00
}
}