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

chore: use enum class for non-game enums

This commit is contained in:
Jan Laupetin
2025-11-10 21:07:48 +01:00
parent 049fa2b8ae
commit f811c14cc2
6 changed files with 38 additions and 25 deletions

View File

@@ -3,12 +3,13 @@
#include "Game/T6/T6.h"
#include "Utils/Logging/Log.h"
#include <cstdint>
#include <string>
#include <vector>
namespace BSP
{
enum BSPMaterialType
enum class BSPMaterialType : std::uint8_t
{
MATERIAL_TYPE_COLOUR,
MATERIAL_TYPE_TEXTURE,

View File

@@ -1,5 +1,7 @@
#include "BSPCalculation.h"
#include <cassert>
namespace BSP
{
constexpr int MAX_NODE_SIZE = 512; // maximum size a BSP node can be before it becomes a leaf
@@ -44,18 +46,20 @@ namespace BSP
float minCoord, maxCoord;
// Select the relevant coordinate based on the plane's axis
if (axis == AXIS_X)
if (axis == PlaneAxis::AXIS_X)
{
minCoord = object.min.x;
maxCoord = object.max.x;
}
else if (axis == AXIS_Y)
else if (axis == PlaneAxis::AXIS_Y)
{
minCoord = object.min.y;
maxCoord = object.max.y;
}
else // axis == AXIS_Z
else
{
assert(axis == PlaneAxis::AXIS_Z);
minCoord = object.min.z;
maxCoord = object.max.z;
}
@@ -63,15 +67,15 @@ namespace BSP
// Compare with the plane's distance
if (maxCoord < distance)
{
return SIDE_BACK; // Object is entirely on the negative side
return PlaneSide::SIDE_BACK; // Object is entirely on the negative side
}
else if (minCoord > distance)
{
return SIDE_FRONT; // Object is entirely on the positive side
return PlaneSide::SIDE_FRONT; // Object is entirely on the positive side
}
else
{
return SIDE_INTERSECTS;
return PlaneSide::SIDE_INTERSECTS;
}
}
@@ -101,7 +105,7 @@ namespace BSP
back = std::make_unique<BSPTree>(min.x, min.y, min.z, halfLength, max.y, max.z, level + 1);
isLeaf = false;
node = std::make_unique<BSPNode>(std::move(front), std::move(back), AXIS_X, halfLength);
node = std::make_unique<BSPNode>(std::move(front), std::move(back), PlaneAxis::AXIS_X, halfLength);
leaf = nullptr;
}
else if (max.y - min.y > MAX_NODE_SIZE)
@@ -112,7 +116,7 @@ namespace BSP
back = std::make_unique<BSPTree>(min.x, min.y, min.z, max.x, halfLength, max.z, level + 1);
isLeaf = false;
node = std::make_unique<BSPNode>(std::move(front), std::move(back), AXIS_Y, halfLength);
node = std::make_unique<BSPNode>(std::move(front), std::move(back), PlaneAxis::AXIS_Y, halfLength);
leaf = nullptr;
}
else if (max.z - min.z > MAX_NODE_SIZE)
@@ -123,7 +127,7 @@ namespace BSP
back = std::make_unique<BSPTree>(min.x, min.y, min.z, max.x, max.y, halfLength, level + 1);
isLeaf = false;
node = std::make_unique<BSPNode>(std::move(front), std::move(back), AXIS_Z, halfLength);
node = std::make_unique<BSPNode>(std::move(front), std::move(back), PlaneAxis::AXIS_Z, halfLength);
leaf = nullptr;
}
else
@@ -143,11 +147,12 @@ namespace BSP
else
{
const auto side = node->objectIsInFront(*object);
if (side == SIDE_FRONT)
if (side == PlaneSide::SIDE_FRONT)
{
node->front->addObjectToTree(std::move(object));
}
else if (side == SIDE_BACK)
else if (side == PlaneSide::SIDE_BACK)
{
node->back->addObjectToTree(std::move(object));
}

View File

@@ -2,16 +2,18 @@
#include "BSP.h"
#include <cstdint>
namespace BSP
{
enum PlaneAxis
enum class PlaneAxis : std::uint8_t
{
AXIS_X,
AXIS_Y,
AXIS_Z
};
enum PlaneSide
enum class PlaneSide : std::uint8_t
{
SIDE_FRONT,
SIDE_BACK,

View File

@@ -67,12 +67,12 @@ namespace
if (mesh->materials.count == 0)
{
surface.material.materialType = MATERIAL_TYPE_EMPTY;
surface.material.materialType = BSPMaterialType::MATERIAL_TYPE_EMPTY;
surface.material.materialName = "";
}
else
{
surface.material.materialType = MATERIAL_TYPE_TEXTURE;
surface.material.materialType = BSPMaterialType::MATERIAL_TYPE_TEXTURE;
surface.material.materialName = mesh->materials.data[meshPart.index]->name.data;
}
@@ -98,15 +98,18 @@ namespace
blenderCoords.z = static_cast<float>(transformedPos.z);
vertex.pos = BSPUtil::convertToBO2Coords(blenderCoords);
if (surface.material.materialType == MATERIAL_TYPE_TEXTURE || surface.material.materialType == MATERIAL_TYPE_EMPTY)
if (surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_TEXTURE
|| surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_EMPTY)
{
vertex.color.x = 1.0f;
vertex.color.y = 1.0f;
vertex.color.z = 1.0f;
vertex.color.w = 1.0f;
}
else // surface->material.materialType == MATERIAL_TYPE_COLOUR
else
{
assert(surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_COLOUR);
float factor = static_cast<float>(mesh->materials.data[meshPart.index]->fbx.diffuse_factor.value_real);
ufbx_vec4 diffuse = mesh->materials.data[meshPart.index]->fbx.diffuse_color.value_vec4;
vertex.color.x = static_cast<float>(diffuse.x * factor);

View File

@@ -361,18 +361,20 @@ namespace BSP
{
cplane_s plane;
plane.dist = tree.node->distance;
if (tree.node->axis == AXIS_X)
if (tree.node->axis == PlaneAxis::AXIS_X)
{
plane.normal = normalX;
plane.type = 0;
}
else if (tree.node->axis == AXIS_Y)
else if (tree.node->axis == PlaneAxis::AXIS_Y)
{
plane.normal = normalY;
plane.type = 1;
}
else // tree->node->axis == AXIS_Z
else
{
assert(tree.node->axis == PlaneAxis::AXIS_Z);
plane.normal = normalZ;
plane.type = 2;
}

View File

@@ -81,7 +81,7 @@ namespace BSP
gfxSurface->tris.vertexDataOffset1 = 0;
std::string surfMaterialName;
if (bspSurface.material.materialType == MATERIAL_TYPE_TEXTURE)
if (bspSurface.material.materialType == BSPMaterialType::MATERIAL_TYPE_TEXTURE)
surfMaterialName = bspSurface.material.materialName;
else // MATERIAL_TYPE_COLOUR || MATERIAL_TYPE_EMPTY
surfMaterialName = BSPLinkingConstants::COLOR_ONLY_IMAGE_NAME;
@@ -200,9 +200,9 @@ namespace BSP
currModelInst->maxs.z = currModel->model->maxs.z + currModel->placement.origin.z;
currModel->cullDist = DEFAULT_SMODEL_CULL_DIST;
currModel->flags = DEFAULT_SMODEL_FLAGS;
currModel->primaryLightIndex = DEFAULT_SMODEL_LIGHT;
currModel->reflectionProbeIndex = DEFAULT_SMODEL_REFLECTION_PROBE;
currModel->flags = BSPEditableConstants::DEFAULT_SMODEL_FLAGS;
currModel->primaryLightIndex = BSPEditableConstants::DEFAULT_SMODEL_LIGHT;
currModel->reflectionProbeIndex = BSPEditableConstants::DEFAULT_SMODEL_REFLECTION_PROBE;
// unknown use / unused
currModel->smid = i;