mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-06-06 08:42:35 +00:00
chore: removed unused code comments
This commit is contained in:
@@ -454,130 +454,6 @@ namespace BSP
|
|||||||
*out_treeContents |= clipMap->info.materials[matData.materialIndex].contentFlags;
|
*out_treeContents |= clipMap->info.materials[matData.materialIndex].contentFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void ClipMapLinker::addAABBTreeFromLeaf(clipMap_t* clipMap, BSPTree* tree, size_t* out_parentCount, size_t* out_parentStartIndex, int* out_treeContents)
|
|
||||||
{
|
|
||||||
assert(tree->isLeaf);
|
|
||||||
BSPLeaf* bspLeaf = tree->leaf.get();
|
|
||||||
|
|
||||||
size_t leafObjectCount = bspLeaf->getObjectCount();
|
|
||||||
assert(leafObjectCount > 0);
|
|
||||||
if (leafObjectCount > highestPartitionCountForAABB)
|
|
||||||
highestPartitionCountForAABB = leafObjectCount;
|
|
||||||
|
|
||||||
// the material index of the AABB tree is only checked for the parent node, so each parent has only children with the same material
|
|
||||||
std::vector<uniqueMatData> uniqueMaterials;
|
|
||||||
for (size_t objIdx = 0; objIdx < leafObjectCount; objIdx++)
|
|
||||||
{
|
|
||||||
int partitionIdx = bspLeaf->getObject(objIdx)->partitionIndex;
|
|
||||||
size_t materialIndex = collisionSurfaceVec.at(partitionToColSurfaceMap.at(partitionIdx)).materialIndex;
|
|
||||||
bool foundIdx = false;
|
|
||||||
for (auto& uniqueMat : uniqueMaterials)
|
|
||||||
{
|
|
||||||
if (uniqueMat.materialIndex == materialIndex)
|
|
||||||
{
|
|
||||||
uniqueMat.objectIndexes.emplace_back(objIdx);
|
|
||||||
foundIdx = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!foundIdx)
|
|
||||||
{
|
|
||||||
uniqueMatData data;
|
|
||||||
data.materialIndex = materialIndex;
|
|
||||||
data.objectIndexes.emplace_back(objIdx);
|
|
||||||
uniqueMaterials.emplace_back(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BO2 has a maximum limit of 128 children per AABB tree (essentially),
|
|
||||||
// so this is fixed by adding multiple parent AABB trees that hold 128 children each
|
|
||||||
size_t totalParentCount = 0;
|
|
||||||
for (auto& matData : uniqueMaterials)
|
|
||||||
{
|
|
||||||
size_t objCount = matData.objectIndexes.size();
|
|
||||||
size_t result = objCount / BSPGameConstants::MAX_AABB_TREE_CHILDREN;
|
|
||||||
size_t remainder = objCount % BSPGameConstants::MAX_AABB_TREE_CHILDREN;
|
|
||||||
if (remainder > 0)
|
|
||||||
result++;
|
|
||||||
totalParentCount += result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// every parent node needs to be contiguous in memory
|
|
||||||
size_t parentAABBArrayIndex = AABBTreeVec.size();
|
|
||||||
AABBTreeVec.resize(AABBTreeVec.size() + totalParentCount);
|
|
||||||
*out_parentCount = totalParentCount;
|
|
||||||
*out_parentStartIndex = parentAABBArrayIndex;
|
|
||||||
|
|
||||||
for (auto& matData : uniqueMaterials)
|
|
||||||
{
|
|
||||||
size_t* objIndexes = matData.objectIndexes.data();
|
|
||||||
size_t objCount = matData.objectIndexes.size();
|
|
||||||
size_t parentCount = objCount / BSPGameConstants::MAX_AABB_TREE_CHILDREN;
|
|
||||||
size_t remainder = objCount % BSPGameConstants::MAX_AABB_TREE_CHILDREN;
|
|
||||||
if (remainder > 0)
|
|
||||||
parentCount++;
|
|
||||||
|
|
||||||
size_t unaddedObjectCount = objCount;
|
|
||||||
size_t addedObjectCount = 0;
|
|
||||||
for (size_t parentIdx = 0; parentIdx < parentCount; parentIdx++)
|
|
||||||
{
|
|
||||||
size_t currChildObjectCount = BSPGameConstants::MAX_AABB_TREE_CHILDREN;
|
|
||||||
if (unaddedObjectCount <= BSPGameConstants::MAX_AABB_TREE_CHILDREN)
|
|
||||||
currChildObjectCount = unaddedObjectCount;
|
|
||||||
else
|
|
||||||
unaddedObjectCount -= BSPGameConstants::MAX_AABB_TREE_CHILDREN;
|
|
||||||
|
|
||||||
vec3_t parentMins;
|
|
||||||
vec3_t parentMaxs;
|
|
||||||
size_t childObjectStartIndex = AABBTreeVec.size();
|
|
||||||
for (size_t objectIdx = 0; objectIdx < currChildObjectCount; objectIdx++)
|
|
||||||
{
|
|
||||||
// create a child AABBTree with the partition and add it to AABBTreeVec
|
|
||||||
int partitionIndex = bspLeaf->getObject(objIndexes[addedObjectCount + objectIdx])->partitionIndex;
|
|
||||||
CollisionPartition* partition = &clipMap->partitions[partitionIndex];
|
|
||||||
vec3_t childMins;
|
|
||||||
vec3_t childMaxs;
|
|
||||||
calculatePartitionAABB(clipMap, partition, childMins, childMaxs);
|
|
||||||
|
|
||||||
CollisionAabbTree childAABBTree;
|
|
||||||
childAABBTree.materialIndex = matData.materialIndex;
|
|
||||||
childAABBTree.childCount = 0;
|
|
||||||
childAABBTree.u.partitionIndex = partitionIndex;
|
|
||||||
childAABBTree.origin = BSPUtil::calcMiddleOfAABB(childMins, childMaxs);
|
|
||||||
childAABBTree.halfSize = BSPUtil::calcHalfSizeOfAABB(childMins, childMaxs);
|
|
||||||
AABBTreeVec.emplace_back(childAABBTree);
|
|
||||||
|
|
||||||
// update the parent AABB with the child AABB
|
|
||||||
if (objectIdx == 0)
|
|
||||||
{
|
|
||||||
parentMins = childMins;
|
|
||||||
parentMaxs = childMaxs;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
BSPUtil::updateAABB(childMins, childMaxs, parentMins, parentMaxs);
|
|
||||||
}
|
|
||||||
|
|
||||||
CollisionAabbTree parentAABB;
|
|
||||||
parentAABB.materialIndex = matData.materialIndex;
|
|
||||||
parentAABB.origin = BSPUtil::calcMiddleOfAABB(parentMins, parentMaxs);
|
|
||||||
parentAABB.halfSize = BSPUtil::calcHalfSizeOfAABB(parentMins, parentMaxs);
|
|
||||||
parentAABB.childCount = static_cast<uint16_t>(currChildObjectCount);
|
|
||||||
parentAABB.u.firstChildIndex = static_cast<int>(childObjectStartIndex);
|
|
||||||
AABBTreeVec.at(parentAABBArrayIndex + parentIdx) = parentAABB;
|
|
||||||
|
|
||||||
addedObjectCount += currChildObjectCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
parentAABBArrayIndex += parentCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_treeContents = 0;
|
|
||||||
for (auto& matData : uniqueMaterials)
|
|
||||||
*out_treeContents |= clipMap->info.materials[matData.materialIndex].contentFlags;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
constexpr vec3_t normalX = {1.0f, 0.0f, 0.0f};
|
constexpr vec3_t normalX = {1.0f, 0.0f, 0.0f};
|
||||||
constexpr vec3_t normalY = {0.0f, 1.0f, 0.0f};
|
constexpr vec3_t normalY = {0.0f, 1.0f, 0.0f};
|
||||||
constexpr vec3_t normalZ = {0.0f, 0.0f, 1.0f};
|
constexpr vec3_t normalZ = {0.0f, 0.0f, 1.0f};
|
||||||
@@ -841,104 +717,6 @@ namespace BSP
|
|||||||
memcpy(clipMap->info.uinds, uniqueIndicesVec.data(), sizeof(uint16_t) * uniqueIndicesVec.size());
|
memcpy(clipMap->info.uinds, uniqueIndicesVec.data(), sizeof(uint16_t) * uniqueIndicesVec.size());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//// The clipmap index buffer has a unique index for each vertex in the world, compared to the gfxworld's
|
|
||||||
//// index buffer having a unique index for each vertex on a surface. This code converts gfxworld indices to clipmap indices.
|
|
||||||
// std::vector<uint16_t> triIndexVec;
|
|
||||||
// for (BSPSurface& surface : bsp->colWorld.surfaces)
|
|
||||||
//{
|
|
||||||
// int indexOfFirstIndex = surface.indexOfFirstIndex;
|
|
||||||
// int indexOfFirstVertex = surface.indexOfFirstVertex;
|
|
||||||
// for (int indexIdx = 0; indexIdx < surface.triCount * 3; indexIdx++)
|
|
||||||
// {
|
|
||||||
// int triIndex = bsp->colWorld.indices[indexOfFirstIndex + indexIdx] + indexOfFirstVertex;
|
|
||||||
// triIndexVec.emplace_back(triIndex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//// the reinterpret_cast is used as triIndices is just a pointer to an array of indicies, and static_cast can't safely do the conversion
|
|
||||||
// clipMap->triCount = static_cast<int>(triIndexVec.size() / 3);
|
|
||||||
// clipMap->triIndices = reinterpret_cast<uint16_t(*)[3]>(m_memory.Alloc<uint16_t>(triIndexVec.size()));
|
|
||||||
// memcpy(clipMap->triIndices, &triIndexVec[0], sizeof(uint16_t) * triIndexVec.size());
|
|
||||||
//
|
|
||||||
//// partitions are "containers" for vertices. BSP tree leafs contain a list of these partitions to determine the collision within a leaf.
|
|
||||||
// std::vector<CollisionPartition> partitionVec;
|
|
||||||
// std::vector<uint16_t> uniqueIndicesVec;
|
|
||||||
// for (size_t surfIdx = 0; surfIdx < bsp->colWorld.surfaces.size(); surfIdx++)
|
|
||||||
//{
|
|
||||||
// BSPSurface& surface = bsp->colWorld.surfaces[surfIdx];
|
|
||||||
//
|
|
||||||
// // partitions are made for each triangle, not one for each surface.
|
|
||||||
// // one for each surface causes physics bugs, as the entire bounding box is considered solid instead of the surface itself (for some reason).
|
|
||||||
// // so a partition is made for each triangle which removes the physics bugs but likely makes the game run slower
|
|
||||||
// int indexOfFirstTri = surface.indexOfFirstIndex / 3;
|
|
||||||
// int indexOfFirstVertex = surface.indexOfFirstVertex;
|
|
||||||
// for (int triIdx = 0; triIdx < surface.triCount; triIdx++)
|
|
||||||
// {
|
|
||||||
// CollisionPartition partition;
|
|
||||||
// partition.triCount = 1;
|
|
||||||
// partition.firstTri = indexOfFirstTri + triIdx;
|
|
||||||
//
|
|
||||||
// partition.nuinds = 3;
|
|
||||||
// partition.fuind = static_cast<int>(uniqueIndicesVec.size());
|
|
||||||
//
|
|
||||||
// // All tri indices are unique since there is only one tri per partition
|
|
||||||
// uint16_t* tri = clipMap->triIndices[partition.firstTri];
|
|
||||||
// uniqueIndicesVec.emplace_back(tri[0]);
|
|
||||||
// uniqueIndicesVec.emplace_back(tri[1]);
|
|
||||||
// uniqueIndicesVec.emplace_back(tri[2]);
|
|
||||||
//
|
|
||||||
// partitionVec.emplace_back(partition);
|
|
||||||
//
|
|
||||||
// partitionToMaterialMap.emplace_back(surface.materialIndex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// clipMap->partitionCount = static_cast<int>(partitionVec.size());
|
|
||||||
// clipMap->partitions = m_memory.Alloc<CollisionPartition>(clipMap->partitionCount);
|
|
||||||
// memcpy(clipMap->partitions, partitionVec.data(), sizeof(CollisionPartition) * partitionVec.size());
|
|
||||||
//
|
|
||||||
// clipMap->info.nuinds = static_cast<int>(uniqueIndicesVec.size());
|
|
||||||
// clipMap->info.uinds = m_memory.Alloc<uint16_t>(uniqueIndicesVec.size());
|
|
||||||
// memcpy(clipMap->info.uinds, uniqueIndicesVec.data(), sizeof(uint16_t) * uniqueIndicesVec.size());
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Proper unique index creation code kept for future use
|
|
||||||
int totalUindCount = 0;
|
|
||||||
std::vector<uint16_t> uindVec;
|
|
||||||
for (int i = 0; i < clipMap->partitionCount; i++)
|
|
||||||
{
|
|
||||||
CollisionPartition* currPartition = &clipMap->partitions[i];
|
|
||||||
std::vector<uint16_t> uniqueVertVec;
|
|
||||||
for (int k = 0; k < currPartition->triCount; k++)
|
|
||||||
{
|
|
||||||
uint16_t* tri = clipMap->triIndices[currPartition->firstTri + k];
|
|
||||||
for (int l = 0; l < 3; l++)
|
|
||||||
{
|
|
||||||
bool isVertexIndexUnique = true;
|
|
||||||
uint16_t vertIndex = tri[l];
|
|
||||||
|
|
||||||
for (size_t m = 0; m < uniqueVertVec.size(); m++)
|
|
||||||
{
|
|
||||||
if (uniqueVertVec[m] == vertIndex)
|
|
||||||
{
|
|
||||||
isVertexIndexUnique = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isVertexIndexUnique)
|
|
||||||
uniqueVertVec.emplace_back(vertIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currPartition->fuind = totalUindCount;
|
|
||||||
currPartition->nuinds = (int)uniqueVertVec.size();
|
|
||||||
uindVec.insert(uindVec.end(), uniqueVertVec.begin(), uniqueVertVec.end());
|
|
||||||
totalUindCount += currPartition->nuinds;
|
|
||||||
}
|
|
||||||
clipMap->info.nuinds = totalUindCount;
|
|
||||||
clipMap->info.uinds = m_memory.Alloc<uint16_t>(totalUindCount);
|
|
||||||
memcpy(clipMap->info.uinds, &uindVec[0], sizeof(uint16_t) * totalUindCount);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClipMapLinker::loadWorldCollision(clipMap_t* clipMap, BSPData* bsp)
|
bool ClipMapLinker::loadWorldCollision(clipMap_t* clipMap, BSPData* bsp)
|
||||||
|
|||||||
Reference in New Issue
Block a user