2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-23 05:12:05 +00:00

Formatted all BSP loading files using clang.

This commit is contained in:
LJW-Dev
2025-10-27 20:43:30 +08:00
parent 0e19f365ff
commit 0fa473eadd
22 changed files with 384 additions and 402 deletions

View File

@@ -1,13 +1,12 @@
#pragma once
#include <vector>
#include <string>
#include <memory>
#include <cassert>
#include "Game/T6/T6.h"
#include "Utils/Logging/Log.h"
#include "Game/T6/T6.h"
#include <cassert>
#include <memory>
#include <string>
#include <vector>
using namespace T6;
namespace BSP
@@ -71,8 +70,7 @@ namespace BSP
BSP_DEFAULT_LIGHT_COUNT = 2
};
inline const char* DEFENDER_SPAWN_POINT_NAMES[] = {
"mp_ctf_spawn_allies",
inline const char* DEFENDER_SPAWN_POINT_NAMES[] = {"mp_ctf_spawn_allies",
"mp_ctf_spawn_allies_start",
"mp_sd_spawn_defender",
"mp_dom_spawn_allies_start",
@@ -82,11 +80,9 @@ namespace BSP
"mp_tdm_spawn_allies_start",
"mp_tdm_spawn_team1_start",
"mp_tdm_spawn_team2_start",
"mp_tdm_spawn_team3_start"
};
"mp_tdm_spawn_team3_start"};
inline const char* ATTACKER_SPAWN_POINT_NAMES[] = {
"mp_ctf_spawn_axis",
inline const char* ATTACKER_SPAWN_POINT_NAMES[] = {"mp_ctf_spawn_axis",
"mp_ctf_spawn_axis_start",
"mp_sd_spawn_attacker",
"mp_dom_spawn_axis_start",
@@ -96,15 +92,10 @@ namespace BSP
"mp_tdm_spawn_axis_start",
"mp_tdm_spawn_team4_start",
"mp_tdm_spawn_team5_start",
"mp_tdm_spawn_team6_start"
};
"mp_tdm_spawn_team6_start"};
inline const char* FFA_SPAWN_POINT_NAMES[] = {
"mp_tdm_spawn",
"mp_dm_spawn",
"mp_dom_spawn"
};
}
inline const char* FFA_SPAWN_POINT_NAMES[] = {"mp_tdm_spawn", "mp_dm_spawn", "mp_dom_spawn"};
} // namespace BSPGameConstants
// BSPLinkingConstants:
// These values are BSP linking constants that are required for the link to be successful
@@ -134,7 +125,6 @@ namespace BSP
]
})";
constexpr const char* DEFAULT_MAP_ENTS_STRING = R"({
"entities": [
{
@@ -152,7 +142,7 @@ namespace BSP
}
]
})";
}
} // namespace BSPLinkingConstants
// BSPEditableConstants:
// These values are BSP constants that can be edited and may not break the linker/game if changed
@@ -188,7 +178,7 @@ namespace BSP
constexpr unsigned char LIGHTGRID_COLOUR = 128;
// Sunlight values
constexpr vec4_t SUNLIGHT_COLOR = { 0.75f, 0.75f, 0.75f, 1.0f };
constexpr vec3_t SUNLIGHT_DIRECTION = { 0.0f, 0.0f, 0.0f };
};
}
constexpr vec4_t SUNLIGHT_COLOR = {0.75f, 0.75f, 0.75f, 1.0f};
constexpr vec3_t SUNLIGHT_DIRECTION = {0.0f, 0.0f, 0.0f};
}; // namespace BSPEditableConstants
} // namespace BSP

View File

@@ -148,4 +148,4 @@ namespace BSP
}
}
}
}
} // namespace BSP

View File

@@ -28,7 +28,6 @@ namespace BSP
BSPObject(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax, int objPartitionIndex);
};
class BSPLeaf
{
public:
@@ -69,4 +68,4 @@ namespace BSP
void splitTree();
void addObjectToTree(std::shared_ptr<BSPObject> object);
};
}
} // namespace BSP

View File

