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

136 lines
3.4 KiB
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#include "STDInclude.hpp"
2016-01-25 17:47:50 -05:00
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
{
2017-03-18 10:19:31 -04:00
AssertSize(Game::cbrush_t, 36);
2016-01-25 17:47:50 -05:00
2017-03-18 10:19:31 -04:00
if (brush->brush.sides)
2016-01-25 17:47:50 -05:00
{
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>();
2017-03-18 10:19:31 -04:00
buffer->saveArray(brush->brush.sides, brush->brush.numsides);
2016-01-25 17:47:50 -05:00
// Save_cbrushside_tArray
2017-03-18 10:19:31 -04:00
for (unsigned short i = 0; i < brush->brush.numsides; ++i)
2016-01-25 17:47:50 -05:00
{
Game::cbrushside_t* destSide = &destBrushSide[i];
2017-03-18 10:19:31 -04:00
Game::cbrushside_t* side = &brush->brush.sides[i];
2016-01-25 17:47:50 -05:00
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);
2018-05-09 08:33:52 -04:00
buffer->save(side->plane, sizeof(Game::cplane_s));
Utils::Stream::ClearPointer(&destSide->plane);
2016-01-25 17:47:50 -05:00
}
}
}
2017-03-18 10:19:31 -04:00
Utils::Stream::ClearPointer(&destBrush->brush.sides);
2016-01-25 17:47:50 -05:00
}
2017-03-18 10:19:31 -04:00
if (brush->brush.baseAdjacentSide)
2016-01-25 17:47:50 -05:00
{
2017-03-18 10:19:31 -04:00
buffer->save(brush->brush.baseAdjacentSide, brush->totalEdgeCount);
Utils::Stream::ClearPointer(&destBrush->brush.baseAdjacentSide);
2016-01-25 17:47:50 -05:00
}
}
if (brush->planes)
{
2018-05-09 08:33:52 -04:00
AssertSize(Game::cplane_s, 20);
2016-01-25 17:47:50 -05:00
if (builder->hasPointer(brush->planes))
2016-01-25 17:47:50 -05:00
{
2017-03-18 10:19:31 -04:00
Components::Logger::Print("Loading cplane pointer before the array has been written. Not sure if this is correct!\n");
destBrush->planes = builder->getPointer(brush->planes);
2016-01-25 17:47:50 -05:00
}
else
{
buffer->align(Utils::Stream::ALIGN_4);
2016-01-25 17:47:50 -05:00
2017-03-18 10:19:31 -04:00
for (unsigned short j = 0; j < brush->brush.numsides; ++j)
{
builder->storePointer(&brush->planes[j]);
buffer->save(&brush->planes[j]);
}
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];
2018-05-09 08:33:52 -04:00
if (geom->brushWrapper)
2016-01-25 17:47:50 -05:00
{
buffer->align(Utils::Stream::ALIGN_4);
2016-01-25 17:47:50 -05:00
2018-05-09 08:33:52 -04:00
this->saveBrushWrapper(builder, geom->brushWrapper);
Utils::Stream::ClearPointer(&destGeom->brushWrapper);
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
}
}