2017-01-20 08:36:52 -05:00
|
|
|
#include "STDInclude.hpp"
|
2016-01-25 17:47:50 -05:00
|
|
|
|
|
|
|
namespace Assets
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
void IPhysCollmap::saveBrushWrapper(Components::ZoneBuilder::Zone* builder, Game::BrushWrapper* brush)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::BrushWrapper, 68);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -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
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::cbrushside_t, 8);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -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
|
|
|
|
2016-12-29 22:14:50 -05:00
|
|
|
if (side->plane)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-12-29 22:14:50 -05:00
|
|
|
if (builder->hasPointer(side->plane))
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-12-29 22:14:50 -05:00
|
|
|
destSide->plane = builder->getPointer(side->plane);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-12-29 22:14:50 -05:00
|
|
|
builder->storePointer(side->plane);
|
2016-12-23 11:03:04 -05:00
|
|
|
|
2018-05-09 08:33:52 -04:00
|
|
|
buffer->save(side->plane, sizeof(Game::cplane_s));
|
2016-12-29 22:14:50 -05:00
|
|
|
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
|
|
|
|
2016-11-20 08:09:07 -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");
|
2016-11-20 08:09:07 -05:00
|
|
|
destBrush->planes = builder->getPointer(brush->planes);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2016-06-10 07:52:55 -04:00
|
|
|
Utils::Stream::ClearPointer(&destBrush->planes);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IPhysCollmap::savePhysGeomInfoArray(Components::ZoneBuilder::Zone* builder, Game::PhysGeomInfo* geoms, unsigned int count)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::PhysGeomInfo, 68);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -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
|
|
|
{
|
2016-11-20 08:09:07 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IPhysCollmap::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::XModel, 304);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-01-25 17:47:50 -05:00
|
|
|
Game::PhysCollmap* asset = header.physCollmap;
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::PhysCollmap* dest = buffer->dest<Game::PhysCollmap>();
|
|
|
|
buffer->save(asset, sizeof(Game::PhysCollmap));
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
|
2016-06-10 07:52:55 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->name);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->geoms)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
this->savePhysGeomInfoArray(builder, asset->geoms, asset->count);
|
2016-06-10 07:52:55 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->geoms);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
}
|