@@ -6,11 +6,8 @@ namespace
{
using namespace BSP;
void addFBXMeshToWorld(ufbx_node* node,
std::vector<BSPSurface>& surfaceVec,
std::vector<BSPVertex>& vertexVec,
std::vector<uint16_t>& indexVec,
bool& hasTangentSpace)
void addFBXMeshToWorld(
ufbx_node* node, std::vector<BSPSurface>& surfaceVec, std::vector<BSPVertex>& vertexVec, std::vector<uint16_t>& indexVec, bool& hasTangentSpace)
{
ufbx_mesh* mesh = node->mesh;
@@ -187,7 +184,7 @@ namespace
if (hasTangentSpace == false)
con::warn("warning: one or more meshes have no tangent space. Be sure to select the tangent space box when exporting the FBX.");
}
}
} // namespace
namespace BSP
{
@@ -211,7 +208,7 @@ namespace BSP
}
ufbx_error errorGfx;
ufbx_load_opts optsGfx {};
ufbx_load_opts optsGfx{};
optsGfx.target_axes = ufbx_axes_right_handed_y_up;
optsGfx.generate_missing_normals = true;
optsGfx.allow_missing_vertex_position = false;
@@ -243,7 +240,7 @@ namespace BSP
}
ufbx_error errorCol;
ufbx_load_opts optsCol {};
ufbx_load_opts optsCol{};
optsCol.target_axes = ufbx_axes_right_handed_y_up;
optsCol.generate_missing_normals = true;
optsCol.allow_missing_vertex_position = false;

View File

@@ -6,4 +6,4 @@
namespace BSP
{
std::unique_ptr<BSPData> createBSPData(std::string& mapName, ISearchPath& searchPath);
};
}; // namespace BSP

View File

@@ -1,35 +1,37 @@
#pragma once
#include "BSPUtil.h"
#include <cmath>
#include <format>
#include "BSPUtil.h"
std::string BSPUtil::getFileNameForBSPAsset(std::string& assetName)
namespace BSP
{
std::string BSPUtil::getFileNameForBSPAsset(std::string& assetName)
{
return std::format("BSP/{}", assetName);
}
}
vec3_t BSPUtil::convertToBO2Coords(vec3_t& coordinate)
{
vec3_t BSPUtil::convertToBO2Coords(vec3_t& coordinate)
{
vec3_t result;
result.x = coordinate.x;
result.y = -coordinate.z;
result.z = coordinate.y;
return result;
}
}
vec3_t BSPUtil::convertFromBO2Coords(vec3_t& coordinate)
{
vec3_t BSPUtil::convertFromBO2Coords(vec3_t& coordinate)
{
vec3_t result;
result.x = coordinate.x;
result.y = coordinate.z;
result.z = -coordinate.y;
return result;
}
}
void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs)
{
void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs)
{
if (AABBMins.x > newAABBMins.x)
AABBMins.x = newAABBMins.x;
@@ -47,10 +49,10 @@ void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBM
if (newAABBMaxs.z > AABBMaxs.z)
AABBMaxs.z = newAABBMaxs.z;
}
}
void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs)
{
void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs)
{
if (AABBMins.x > point.x)
AABBMins.x = point.x;
@@ -68,42 +70,42 @@ void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBM
if (point.z > AABBMaxs.z)
AABBMaxs.z = point.z;
}
}
vec3_t BSPUtil::calcMiddleOfAABB(vec3_t& mins, vec3_t& maxs)
{
vec3_t BSPUtil::calcMiddleOfAABB(vec3_t& mins, vec3_t& maxs)
{
vec3_t result;
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;
}
}
vec3_t BSPUtil::calcHalfSizeOfAABB(vec3_t& mins, vec3_t& maxs)
{
vec3_t BSPUtil::calcHalfSizeOfAABB(vec3_t& mins, vec3_t& maxs)
{
vec3_t result;
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;
}
}
size_t BSPUtil::allignBy128(size_t size)
{
size_t BSPUtil::allignBy128(size_t size)
{
return ((size + 127) & 0xFFFFFF80);
}
}
float BSPUtil::distBetweenPoints(vec3_t& p1, vec3_t& p2)
{
float BSPUtil::distBetweenPoints(vec3_t& p1, vec3_t& p2)
{
float x = p2.x - p1.x;
float y = p2.y - p1.y;
float z = p2.z - p1.z;
return sqrtf((x * x) + (y * y) + (z * z));
}
}
// angles are in euler degrees
void BSPUtil::convertAnglesToAxis(vec3_t* angles, vec3_t* axis)
{
// angles are in euler degrees
void BSPUtil::convertAnglesToAxis(vec3_t* angles, vec3_t* axis)
{
float xRadians = angles->x * 0.017453292f; // M_PI / 180.0f
float yRadians = angles->y * 0.017453292f; // M_PI / 180.0f
float zRadians = angles->z * 0.017453292f; // M_PI / 180.0f
@@ -124,10 +126,10 @@ void BSPUtil::convertAnglesToAxis(vec3_t* angles, vec3_t* axis)
axis[2].x = (cosZ * sinX * cosY) + (sinZ * sinY);
axis[2].y = (cosZ * sinX * sinY) - (sinZ * cosY);
axis[2].z = cosZ * cosX;
}
}
void BSPUtil::matrixTranspose3x3(const vec3_t* in, vec3_t* out)
{
void BSPUtil::matrixTranspose3x3(const vec3_t* in, vec3_t* out)
{
out[0].x = in[0].x;
out[0].y = in[1].x;
out[0].z = in[2].x;
@@ -137,10 +139,10 @@ void BSPUtil::matrixTranspose3x3(const vec3_t* in, vec3_t* out)
out[2].x = in[0].z;
out[2].y = in[1].z;
out[2].z = in[2].z;
}
}
vec3_t BSPUtil::convertStringToVec3(std::string& str)
{
vec3_t BSPUtil::convertStringToVec3(std::string& str)
{
std::string v1Str = str;
int nextValIndex = 0;
@@ -160,10 +162,12 @@ vec3_t BSPUtil::convertStringToVec3(std::string& str)
result.y = static_cast<float>(atof(v2Str.c_str()));
result.z = static_cast<float>(atof(v3Str.c_str()));
return result;
}
}
std::string BSPUtil::convertVec3ToString(vec3_t& vec)
{
std::string BSPUtil::convertVec3ToString(vec3_t& vec)
{
std::string result = std::format("{} {} {}", vec.x, vec.y, vec.z);
return result;
}
}
} // namespace BSP

