From a8456f88a49fae340446833234f33df1c2274e5b Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Thu, 6 Nov 2025 20:25:32 +0100 Subject: [PATCH] chore: use std min and std max in bsp utils --- src/ObjLoading/Game/T6/BSP/BSPUtil.cpp | 43 ++++++------------- .../Game/T6/BSP/Linker/ClipMapLinker.cpp | 3 +- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp b/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp index 070edf11..452faf68 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp +++ b/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp @@ -1,5 +1,6 @@ #include "BSPUtil.h" +#include #include #include @@ -32,44 +33,26 @@ namespace BSP void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs) { - if (AABBMins.x > newAABBMins.x) - AABBMins.x = newAABBMins.x; + AABBMins.x = std::min(AABBMins.x, newAABBMins.x); + AABBMaxs.x = std::max(AABBMaxs.x, newAABBMaxs.x); - if (newAABBMaxs.x > AABBMaxs.x) - AABBMaxs.x = newAABBMaxs.x; + AABBMins.y = std::min(AABBMins.y, newAABBMins.y); + AABBMaxs.y = std::max(AABBMaxs.y, newAABBMaxs.y); - if (AABBMins.y > newAABBMins.y) - AABBMins.y = newAABBMins.y; - - if (newAABBMaxs.y > AABBMaxs.y) - AABBMaxs.y = newAABBMaxs.y; - - if (AABBMins.z > newAABBMins.z) - AABBMins.z = newAABBMins.z; - - if (newAABBMaxs.z > AABBMaxs.z) - AABBMaxs.z = newAABBMaxs.z; + AABBMins.z = std::min(AABBMins.z, newAABBMins.z); + AABBMaxs.z = std::max(AABBMaxs.z, newAABBMaxs.z); } void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs) { - if (AABBMins.x > point.x) - AABBMins.x = point.x; + AABBMins.x = std::min(AABBMins.x, point.x); + AABBMaxs.x = std::max(AABBMaxs.x, point.x); - if (point.x > AABBMaxs.x) - AABBMaxs.x = point.x; + AABBMins.y = std::min(AABBMins.y, point.y); + AABBMaxs.y = std::max(AABBMaxs.y, point.y); - if (AABBMins.y > point.y) - AABBMins.y = point.y; - - if (point.y > AABBMaxs.y) - AABBMaxs.y = point.y; - - if (AABBMins.z > point.z) - AABBMins.z = point.z; - - if (point.z > AABBMaxs.z) - AABBMaxs.z = point.z; + AABBMins.z = std::min(AABBMins.z, point.z); + AABBMaxs.z = std::max(AABBMaxs.z, point.z); } vec3_t BSPUtil::calcMiddleOfAABB(vec3_t& mins, vec3_t& maxs) diff --git a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp index fd857f4c..23cf6ac2 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp @@ -217,8 +217,7 @@ namespace BSP size_t leafObjectCount = tree->leaf->getObjectCount(); assert(leafObjectCount > 0); - if (leafObjectCount > highestLeafObjectCount) - highestLeafObjectCount = leafObjectCount; + highestLeafObjectCount = std::max(leafObjectCount, highestLeafObjectCount); // 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