From 12647a505c4d46cb196ba313c8071e082077befc Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Mon, 10 Nov 2025 22:12:17 +0100 Subject: [PATCH] chore: misc code improvements --- src/ObjLoading/Game/T6/BSP/BSPCalculation.cpp | 1 + src/ObjLoading/Game/T6/BSP/BSPCalculation.h | 1 + src/ObjLoading/Game/T6/BSP/BSPUtil.cpp | 14 ++++++++------ .../Game/T6/BSP/Linker/ClipMapLinker.cpp | 14 ++++++++++---- .../Game/T6/BSP/Linker/ComWorldLinker.cpp | 2 ++ src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.h | 1 + .../Game/T6/BSP/Linker/GameWorldMpLinker.h | 1 + src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h | 1 + src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.h | 1 + .../Game/T6/BSP/Linker/SkinnedVertsLinker.h | 1 + .../Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp | 2 +- 11 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/ObjLoading/Game/T6/BSP/BSPCalculation.cpp b/src/ObjLoading/Game/T6/BSP/BSPCalculation.cpp index 8bba32ba..5837743f 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPCalculation.cpp +++ b/src/ObjLoading/Game/T6/BSP/BSPCalculation.cpp @@ -88,6 +88,7 @@ namespace BSP max.y = yMax; max.z = zMax; level = treeLevel; + splitTree(); } diff --git a/src/ObjLoading/Game/T6/BSP/BSPCalculation.h b/src/ObjLoading/Game/T6/BSP/BSPCalculation.h index 08a5e39e..1b2fe988 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPCalculation.h +++ b/src/ObjLoading/Game/T6/BSP/BSPCalculation.h @@ -59,6 +59,7 @@ namespace BSP { public: BSPTree(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax, int treeLevel); + void splitTree(); void addObjectToTree(std::shared_ptr object) const; diff --git a/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp b/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp index b0f8e3a8..b931a680 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp +++ b/src/ObjLoading/Game/T6/BSP/BSPUtil.cpp @@ -62,6 +62,7 @@ namespace BSP result.x = (mins.x + maxs.x) * 0.5f; result.y = (mins.y + maxs.y) * 0.5f; result.z = (mins.z + maxs.z) * 0.5f; + return result; } @@ -71,6 +72,7 @@ namespace BSP result.x = (maxs.x - mins.x) * 0.5f; result.y = (maxs.y - mins.y) * 0.5f; result.z = (maxs.z - mins.z) * 0.5f; + return result; } @@ -91,12 +93,12 @@ namespace BSP const auto yRadians = angles->y * conversionValue; const auto zRadians = angles->z * conversionValue; - const auto cosX = cos(xRadians); - const auto sinX = sin(xRadians); - const auto cosY = cos(yRadians); - const auto sinY = sin(yRadians); - const auto cosZ = cos(zRadians); - const auto sinZ = sin(zRadians); + const auto cosX = std::cos(xRadians); + const auto sinX = std::sin(xRadians); + const auto cosY = std::cos(yRadians); + const auto sinY = std::sin(yRadians); + const auto cosZ = std::cos(zRadians); + const auto sinZ = std::sin(zRadians); axis[0].x = cosX * cosY; axis[0].y = cosX * sinY; diff --git a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp index ce40b08e..bd36aa20 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp @@ -295,7 +295,7 @@ namespace BSP BSPUtil::updateAABBWithPoint(vert, childMins, childMaxs); } - CollisionAabbTree childAABBTree; + CollisionAabbTree childAABBTree{}; childAABBTree.materialIndex = 0; // always use the first material childAABBTree.childCount = 0; childAABBTree.u.partitionIndex = partitionIndex; @@ -311,9 +311,15 @@ namespace BSP outParentStartIndex = parentAABBArrayIndex; } - constexpr vec3_t normalX = {1.0f, 0.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 normalX = { + {.x = 1.0f, .y = 0.0f, .z = 0.0f} + }; + constexpr vec3_t normalY = { + {.x = 0.0f, .y = 1.0f, .z = 0.0f} + }; + constexpr vec3_t normalZ = { + {.x = 0.0f, .y = 0.0f, .z = 1.0f} + }; // returns the index of the node/leaf parsed by the function // Nodes are indexed by their index in the node array diff --git a/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.cpp index 3ddd2e01..77d7f895 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.cpp @@ -15,6 +15,7 @@ namespace BSP { // all lights that aren't the sunlight or default light need their own GfxLightDef asset ComWorld* comWorld = m_memory.Alloc(); + comWorld->name = m_memory.Dup(bsp.bspName.c_str()); comWorld->isInUse = 1; comWorld->primaryLightCount = BSPGameConstants::BSP_DEFAULT_LIGHT_COUNT; @@ -25,6 +26,7 @@ namespace BSP ComPrimaryLight* sunLight = &comWorld->primaryLights[1]; const vec4_t sunLightColor = BSPEditableConstants::SUNLIGHT_COLOR; const vec3_t sunLightDirection = BSPEditableConstants::SUNLIGHT_DIRECTION; + sunLight->type = GFX_LIGHT_TYPE_DIR; sunLight->diffuseColor.r = sunLightColor.r; sunLight->diffuseColor.g = sunLightColor.g; diff --git a/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.h index 3f3652b2..5f63acce 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/ComWorldLinker.h @@ -11,6 +11,7 @@ namespace BSP { public: ComWorldLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context); + [[nodiscard]] T6::ComWorld* linkComWorld(const BSPData& bsp) const; private: diff --git a/src/ObjLoading/Game/T6/BSP/Linker/GameWorldMpLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/GameWorldMpLinker.h index 86c64a7e..b7d0fb40 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/GameWorldMpLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/GameWorldMpLinker.h @@ -11,6 +11,7 @@ namespace BSP { public: GameWorldMpLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context); + [[nodiscard]] T6::GameWorldMp* linkGameWorldMp(const BSPData& bsp) const; private: diff --git a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h index 796f6be9..c540b372 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h @@ -11,6 +11,7 @@ namespace BSP { public: GfxWorldLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context); + [[nodiscard]] T6::GfxWorld* linkGfxWorld(const BSPData& bsp) const; private: diff --git a/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.h index 4f796b2e..0c0b7e58 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.h @@ -11,6 +11,7 @@ namespace BSP { public: MapEntsLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context); + [[nodiscard]] T6::MapEnts* linkMapEnts(const BSPData& bsp) const; private: diff --git a/src/ObjLoading/Game/T6/BSP/Linker/SkinnedVertsLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/SkinnedVertsLinker.h index e892114d..0b280920 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/SkinnedVertsLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/SkinnedVertsLinker.h @@ -11,6 +11,7 @@ namespace BSP { public: SkinnedVertsLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context); + [[nodiscard]] T6::SkinnedVertsDef* linkSkinnedVerts(const BSPData& bsp) const; private: diff --git a/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp b/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp index 43cc6e0b..6e59b1fb 100644 --- a/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp +++ b/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp @@ -91,7 +91,7 @@ namespace consts[1] = currArgJs["u"]["const1"]; consts[2] = currArgJs["u"]["const2"]; consts[3] = currArgJs["u"]["const3"]; - currArg->u.literalConst = (float(*)[4])consts; + currArg->u.literalConst = (float (*)[4])consts; } else {