View File

@@ -2,10 +2,11 @@
#include "BSP.h"
class BSPUtil
namespace BSP
{
public:
class BSPUtil
{
public:
static std::string getFileNameForBSPAsset(std::string& assetName);
static vec3_t convertToBO2Coords(vec3_t& OGL_coordinate);
static vec3_t convertFromBO2Coords(vec3_t& bo2_coordinate);
@@ -19,4 +20,5 @@ public:
static void matrixTranspose3x3(const vec3_t* in, vec3_t* out);
static vec3_t convertStringToVec3(std::string& str);
static std::string convertVec3ToString(vec3_t& vec);
};
};
} // namespace BSP

View File

@@ -1,7 +1,6 @@
#include "BSPLinker.h"
#include "ComWorldLinker.h"
#include "ClipMapLinker.h"
#include "ComWorldLinker.h"
#include "GameWorldMpLinker.h"
#include "GfxWorldLinker.h"
#include "MapEntsLinker.h"
@@ -93,5 +92,4 @@ namespace BSP
return result;
}
}
} // namespace BSP

View File

@@ -21,4 +21,4 @@ namespace BSP
ISearchPath& m_search_path;
AssetCreationContext& m_context;
};
}
} // namespace BSP

View File

@@ -1,5 +1,5 @@
#include "ClipMapLinker.h"
#include "../BSPUtil.h"
#include "ClipMapLinker.h"
namespace BSP
{
@@ -282,9 +282,9 @@ namespace BSP
return static_cast<int>(parentAABBIndex);
}
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 = {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};
// returns the index of the node/leaf parsed by the function
// Nodes are indexed by their index in the node array
@@ -428,7 +428,8 @@ namespace BSP
}
BSPUtil::updateAABBWithPoint(vert, partitionMins, partitionMaxs);
}
std::shared_ptr<BSPObject> currObject = std::make_shared<BSPObject>(partitionMins.x, partitionMins.y, partitionMins.z, partitionMaxs.x, partitionMaxs.y, partitionMaxs.z, partitionIdx);
std::shared_ptr<BSPObject> currObject =
std::make_shared<BSPObject>(partitionMins.x, partitionMins.y, partitionMins.z, partitionMaxs.x, partitionMaxs.y, partitionMaxs.z, partitionIdx);
tree->addObjectToTree(std::move(currObject));
}
@@ -493,7 +494,7 @@ namespace BSP
}
// 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()));
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.
@@ -648,5 +649,4 @@ namespace BSP
auto clipMapAsset = m_context.AddAsset<AssetClipMap>(clipMap->name, clipMap);
return AssetCreationResult::Success(clipMapAsset);
}
}
} // namespace BSP

View File

