[ZoneBuilder] clipmap and gfxworld fixes

This commit is contained in:
momo5502 2016-12-21 19:18:33 +01:00
parent 48557d02d1
commit b72b8b8a15
3 changed files with 384 additions and 269 deletions

View File

@ -10,105 +10,106 @@ namespace Assets
Components::Logger::Error("Missing GfxMap %s... you can't make them yet you idiot.", name.data()); Components::Logger::Error("Missing GfxMap %s... you can't make them yet you idiot.", name.data());
} }
void IGfxWorld::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) void IGfxWorld::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{ {
Game::GfxWorld* asset = header.gfxWorld; Game::GfxWorld* asset = header.gfxWorld;
if(asset->worldDraw.reflectionImages) if (asset->worldDraw.reflectionImages)
{ {
for (unsigned int i = 0; i < asset->worldDraw.reflectionProbeCount; i++) for (unsigned int i = 0; i < asset->worldDraw.reflectionProbeCount; i++)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.reflectionImages[i]->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.reflectionImages[i]->name);
} }
} }
if (asset->worldDraw.lightmaps) if (asset->worldDraw.lightmaps)
{ {
for (int i = 0; i < asset->worldDraw.lightmapCount; i++) for (int i = 0; i < asset->worldDraw.lightmapCount; i++)
{ {
if (asset->worldDraw.lightmaps[i].primary) if (asset->worldDraw.lightmaps[i].primary)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.lightmaps[i].primary->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.lightmaps[i].primary->name);
} }
if (asset->worldDraw.lightmaps[i].secondary) if (asset->worldDraw.lightmaps[i].secondary)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.lightmaps[i].secondary->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.lightmaps[i].secondary->name);
} }
} }
} }
if (asset->worldDraw.skyImage) if (asset->worldDraw.skyImage)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.skyImage->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.skyImage->name);
} }
if (asset->worldDraw.outdoorImage) if (asset->worldDraw.outdoorImage)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.outdoorImage->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->worldDraw.outdoorImage->name);
} }
if (asset->sun.spriteMaterial) if (asset->sun.spriteMaterial)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->sun.spriteMaterial->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->sun.spriteMaterial->name);
} }
if (asset->sun.flareMaterial) if (asset->sun.flareMaterial)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->sun.flareMaterial->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->sun.flareMaterial->name);
} }
if (asset->skies) { if (asset->skies) {
for (unsigned int i = 0; i < asset->skyCount; i++) for (unsigned int i = 0; i < asset->skyCount; i++)
{ {
if (asset->skies[i].skyImage) if (asset->skies[i].skyImage)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->skies[i].skyImage->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->skies[i].skyImage->name);
} }
} }
} }
if (asset->materialMemory) { if (asset->materialMemory) {
for (int i = 0; i < asset->materialMemoryCount; i++) for (int i = 0; i < asset->materialMemoryCount; i++)
{ {
if (asset->materialMemory[i].material) if (asset->materialMemory[i].material)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materialMemory[i].material->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materialMemory[i].material->name);
} }
} }
} }
if (asset->unknownImage) if (asset->unknownImage)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->unknownImage->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_IMAGE, asset->unknownImage->name);
} }
if (asset->dpvs.surfaces) if (asset->dpvs.surfaces)
{ {
for (int i = 0; i < asset->dpvsSurfaceCount; i++) for (int i = 0; i < asset->dpvsSurfaceCount; i++)
{ {
if (asset->dpvs.surfaces[i].material) if (asset->dpvs.surfaces[i].material)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->dpvs.surfaces[i].material->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->dpvs.surfaces[i].material->name);
} }
} }
} }
if (asset->dpvs.smodelDrawInsts) if (asset->dpvs.smodelDrawInsts)
{ {
for (unsigned int i = 0; i < asset->dpvs.smodelCount; i++) for (unsigned int i = 0; i < asset->dpvs.smodelCount; i++)
{ {
if (asset->dpvs.smodelDrawInsts[i].model) if (asset->dpvs.smodelDrawInsts[i].model)
{ {
builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODEL, asset->dpvs.smodelDrawInsts[i].model->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODEL, asset->dpvs.smodelDrawInsts[i].model->name);
} }
} }
} }
} }
void IGfxWorld::saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder) { void IGfxWorld::saveGfxWorldDpvsPlanes(Game::GfxWorld* world, Game::GfxWorldDpvsPlanes* asset, Game::GfxWorldDpvsPlanes* dest, Components::ZoneBuilder::Zone* builder)
{
AssertSize(Game::GfxWorldDpvsPlanes, 16); AssertSize(Game::GfxWorldDpvsPlanes, 16);
Utils::Stream* buffer = builder->getBuffer(); Utils::Stream* buffer = builder->getBuffer();
@ -121,7 +122,8 @@ namespace Assets
} }
else else
{ {
AssertSize(Game::cplane_s, 20); AssertSize(Game::cplane_t, 20);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
builder->storePointer(asset->planes); builder->storePointer(asset->planes);
@ -248,30 +250,30 @@ namespace Assets
} }
// saveGfxWorldVertexData // saveGfxWorldVertexData
{ {
if (asset->vd.vertices) if (asset->vd.vertices)
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->vd.vertices, asset->vertexCount); buffer->saveArray(asset->vd.vertices, asset->vertexCount);
Utils::Stream::ClearPointer(&dest->vd.vertices); Utils::Stream::ClearPointer(&dest->vd.vertices);
} }
// this one has no if statement on purpouse // this one has no if statement on purpouse
buffer->save(&asset->vd.worldVb, 1, 4); buffer->save(&asset->vd.worldVb, 1, 4);
} }
// saveGfxWorldVertexLayerData // saveGfxWorldVertexLayerData
{ {
if (asset->vld.data) if (asset->vld.data)
{ {
// no align for char // no align for char
buffer->saveArray(asset->vld.data, asset->vertexLayerDataSize); buffer->saveArray(asset->vld.data, asset->vertexLayerDataSize);
Utils::Stream::ClearPointer(&dest->vld.data); Utils::Stream::ClearPointer(&dest->vld.data);
} }
buffer->save(&asset->vld.layerVb, 1, 4); buffer->save(&asset->vld.layerVb, 1, 4);
} }
if (asset->indices) if (asset->indices)
{ {
@ -383,52 +385,53 @@ namespace Assets
{ {
AssertSize(Game::GfxSurface, 24); AssertSize(Game::GfxSurface, 24);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::GfxSurface* destSurfaceTable = buffer->dest<Game::GfxSurface>(); Game::GfxSurface* destSurfaceTable = buffer->dest<Game::GfxSurface>();
buffer->saveArray(asset->surfaces, world->dpvsSurfaceCount); buffer->saveArray(asset->surfaces, world->dpvsSurfaceCount);
for (int i = 0; i < world->dpvsSurfaceCount; i++) for (int i = 0; i < world->dpvsSurfaceCount; i++)
{ {
Game::GfxSurface* surface = &asset->surfaces[i]; Game::GfxSurface* surface = &asset->surfaces[i];
Game::GfxSurface* destSurface = &destSurfaceTable[i]; Game::GfxSurface* destSurface = &destSurfaceTable[i];
if (surface->material) if (surface->material)
{ {
destSurface->material = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, surface->material->name).material; destSurface->material = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, surface->material->name).material;
} }
} }
Utils::Stream::ClearPointer(&dest->surfaces);
Utils::Stream::ClearPointer(&dest->surfaces);
} }
if (asset->surfacesBounds) if (asset->surfacesBounds)
{ {
//AssertSize(Game::GfxSurfaceBounds, 24); AssertSize(Game::GfxSurfaceBounds, 24);
// this is wrong but i dont really care since its just a single struct
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->surfacesBounds, 24, world->dpvsSurfaceCount); buffer->saveArray(asset->surfacesBounds, world->dpvsSurfaceCount);
Utils::Stream::ClearPointer(&dest->surfacesBounds); Utils::Stream::ClearPointer(&dest->surfacesBounds);
} }
if (asset->smodelDrawInsts) if (asset->smodelDrawInsts)
{ {
AssertSize(Game::GfxStaticModelDrawInst, 76); AssertSize(Game::GfxStaticModelDrawInst, 76);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::GfxStaticModelDrawInst* destModelTable = buffer->dest<Game::GfxStaticModelDrawInst>(); Game::GfxStaticModelDrawInst* destModelTable = buffer->dest<Game::GfxStaticModelDrawInst>();
buffer->saveArray(asset->smodelDrawInsts, asset->smodelCount); buffer->saveArray(asset->smodelDrawInsts, asset->smodelCount);
for (unsigned int i = 0; i < asset->smodelCount; i++) for (unsigned int i = 0; i < asset->smodelCount; i++)
{ {
Game::GfxStaticModelDrawInst* model = &asset->smodelDrawInsts[i]; Game::GfxStaticModelDrawInst* model = &asset->smodelDrawInsts[i];
Game::GfxStaticModelDrawInst* destModel = &destModelTable[i]; Game::GfxStaticModelDrawInst* destModel = &destModelTable[i];
if (model->model) if (model->model)
{ {
destModel->model = builder->requireAsset(Game::XAssetType::ASSET_TYPE_XMODEL, model->model->name).model; destModel->model = builder->requireAsset(Game::XAssetType::ASSET_TYPE_XMODEL, model->model->name).model;
} }
} }
Utils::Stream::ClearPointer(&dest->smodelDrawInsts);
Utils::Stream::ClearPointer(&dest->smodelDrawInsts);
} }
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME); buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
@ -437,18 +440,18 @@ namespace Assets
{ {
AssertSize(Game::GfxDrawSurf, 8); AssertSize(Game::GfxDrawSurf, 8);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->surfaceMaterials, world->dpvsSurfaceCount); buffer->saveArray(asset->surfaceMaterials, world->dpvsSurfaceCount);
Utils::Stream::ClearPointer(&dest->surfaceMaterials); Utils::Stream::ClearPointer(&dest->surfaceMaterials);
} }
if (asset->surfaceCastsSunShadow) if (asset->surfaceCastsSunShadow)
{ {
AssertSize(Game::GfxDrawSurf, 8); AssertSize(Game::GfxDrawSurf, 8);
buffer->align(Utils::Stream::ALIGN_128); buffer->align(Utils::Stream::ALIGN_128);
buffer->save(asset->surfaceCastsSunShadow, 4, asset->sunShadowCount); buffer->save(asset->surfaceCastsSunShadow, 4, asset->sunShadowCount);
Utils::Stream::ClearPointer(&dest->surfaceCastsSunShadow); Utils::Stream::ClearPointer(&dest->surfaceCastsSunShadow);
} }
buffer->popBlock(); buffer->popBlock();
@ -582,7 +585,7 @@ namespace Assets
// ok this one is based on some assumptions because the actual count is this // ok this one is based on some assumptions because the actual count is this
// *(int *)((char *)&varGfxWorld->aabbTreeCounts->aabbTreeCount + (((char *)varGfxCellTree - (char *)varGfxWorld->aabbTrees) & 0xFFFFFFFC)) // *(int *)((char *)&varGfxWorld->aabbTreeCounts->aabbTreeCount + (((char *)varGfxCellTree - (char *)varGfxWorld->aabbTrees) & 0xFFFFFFFC))
// which makes no sense // which makes no sense
// what DOES make sense is using the count from the strucutre // what DOES make sense is using the count from the structure
for (int j = 0; j < asset->aabbTreeCounts[i].aabbTreeCount; ++j) for (int j = 0; j < asset->aabbTreeCounts[i].aabbTreeCount; ++j)
{ {

View File

@ -13,37 +13,55 @@ namespace Assets
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL); buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
if (asset->cPlanes) // OffsetToPointer support if (asset->cPlanes)
{ {
buffer->align(Utils::Stream::ALIGN_4); AssertSize(Game::cplane_t, 20);
buffer->save(asset->cPlanes, sizeof(Game::cPlane), asset->numCPlanes);
Utils::Stream::ClearPointer(&dest->cPlanes); if (builder->hasPointer(asset->cPlanes))
{
dest->cPlanes = builder->getPointer(asset->cPlanes);
}
else
{
builder->storePointer(asset->cPlanes);
buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->cPlanes, asset->numCPlanes);
Utils::Stream::ClearPointer(&dest->cPlanes);
}
} }
if (asset->staticModelList) if (asset->staticModelList)
{ {
AssertSize(Game::cStaticModel_t, 76);
// xmodel is already stored // xmodel is already stored
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::cStaticModel* destStaticModelList = buffer->dest<Game::cStaticModel>(); Game::cStaticModel_t* destStaticModelList = buffer->dest<Game::cStaticModel_t>();
buffer->save(asset->staticModelList, sizeof(Game::cStaticModel), asset->numStaticModels); buffer->saveArray(asset->staticModelList, asset->numStaticModels);
for (int i = 0; i < asset->numStaticModels; i++)
for (int i = 0; i < asset->numStaticModels; ++i)
{ {
if (asset->staticModelList[i].xmodel) if (asset->staticModelList[i].xmodel)
{ {
destStaticModelList[i].xmodel = builder->requireAsset(Game::XAssetType::ASSET_TYPE_XMODEL, asset->staticModelList[i].xmodel->name).model; destStaticModelList[i].xmodel = builder->requireAsset(Game::XAssetType::ASSET_TYPE_XMODEL, asset->staticModelList[i].xmodel->name).model;
} }
} }
Utils::Stream::ClearPointer(&dest->staticModelList); Utils::Stream::ClearPointer(&dest->staticModelList);
} }
if (asset->materials) if (asset->materials)
{ {
AssertSize(Game::ClipMaterial, 12);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::dMaterial* mats = buffer->dest<Game::dMaterial>(); Game::ClipMaterial* mats = buffer->dest<Game::ClipMaterial>();
buffer->save(asset->materials, sizeof(Game::dMaterial), asset->numMaterials); buffer->saveArray(asset->materials, asset->numMaterials);
for (int i = 0; i < asset->numMaterials; i++)
for (int i = 0; i < asset->numMaterials; ++i)
{ {
buffer->save(asset->materials[i].name, strlen(asset->materials[i].name) + 1, 1); buffer->saveString(asset->materials[i].name);
Utils::Stream::ClearPointer(&mats[i].name); Utils::Stream::ClearPointer(&mats[i].name);
} }
Utils::Stream::ClearPointer(&dest->materials); Utils::Stream::ClearPointer(&dest->materials);
@ -51,174 +69,272 @@ namespace Assets
if (asset->cBrushSides) if (asset->cBrushSides)
{ {
AssertSize(Game::cbrushside_t, 8);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::cBrushSide* sides = buffer->dest<Game::cBrushSide>(); Game::cbrushside_t* sides = buffer->dest<Game::cbrushside_t>();
buffer->save(asset->cBrushSides, sizeof(Game::cBrushSide), asset->numCBrushSides); buffer->saveArray(asset->cBrushSides, asset->numCBrushSides);
for (int i = 0; i < asset->numCBrushSides; i++)
for (int i = 0; i < asset->numCBrushSides; ++i)
{ {
if (sides[i].side) // OffsetToPointer if (sides[i].side)
{ {
buffer->align(Utils::Stream::ALIGN_4); AssertSize(Game::cplane_t, 20);
buffer->save(sides[i].side, sizeof(Game::cPlane), 1);
Utils::Stream::ClearPointer(&sides[i].side); if (builder->hasPointer(sides[i].side))
{
sides[i].side = builder->getPointer(sides[i].side);
}
else
{
builder->storePointer(sides[i].side);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(sides[i].side);
Utils::Stream::ClearPointer(&sides[i].side);
}
} }
} }
Utils::Stream::ClearPointer(&dest->cBrushSides); Utils::Stream::ClearPointer(&dest->cBrushSides);
} }
if (asset->cBrushEdges) if (asset->cBrushEdges)
{ {
// no align for char // no align for char
buffer->save(asset->cBrushEdges, 1, asset->numCBrushEdges); buffer->saveArray(asset->cBrushEdges, asset->numCBrushEdges);
Utils::Stream::ClearPointer(&dest->cBrushEdges); Utils::Stream::ClearPointer(&dest->cBrushEdges);
} }
if (asset->cNodes) if (asset->cNodes)
{ {
AssertSize(Game::cNode_t, 8);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::cNode* nodes = buffer->dest<Game::cNode>(); Game::cNode_t* nodes = buffer->dest<Game::cNode_t>();
buffer->save(asset->cNodes, sizeof(Game::cNode), asset->numCNodes); buffer->saveArray(asset->cNodes, asset->numCNodes);
for (int i = 0; i < asset->numCNodes; i++)
for (int i = 0; i < asset->numCNodes; ++i)
{ {
if (nodes[i].plane) // OffsetToPointer if (nodes[i].plane)
{ {
buffer->align(Utils::Stream::ALIGN_4); if (builder->hasPointer(nodes[i].plane))
buffer->save(nodes[i].plane, sizeof(Game::cPlane), 1); {
Utils::Stream::ClearPointer(&nodes[i].plane); nodes[i].plane = builder->getPointer(nodes[i].plane);
}
else
{
builder->storePointer(nodes[i].plane);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(nodes[i].plane);
Utils::Stream::ClearPointer(&nodes[i].plane);
}
} }
} }
Utils::Stream::ClearPointer(&dest->cNodes); Utils::Stream::ClearPointer(&dest->cNodes);
} }
if (asset->cLeaf) if (asset->cLeaf)
{ {
AssertSize(Game::cLeaf_t, 40);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->cLeaf, sizeof(Game::cLeaf), asset->numCLeaf); buffer->saveArray(asset->cLeaf, asset->numCLeaf);
Utils::Stream::ClearPointer(&dest->cLeaf); Utils::Stream::ClearPointer(&dest->cLeaf);
} }
if (asset->leafBrushes) if (asset->leafBrushes)
{ {
buffer->align(Utils::Stream::ALIGN_2); buffer->align(Utils::Stream::ALIGN_2);
buffer->save(asset->leafBrushes, 2, asset->numLeafBrushes); buffer->saveArray(asset->leafBrushes, asset->numLeafBrushes);
Utils::Stream::ClearPointer(&dest->leafBrushes); Utils::Stream::ClearPointer(&dest->leafBrushes);
} }
if (asset->cLeafBrushNodes) if (asset->cLeafBrushNodes)
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::cLeafBrushNode* node = buffer->dest<Game::cLeafBrushNode>(); Game::cLeafBrushNode_t* node = buffer->dest<Game::cLeafBrushNode_t>();
buffer->save(asset->cLeafBrushNodes, sizeof(Game::cLeafBrushNode), asset->numCLeafBrushNodes); buffer->saveArray(asset->cLeafBrushNodes, asset->numCLeafBrushNodes);
for (int i = 0; i < asset->numCLeafBrushNodes; i++) for (int i = 0; i < asset->numCLeafBrushNodes; ++i)
{ {
if (node[i].leafBrushCount > 0) if (node[i].leafBrushCount > 0)
{ {
if (node[i].data.leaf.brushes) // OffsetToPointer if (node[i].data.leaf.brushes)
{ {
buffer->align(Utils::Stream::ALIGN_2); if (builder->hasPointer(node[i].data.leaf.brushes))
buffer->save(node[i].data.leaf.brushes, 2, node[i].leafBrushCount); {
Utils::Stream::ClearPointer(&node[i].data.leaf.brushes); node[i].data.leaf.brushes = builder->getPointer(node[i].data.leaf.brushes);
}
else
{
builder->storePointer(node[i].data.leaf.brushes);
buffer->align(Utils::Stream::ALIGN_2);
buffer->saveArray(node[i].data.leaf.brushes, node[i].leafBrushCount);
Utils::Stream::ClearPointer(&node[i].data.leaf.brushes);
}
} }
} }
} }
Utils::Stream::ClearPointer(&dest->cLeafBrushNodes); Utils::Stream::ClearPointer(&dest->cLeafBrushNodes);
} }
if (asset->leafSurfaces) if (asset->leafSurfaces)
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->leafSurfaces, sizeof(int), asset->numLeafSurfaces); buffer->saveArray(asset->leafSurfaces, asset->numLeafSurfaces);
Utils::Stream::ClearPointer(&dest->leafSurfaces); Utils::Stream::ClearPointer(&dest->leafSurfaces);
} }
if (asset->verts) if (asset->verts)
{ {
AssertSize(Game::vec3_t, 12);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->verts, sizeof(Game::vec3_t), asset->numVerts); buffer->saveArray(asset->verts, asset->numVerts);
Utils::Stream::ClearPointer(&dest->verts); Utils::Stream::ClearPointer(&dest->verts);
} }
if (asset->triIndices) if (asset->triIndices)
{ {
buffer->align(Utils::Stream::ALIGN_2); buffer->align(Utils::Stream::ALIGN_2);
buffer->save(asset->triIndices, sizeof(short), 3 * asset->numTriIndices); buffer->save(asset->triIndices, 6, asset->numTriIndices);
Utils::Stream::ClearPointer(&dest->triIndices); Utils::Stream::ClearPointer(&dest->triIndices);
} }
if (asset->triEdgeIsWalkable) if (asset->triEdgeIsWalkable)
{ {
// no align for char // no align for char
buffer->save(asset->triEdgeIsWalkable, sizeof(char), ((3 * asset->numTriIndices + 31) >> 3) & 0xFFFFFFFC); buffer->save(asset->triEdgeIsWalkable, 1, 4 * ((3 * asset->numTriIndices + 31) >> 5));
Utils::Stream::ClearPointer(&dest->triEdgeIsWalkable); Utils::Stream::ClearPointer(&dest->triEdgeIsWalkable);
} }
if (asset->collisionBorders) if (asset->collisionBorders)
{ {
AssertSize(Game::CollisionBorder, 28);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->collisionBorders, sizeof(Game::CollisionBorder), asset->numCollisionBorders);
for (int i = 0; i < asset->numCollisionBorders; ++i)
{
builder->storePointer(&asset->collisionBorders[i]);
buffer->save(&asset->collisionBorders[i]);
}
Utils::Stream::ClearPointer(&dest->collisionBorders); Utils::Stream::ClearPointer(&dest->collisionBorders);
} }
if (asset->collisionPartitions) if (asset->collisionPartitions)
{ {
AssertSize(Game::CollisionPartition, 12);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::CollisionPartition* border = buffer->dest<Game::CollisionPartition>(); Game::CollisionPartition* border = buffer->dest<Game::CollisionPartition>();
buffer->save(asset->collisionPartitions, sizeof(Game::CollisionPartition), asset->numCollisionPartitions); buffer->saveArray(asset->collisionPartitions, asset->numCollisionPartitions);
for (int i = 0; i < asset->numCollisionPartitions; i++) for (int i = 0; i < asset->numCollisionPartitions; ++i)
{ {
if (border[i].borders) // OffsetToPointer if (border[i].borders)
{ {
buffer->align(Utils::Stream::ALIGN_4); if (builder->hasPointer(border[i].borders))
buffer->save(border[i].borders, sizeof(Game::CollisionBorder), 1); {
Utils::Stream::ClearPointer(&border[i].borders); border[i].borders = builder->getPointer(border[i].borders);
}
else
{
builder->storePointer(border[i].borders);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(border[i].borders);
Utils::Stream::ClearPointer(&border[i].borders);
}
} }
} }
Utils::Stream::ClearPointer(&dest->collisionPartitions); Utils::Stream::ClearPointer(&dest->collisionPartitions);
} }
if (asset->collisionAABBTrees) if (asset->collisionAABBTrees)
{ {
AssertSize(Game::CollisionAabbTree, 32);
buffer->align(Utils::Stream::ALIGN_16); buffer->align(Utils::Stream::ALIGN_16);
buffer->save(asset->collisionAABBTrees, sizeof(Game::CollisionAabbTree), asset->numCollisionAABBTrees); buffer->saveArray(asset->collisionAABBTrees, asset->numCollisionAABBTrees);
Utils::Stream::ClearPointer(&dest->collisionAABBTrees); Utils::Stream::ClearPointer(&dest->collisionAABBTrees);
} }
if (asset->cModels) if (asset->cModels)
{ {
AssertSize(Game::cmodel_t, 68);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->cModels, sizeof(Game::cModel), asset->numCModels); buffer->saveArray(asset->cModels, asset->numCModels);
Utils::Stream::ClearPointer(&dest->cModels); Utils::Stream::ClearPointer(&dest->cModels);
} }
if (asset->cBrushes) if (asset->cBrushes)
{ {
buffer->align(Utils::Stream::ALIGN_128); AssertSize(Game::cbrush_t, 36);
Game::cBrush* brushes = buffer->dest<Game::cBrush>();
buffer->save(asset->cBrushes, sizeof(Game::cBrush), asset->numCBrushes);
for (short i = 0; i < asset->numCBrushes; i++) buffer->align(Utils::Stream::ALIGN_128);
Game::cbrush_t* brushes = buffer->dest<Game::cbrush_t>();
buffer->saveArray(asset->cBrushes, asset->numCBrushes);
for (short i = 0; i < asset->numCBrushes; ++i)
{ {
if (brushes[i].brushSide) if (brushes[i].brushSide)
{ {
Game::cBrushSide* side = buffer->dest<Game::cBrushSide>(); if (builder->hasPointer(brushes[i].brushSide))
buffer->save(brushes[i].brushSide, sizeof(Game::cBrushSide), 1); {
brushes[i].brushSide = builder->getPointer(brushes[i].brushSide);
}
else
{
builder->storePointer(brushes[i].brushSide);
AssertSize(Game::cbrushside_t, 8);
if (brushes[i].brushSide->side)
{
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(brushes[i].brushSide->side, sizeof(Game::cPlane), 1); Game::cbrushside_t* side = buffer->dest<Game::cbrushside_t>();
Utils::Stream::ClearPointer(&side->side); buffer->save(brushes[i].brushSide);
}
Utils::Stream::ClearPointer(&brushes[i].brushSide); if (brushes[i].brushSide->side)
{
if (builder->hasPointer(brushes[i].brushSide->side))
{
brushes[i].brushSide->side = builder->getPointer(brushes[i].brushSide->side);
}
else
{
builder->storePointer(brushes[i].brushSide->side);
buffer->align(Utils::Stream::ALIGN_4);
buffer->save(brushes[i].brushSide->side);
Utils::Stream::ClearPointer(&side->side);
}
}
Utils::Stream::ClearPointer(&brushes[i].brushSide);
}
} }
if (brushes[i].brushEdge) if (brushes[i].brushEdge)
{ {
buffer->save(brushes[i].brushEdge, 1, 1); if (builder->hasPointer(brushes[i].brushEdge))
Utils::Stream::ClearPointer(&brushes[i].brushEdge); {
brushes[i].brushEdge = builder->getPointer(brushes[i].brushEdge);
}
else
{
builder->storePointer(brushes[i].brushEdge);
buffer->save(brushes[i].brushEdge);
Utils::Stream::ClearPointer(&brushes[i].brushEdge);
}
} }
} }
Utils::Stream::ClearPointer(&dest->cBrushes); Utils::Stream::ClearPointer(&dest->cBrushes);
@ -226,22 +342,26 @@ namespace Assets
if (asset->cBrushBounds) if (asset->cBrushBounds)
{ {
AssertSize(Game::Bounds, 24);
buffer->align(Utils::Stream::ALIGN_128); buffer->align(Utils::Stream::ALIGN_128);
buffer->save(asset->cBrushBounds, sizeof(Game::Bounds), asset->numCBrushes); buffer->saveArray(asset->cBrushBounds, asset->numCBrushes);
Utils::Stream::ClearPointer(&dest->cBrushBounds); Utils::Stream::ClearPointer(&dest->cBrushBounds);
} }
if (asset->cBrushContents) if (asset->cBrushContents)
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->cBrushContents, sizeof(int), asset->numCBrushes); buffer->saveArray(asset->cBrushContents, asset->numCBrushes);
Utils::Stream::ClearPointer(&dest->cBrushContents); Utils::Stream::ClearPointer(&dest->cBrushContents);
} }
if (asset->unknown4) if (asset->unknown4)
{ {
AssertSize(Game::SModelAabbNode, 28);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->unknown4, 28, asset->unkCount4); buffer->saveArray(asset->unknown4, asset->unkCount4);
Utils::Stream::ClearPointer(&dest->unknown4); Utils::Stream::ClearPointer(&dest->unknown4);
} }
@ -250,18 +370,21 @@ namespace Assets
dest->mapEnts = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->name).mapEnts; dest->mapEnts = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, asset->name).mapEnts;
} }
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; ++i)
{ {
if (asset->dynEntDefList[i]) if (asset->dynEntDefList[i])
{ {
AssertSize(Game::DynEntityDef, 92);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
Game::DynEntityDef* dynEntDest = buffer->dest<Game::DynEntityDef>(); Game::DynEntityDef* dynEntDest = buffer->dest<Game::DynEntityDef>();
buffer->save(asset->dynEntDefList[i], sizeof(Game::DynEntityDef), asset->dynEntCount[i]); buffer->saveArray(asset->dynEntDefList[i], asset->dynEntCount[i]);
for (int j = 0; j < asset->dynEntCount[i]; j++)
for (int j = 0; j < asset->dynEntCount[i]; ++j)
{ {
Game::XModel* m = asset->dynEntDefList[j]->xModel; Game::XModel* m = asset->dynEntDefList[i][j].xModel;
Game::FxEffectDef* fx = asset->dynEntDefList[j]->destroyFx; Game::FxEffectDef* fx = asset->dynEntDefList[i][j].destroyFx;
Game::PhysPreset* p = asset->dynEntDefList[j]->physPreset; Game::PhysPreset* p = asset->dynEntDefList[i][j].physPreset;
if (m) if (m)
{ {
@ -289,8 +412,10 @@ namespace Assets
{ {
if (asset->dynEntPoseList[i]) if (asset->dynEntPoseList[i])
{ {
AssertSize(Game::DynEntityPose, 32);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->dynEntPoseList[i], sizeof(Game::DynEntityPose), asset->dynEntCount[i]); buffer->saveArray(asset->dynEntPoseList[i], asset->dynEntCount[i]);
Utils::Stream::ClearPointer(&dest->dynEntPoseList[i]); Utils::Stream::ClearPointer(&dest->dynEntPoseList[i]);
} }
@ -300,8 +425,10 @@ namespace Assets
{ {
if (asset->dynEntClientList[i]) if (asset->dynEntClientList[i])
{ {
AssertSize(Game::DynEntityClient, 12);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->dynEntClientList[i], sizeof(Game::DynEntityClient), asset->dynEntCount[i]); buffer->save(asset->dynEntClientList[i], asset->dynEntCount[i]);
Utils::Stream::ClearPointer(&dest->dynEntClientList[i]); Utils::Stream::ClearPointer(&dest->dynEntClientList[i]);
} }
} }
@ -310,8 +437,10 @@ namespace Assets
{ {
if (asset->dynEntCollList[i]) if (asset->dynEntCollList[i])
{ {
AssertSize(Game::DynEntityColl, 20);
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->save(asset->dynEntCollList[i], sizeof(Game::DynEntityColl), asset->dynEntCount[i]); buffer->save(asset->dynEntCollList[i], asset->dynEntCount[i]);
Utils::Stream::ClearPointer(&dest->dynEntCollList[i]); Utils::Stream::ClearPointer(&dest->dynEntCollList[i]);
} }
} }
@ -333,11 +462,11 @@ namespace Assets
{ {
for (int i = 0; i < asset->dynEntCount[j]; i++) for (int i = 0; i < asset->dynEntCount[j]; i++)
{ {
Game::XModel* m = asset->dynEntDefList[j]->xModel; Game::XModel* m = asset->dynEntDefList[j][i].xModel;
builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODEL, m->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODEL, m->name);
Game::FxEffectDef* fx = asset->dynEntDefList[j]->destroyFx; Game::FxEffectDef* fx = asset->dynEntDefList[j][i].destroyFx;
builder->loadAsset(Game::XAssetType::ASSET_TYPE_FX, fx->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_FX, fx->name);
Game::PhysPreset* p = asset->dynEntDefList[j]->physPreset; Game::PhysPreset* p = asset->dynEntDefList[j][i].physPreset;
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, p->name); builder->loadAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, p->name);
} }
} }

View File

@ -1512,9 +1512,10 @@ namespace Game
struct cplane_t struct cplane_t
{ {
vec3_t a; float normal[3];
float dist; float dist;
int type; char type;
char signbits;
}; };
struct cbrushside_t struct cbrushside_t
@ -2252,14 +2253,7 @@ namespace Game
bool(__cdecl *handler)(const char**, FxEditorElemDef*); bool(__cdecl *handler)(const char**, FxEditorElemDef*);
}; };
struct cPlane struct cStaticModel_t
{
vec3_t a;
float dist;
int type;
};
struct cStaticModel
{ {
XModel *xmodel; XModel *xmodel;
float origin[3]; float origin[3];
@ -2268,34 +2262,28 @@ namespace Game
float absmax[3]; float absmax[3];
}; };
struct dMaterial struct ClipMaterial
{ {
char* name; char* name;
int unk; int unk;
int unk2; int unk2;
}; };
struct cNode struct cNode_t
{ {
cPlane* plane; cplane_t* plane;
short children[2]; short children[2];
}; };
struct cBrushSide struct cbrush_t
{
cPlane* side;
short texInfo, dispInfo;
};
struct cBrush
{ {
int count; int count;
cBrushSide * brushSide; cbrushside_t * brushSide;
char * brushEdge; char * brushEdge;
char pad[24]; char pad[24];
}; };
struct cLeaf struct cLeaf_t
{ {
unsigned __int16 firstCollAabbIndex; unsigned __int16 firstCollAabbIndex;
unsigned __int16 collAabbCount; unsigned __int16 collAabbCount;
@ -2324,7 +2312,7 @@ namespace Game
cLeafBrushNodeChildren children; cLeafBrushNodeChildren children;
}; };
struct cLeafBrushNode struct cLeafBrushNode_t
{ {
char axis; char axis;
__int16 leafBrushCount; __int16 leafBrushCount;
@ -2332,12 +2320,12 @@ namespace Game
cLeafBrushNodeData data; cLeafBrushNodeData data;
}; };
struct cModel struct cmodel_t
{ {
float mins[3]; float mins[3];
float maxs[3]; float maxs[3];
float radius; float radius;
cLeaf leaf; cLeaf_t leaf;
}; };
enum DynEntityType enum DynEntityType
@ -2422,26 +2410,31 @@ namespace Game
CollisionAabbTreeIndex u; CollisionAabbTreeIndex u;
}; };
struct SModelAabbNode
{
char pad[28];
};
struct clipMap_t struct clipMap_t
{ {
const char* name; const char* name;
int unknown1; // +8 int unknown1; // +8
int numCPlanes; // +8 int numCPlanes; // +8
cPlane* cPlanes; // sizeof 20, +12 cplane_t* cPlanes; // sizeof 20, +12
int numStaticModels; // +16 int numStaticModels; // +16
cStaticModel* staticModelList; // sizeof 76, +20 cStaticModel_t* staticModelList; // sizeof 76, +20
int numMaterials; // +24 int numMaterials; // +24
dMaterial* materials; // sizeof 12 with a string (possibly name?), +28 ClipMaterial* materials; // sizeof 12 with a string (possibly name?), +28
int numCBrushSides; // +32 int numCBrushSides; // +32
cBrushSide* cBrushSides; // sizeof 8, +36 cbrushside_t* cBrushSides; // sizeof 8, +36
int numCBrushEdges; // +40 int numCBrushEdges; // +40
char* cBrushEdges; // +44 char* cBrushEdges; // +44
int numCNodes; // +48 int numCNodes; // +48
cNode * cNodes; // sizeof 8, +52 cNode_t* cNodes; // sizeof 8, +52
int numCLeaf; // +56 int numCLeaf; // +56
cLeaf* cLeaf; // +60 cLeaf_t* cLeaf; // +60
int numCLeafBrushNodes; // +64 int numCLeafBrushNodes; // +64
cLeafBrushNode* cLeafBrushNodes; // +68 cLeafBrushNode_t* cLeafBrushNodes; // +68
int numLeafBrushes; // +72 int numLeafBrushes; // +72
short* leafBrushes; // +76 short* leafBrushes; // +76
int numLeafSurfaces; // +80 int numLeafSurfaces; // +80
@ -2458,15 +2451,15 @@ namespace Game
int numCollisionAABBTrees; // +124 int numCollisionAABBTrees; // +124
CollisionAabbTree* collisionAABBTrees;// sizeof 32, +128 CollisionAabbTree* collisionAABBTrees;// sizeof 32, +128
int numCModels; // +132 int numCModels; // +132
cModel* cModels; // sizeof 68, +136 cmodel_t* cModels; // sizeof 68, +136
short numCBrushes; // +140 short numCBrushes; // +140
short pad2; // +142 short pad2; // +142
cBrush * cBrushes; // sizeof 36, +144 cbrush_t * cBrushes; // sizeof 36, +144
void* cBrushBounds; // same count as cBrushes, +148 Bounds* cBrushBounds; // same count as cBrushes, +148
int * cBrushContents; // same count as cBrushes, +152 int * cBrushContents; // same count as cBrushes, +152
MapEnts * mapEnts; // +156 MapEnts * mapEnts; // +156
int unkCount4; // +160 int unkCount4; // +160
void* unknown4; // +164 SModelAabbNode* unknown4; // +164
unsigned __int16 dynEntCount[2]; unsigned __int16 dynEntCount[2];
DynEntityDef *dynEntDefList[2]; DynEntityDef *dynEntDefList[2];
DynEntityPose *dynEntPoseList[2]; DynEntityPose *dynEntPoseList[2];
@ -2788,12 +2781,10 @@ namespace Game
float offset[3]; float offset[3];
}; };
struct cplane_s;
struct GfxWorldDpvsPlanes struct GfxWorldDpvsPlanes
{ {
int cellCount; int cellCount;
cplane_s *planes; cplane_t *planes;
unsigned __int16 *nodes; unsigned __int16 *nodes;
unsigned int *sceneEntCellBits; //Size = cellCount << 11 unsigned int *sceneEntCellBits; //Size = cellCount << 11
}; };
@ -2890,7 +2881,7 @@ namespace Game
struct GfxSurfaceBounds struct GfxSurfaceBounds
{ {
Bounds bounds; Bounds bounds;
char flags; //char flags;
}; };
struct GfxDrawSurfFields struct GfxDrawSurfFields
@ -2950,14 +2941,6 @@ namespace Game
char pad2[8]; char pad2[8];
}; };
struct cplane_s
{
float normal[3];
float dist;
char type;
char signbits;
};
struct GfxPortalWritable struct GfxPortalWritable
{ {
bool isQueued; bool isQueued;