[ZoneBuilder] Store inter-asset-related pointers

This commit is contained in:
momo5502 2016-12-23 01:12:38 +01:00
parent cec0db3e4c
commit 4c1859e871
8 changed files with 53 additions and 18 deletions

View File

@ -126,9 +126,13 @@ namespace Assets
AssertSize(Game::cplane_t, 20); AssertSize(Game::cplane_t, 20);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(asset->planes);
buffer->saveArray(asset->planes, world->planeCount); for (int i = 0; i < world->planeCount; ++i)
{
builder->storePointer(&asset->planes[i]);
buffer->save(&asset->planes[i]);
}
Utils::Stream::ClearPointer(&dest->planes); Utils::Stream::ClearPointer(&dest->planes);
} }
} }
@ -615,9 +619,13 @@ namespace Assets
else else
{ {
buffer->align(Utils::Stream::ALIGN_2); buffer->align(Utils::Stream::ALIGN_2);
builder->storePointer(aabbTree->smodelIndexes);
buffer->saveArray(aabbTree->smodelIndexes, aabbTree->smodelIndexCount); for (unsigned short k = 0; k < aabbTree->smodelIndexCount; ++k)
{
builder->storePointer(&aabbTree->smodelIndexes[k]);
buffer->save(&aabbTree->smodelIndexes[k]);
}
Utils::Stream::ClearPointer(&destAabbTree->smodelIndexes); Utils::Stream::ClearPointer(&destAabbTree->smodelIndexes);
} }
} }

View File

@ -40,8 +40,7 @@ namespace Assets
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(side->side); builder->storePointer(side->side);
buffer->save(side->side);
buffer->save(side->side, sizeof(Game::cplane_t));
Utils::Stream::ClearPointer(&destSide->side); Utils::Stream::ClearPointer(&destSide->side);
} }
} }
@ -68,9 +67,13 @@ namespace Assets
else else
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(brush->planes);
buffer->save(brush->planes, sizeof(Game::cplane_t)); for (short i = 0; i < brush->brush.count; ++i)
{
builder->storePointer(&brush->planes[i]);
buffer->save(&brush->planes[i]);
}
Utils::Stream::ClearPointer(&destBrush->planes); Utils::Stream::ClearPointer(&destBrush->planes);
} }
} }

View File

@ -32,9 +32,13 @@ namespace Assets
else else
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(asset->cPlanes);
buffer->saveArray(asset->cPlanes, asset->numCPlanes); for (int i = 0; i < asset->numCPlanes; ++i)
{
builder->storePointer(&asset->cPlanes[i]);
buffer->save(&asset->cPlanes[i]);
}
Utils::Stream::ClearPointer(&dest->cPlanes); Utils::Stream::ClearPointer(&dest->cPlanes);
} }
@ -47,8 +51,9 @@ namespace Assets
AssertSize(Game::cStaticModel_t, 76); AssertSize(Game::cStaticModel_t, 76);
SaveLogEnter("cStaticModel_t"); SaveLogEnter("cStaticModel_t");
// xmodel is already stored
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Utils::Stream::Offset mark = buffer->getOffset();
Game::cStaticModel_t* destStaticModelList = buffer->dest<Game::cStaticModel_t>(); Game::cStaticModel_t* destStaticModelList = buffer->dest<Game::cStaticModel_t>();
buffer->saveArray(asset->staticModelList, asset->numStaticModels); buffer->saveArray(asset->staticModelList, asset->numStaticModels);
@ -204,9 +209,13 @@ namespace Assets
else else
{ {
buffer->align(Utils::Stream::ALIGN_2); buffer->align(Utils::Stream::ALIGN_2);
builder->storePointer(node[i].data.brushes);
buffer->saveArray(node[i].data.brushes, node[i].leafBrushCount); for (short j = 0; j < node[i].leafBrushCount; ++j)
{
builder->storePointer(&node[i].data.brushes[j]);
buffer->save(&node[i].data.brushes[j]);
}
Utils::Stream::ClearPointer(&node[i].data.brushes); Utils::Stream::ClearPointer(&node[i].data.brushes);
} }
} }
@ -427,7 +436,7 @@ namespace Assets
if (asset->mapEnts) if (asset->mapEnts)
{ {
dest->mapEnts = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->name).mapEnts; dest->mapEnts = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->mapEnts->name).mapEnts;
} }
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)

View File

@ -374,9 +374,14 @@ namespace Components
return NULL; return NULL;
} }
void ZoneBuilder::Zone::storePointer(const void* pointer, Utils::Stream::Offset offset)
{
this->pointerMap[pointer] = offset.getPackedOffset();
}
void ZoneBuilder::Zone::storePointer(const void* pointer) void ZoneBuilder::Zone::storePointer(const void* pointer)
{ {
this->pointerMap[pointer] = this->buffer.getPackedOffset(); this->storePointer(pointer, this->buffer.getOffset());
} }
int ZoneBuilder::Zone::addScriptString(std::string str) int ZoneBuilder::Zone::addScriptString(std::string str)

View File

@ -20,6 +20,7 @@ namespace Components
bool hasPointer(const void* pointer); bool hasPointer(const void* pointer);
void storePointer(const void* pointer); void storePointer(const void* pointer);
void storePointer(const void* pointer, Utils::Stream::Offset offset);
template<typename T> template<typename T>
inline T* getPointer(const T* pointer) { return reinterpret_cast<T*>(this->safeGetPointer(pointer)); } inline T* getPointer(const T* pointer) { return reinterpret_cast<T*>(this->safeGetPointer(pointer)); }

View File

@ -1542,9 +1542,10 @@ namespace Game
struct cbrushWrapper_t struct cbrushWrapper_t
{ {
short count; short count;
short pad;
cbrushside_t* brushSide; cbrushside_t* brushSide;
char * brushEdge; char * brushEdge;
char pad[24]; char pad2[24];
}; };
#pragma pack(push, 4) #pragma pack(push, 4)

View File

@ -277,14 +277,20 @@ namespace Utils
return 0; return 0;
} }
DWORD Stream::getPackedOffset() Stream::Offset Stream::getOffset()
{ {
Game::XFILE_BLOCK_TYPES block = this->getCurrentBlock(); Game::XFILE_BLOCK_TYPES block = this->getCurrentBlock();
Stream::Offset offset; Stream::Offset offset;
offset.block = block; offset.block = block;
offset.offset = this->getBlockSize(block); offset.offset = this->getBlockSize(block);
return offset.getPackedOffset();
return offset;
}
DWORD Stream::getPackedOffset()
{
return this->getOffset().getPackedOffset();
} }
void Stream::toBuffer(std::string& outBuffer) void Stream::toBuffer(std::string& outBuffer)

View File

@ -177,5 +177,7 @@ namespace Utils
return lOffset.block; return lOffset.block;
}; };
}; };
Offset getOffset();
}; };
} }