@@ -1,10 +1,10 @@
#pragma once
#include "../BSP.h"
#include "../BSPCalculation.h"
#include "Asset/IAssetCreator.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include "../BSPCalculation.h"
namespace BSP
{
@@ -36,4 +36,4 @@ namespace BSP
bool loadPartitions(clipMap_t* clipMap, BSPData* bsp);
bool loadWorldCollision(clipMap_t* clipMap, BSPData* bsp);
};
}
} // namespace BSP

View File

@@ -35,5 +35,4 @@ namespace BSP
auto comWorldAsset = m_context.AddAsset<AssetComWorld>(comWorld->name, comWorld);
return AssetCreationResult::Success(comWorldAsset);
}
}
} // namespace BSP

View File

@@ -18,4 +18,4 @@ namespace BSP
ISearchPath& m_search_path;
AssetCreationContext& m_context;
};
}
} // namespace BSP

View File

@@ -32,5 +32,4 @@ namespace BSP
auto gameWorldMpAsset = m_context.AddAsset<AssetGameWorldMp>(gameWorldMp->name, gameWorldMp);
return AssetCreationResult::Success(gameWorldMpAsset);
}
}
} // namespace BSP

View File

@@ -18,4 +18,4 @@ namespace BSP
ISearchPath& m_search_path;
AssetCreationContext& m_context;
};
}
} // namespace BSP

View File

@@ -1,5 +1,5 @@
#include "GfxWorldLinker.h"
#include "../BSPUtil.h"
#include "GfxWorldLinker.h"
#include "Utils/Pack.h"
namespace BSP
@@ -409,7 +409,7 @@ namespace BSP
gfxWorld->lightGrid.entries = entryArray;
// colours are looked up with a lightgrid entries colorsIndex
gfxWorld->lightGrid.colorCount = 0x1000; //0x1000 as it should be enough to hold every index
gfxWorld->lightGrid.colorCount = 0x1000; // 0x1000 as it should be enough to hold every index
gfxWorld->lightGrid.colors = m_memory.Alloc<GfxCompressedLightGridColors>(gfxWorld->lightGrid.colorCount);
memset(gfxWorld->lightGrid.colors, BSPEditableConstants::LIGHTGRID_COLOUR, rowDataStartSize * sizeof(uint16_t));
@@ -519,7 +519,7 @@ namespace BSP
// Other models aren't implemented yet
// Code kept for future use
//for (size_t i = 0; i < entityModelList.size(); i++)
// for (size_t i = 0; i < entityModelList.size(); i++)
//{
// auto currEntModel = &gfxWorld->models[i + 1];
// entModelBounds currEntModelBounds = entityModelList[i];
@@ -772,5 +772,4 @@ namespace BSP
auto gfxWorldAsset = m_context.AddAsset<AssetGfxWorld>(gfxWorld->name, gfxWorld);
return AssetCreationResult::Success(gfxWorldAsset);
}
}
} // namespace BSP

View File

@@ -34,4 +34,4 @@ namespace BSP
void loadSunData(GfxWorld* gfxWorld);
void loadWorldBounds(GfxWorld* gfxWorld);
};
}
} // namespace BSP

View File

@@ -1,5 +1,5 @@
#include "MapEntsLinker.h"
#include "../BSPUtil.h"
#include "MapEntsLinker.h"
#include <nlohmann/json.hpp>
using namespace nlohmann;
@@ -59,11 +59,8 @@ namespace
}
}
std::string loadMapEnts()
{
}
}
std::string loadMapEnts() {}
} // namespace
namespace BSP
{
@@ -138,5 +135,4 @@ namespace BSP
return AssetCreationResult::Failure();
}
}
}
} // namespace BSP

View File

@@ -18,4 +18,4 @@ namespace BSP
ISearchPath& m_search_path;
AssetCreationContext& m_context;
};
}
} // namespace BSP

View File

@@ -22,5 +22,4 @@ namespace BSP
auto skinnedVertsAsset = m_context.AddAsset<AssetSkinnedVerts>(assetName, skinnedVerts);
return AssetCreationResult::Success(skinnedVertsAsset);
}
}
} // namespace BSP

View File

@@ -18,4 +18,4 @@ namespace BSP
ISearchPath& m_search_path;
AssetCreationContext& m_context;
};
}
} // namespace BSP

View File

@@ -1,7 +1,7 @@
#include "LoaderBSP_T6.h"
#include "BSPCreator.h"
#include "BSPUtil.h"
#include "Linker/BSPLinker.h"
#include "LoaderBSP_T6.h"
namespace
{