chore: use const and reference whenever possible

This commit is contained in:
Jan Laupetin committed 2025-11-10 21:45:52 +01:00
1 parent 08a8a5cd07
commit e9e0c7f511
21 files changed
+657 -648

No files matched your search

+15 -14
View File
@@ -4,7 +4,8 @@ namespace BSP
{
constexpr int MAX_NODE_SIZE = 512; // maximum size a BSP node can be before it becomes a leaf
BSPObject::BSPObject(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax, int objPartitionIndex)
BSPObject::BSPObject(
const float xMin, const float yMin, const float zMin, const float xMax, const float yMax, const float zMax, const int objPartitionIndex)
{
min.x = xMin;
min.y = yMin;
@@ -20,17 +21,17 @@ namespace BSP
objectList.emplace_back(std::move(object));
}
BSPObject* BSPLeaf::getObject(size_t index)
BSPObject* BSPLeaf::getObject(const size_t index) const
{
return objectList.at(index).get();
}
size_t BSPLeaf::getObjectCount()
size_t BSPLeaf::getObjectCount() const
{
return objectList.size();
}
BSPNode::BSPNode(std::unique_ptr<BSPTree> frontTree, std::unique_ptr<BSPTree> backTree, PlaneAxis nodeAxis, float nodeDistance)
BSPNode::BSPNode(std::unique_ptr<BSPTree> frontTree, std::unique_ptr<BSPTree> backTree, const PlaneAxis nodeAxis, const float nodeDistance)
{
front = std::move(frontTree);
back = std::move(backTree);
@@ -38,25 +39,25 @@ namespace BSP
distance = nodeDistance;
}
PlaneSide BSPNode::objectIsInFront(BSPObject* object)
PlaneSide BSPNode::objectIsInFront(const BSPObject& object) const
{
float minCoord, maxCoord;
// Select the relevant coordinate based on the plane's axis
if (axis == AXIS_X)
{
minCoord = object->min.x;
maxCoord = object->max.x;
minCoord = object.min.x;
maxCoord = object.max.x;
}
else if (axis == AXIS_Y)
{
minCoord = object->min.y;
maxCoord = object->max.y;
minCoord = object.min.y;
maxCoord = object.max.y;
}
else // axis == AXIS_Z
{
minCoord = object->min.z;
maxCoord = object->max.z;
minCoord = object.min.z;
maxCoord = object.max.z;
}
// Compare with the plane's distance
@@ -74,7 +75,7 @@ namespace BSP
}
}
BSPTree::BSPTree(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax, int treeLevel)
BSPTree::BSPTree(const float xMin, const float yMin, const float zMin, const float xMax, const float yMax, const float zMax, const int treeLevel)
{
min.x = xMin;
min.y = yMin;
@@ -133,7 +134,7 @@ namespace BSP
}
}
void BSPTree::addObjectToTree(std::shared_ptr<BSPObject> object)
void BSPTree::addObjectToTree(std::shared_ptr<BSPObject> object) const
{
if (isLeaf)
{
@@ -141,7 +142,7 @@ namespace BSP
}
else
{
PlaneSide side = node->objectIsInFront(object.get());
const PlaneSide side = node->objectIsInFront(*object);
if (side == SIDE_FRONT)
{
node->front->addObjectToTree(std::move(object));
+4 -4
View File
@@ -34,8 +34,8 @@ namespace BSP
std::vector<std::shared_ptr<BSPObject>> objectList;
void addObject(std::shared_ptr<BSPObject> object);
BSPObject* getObject(size_t index);
size_t getObjectCount();
BSPObject* getObject(size_t index) const;
size_t getObjectCount() const;
};
class BSPTree;
@@ -50,7 +50,7 @@ namespace BSP
float distance; // distance from the origin (0, 0, 0) to the plane
BSPNode(std::unique_ptr<BSPTree> frontTree, std::unique_ptr<BSPTree> backTree, PlaneAxis nodeAxis, float nodeDistance);
PlaneSide objectIsInFront(BSPObject* object);
PlaneSide objectIsInFront(const BSPObject& object) const;
};
class BSPTree
@@ -66,6 +66,6 @@ namespace BSP
BSPTree(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax, int treeLevel);
void splitTree();
void addObjectToTree(std::shared_ptr<BSPObject> object);
void addObjectToTree(std::shared_ptr<BSPObject> object) const;
};
} // namespace BSP
+9 -9
View File
@@ -170,17 +170,17 @@ namespace
}
}
void loadWorldData(ufbx_scene* scene, BSPData* bsp, bool isGfxData)
void loadWorldData(const ufbx_scene& scene, BSPData& bsp, const bool isGfxData)
{
bool hasTangentSpace = true;
for (ufbx_node* node : scene->nodes)
for (ufbx_node* node : scene.nodes)
{
if (node->attrib_type == UFBX_ELEMENT_MESH)
{
if (isGfxData)
addFBXMeshToWorld(node, bsp->gfxWorld.surfaces, bsp->gfxWorld.vertices, bsp->gfxWorld.indices, hasTangentSpace);
addFBXMeshToWorld(node, bsp.gfxWorld.surfaces, bsp.gfxWorld.vertices, bsp.gfxWorld.indices, hasTangentSpace);
else
addFBXMeshToWorld(node, bsp->colWorld.surfaces, bsp->colWorld.vertices, bsp->colWorld.indices, hasTangentSpace);
addFBXMeshToWorld(node, bsp.colWorld.surfaces, bsp.colWorld.vertices, bsp.colWorld.indices, hasTangentSpace);
}
else
{
@@ -195,7 +195,7 @@ namespace
namespace BSP
{
std::unique_ptr<BSPData> createBSPData(std::string& mapName, ISearchPath& searchPath)
std::unique_ptr<BSPData> createBSPData(const std::string& mapName, ISearchPath& searchPath)
{
std::string gfxFbxFileName = "map_gfx.fbx";
std::string gfxFbxPath = BSPUtil::getFileNameForBSPAsset(gfxFbxFileName);
@@ -228,8 +228,8 @@ namespace BSP
ufbx_scene* colScene;
std::string colFbxFileName = "map_col.fbx";
std::string colFbxPath = BSPUtil::getFileNameForBSPAsset(colFbxFileName);
auto colFile = searchPath.Open(colFbxPath);
const auto colFbxPath = BSPUtil::getFileNameForBSPAsset(colFbxFileName);
const auto colFile = searchPath.Open(colFbxPath);
if (!colFile.IsOpen())
{
con::warn("Failed to open map collison fbx file: {}. map gfx will be used for collision instead.", colFbxPath);
@@ -264,8 +264,8 @@ namespace BSP
bsp->name = mapName;
bsp->bspName = "maps/mp/" + mapName + ".d3dbsp";
loadWorldData(gfxScene, bsp.get(), true);
loadWorldData(colScene, bsp.get(), false);
loadWorldData(*gfxScene, *bsp, true);
loadWorldData(*colScene, *bsp, false);
ufbx_free_scene(gfxScene);
if (gfxScene != colScene)
+1 -1
View File
@@ -5,5 +5,5 @@
namespace BSP
{
std::unique_ptr<BSPData> createBSPData(std::string& mapName, ISearchPath& searchPath);
std::unique_ptr<BSPData> createBSPData(const std::string& mapName, ISearchPath& searchPath);
}; // namespace BSP
+22 -21
View File
@@ -8,12 +8,12 @@ using namespace T6;
namespace BSP
{
std::string BSPUtil::getFileNameForBSPAsset(std::string& assetName)
std::string BSPUtil::getFileNameForBSPAsset(const std::string& assetName)
{
return std::format("BSP/{}", assetName);
}
vec3_t BSPUtil::convertToBO2Coords(vec3_t& coordinate)
vec3_t BSPUtil::convertToBO2Coords(const vec3_t& coordinate)
{
vec3_t result;
result.x = coordinate.x;
@@ -22,7 +22,7 @@ namespace BSP
return result;
}
vec3_t BSPUtil::convertFromBO2Coords(vec3_t& coordinate)
vec3_t BSPUtil::convertFromBO2Coords(const vec3_t& coordinate)
{
vec3_t result;
result.x = coordinate.x;
@@ -31,7 +31,7 @@ namespace BSP
return result;
}
void BSPUtil::updateAABB(vec3_t& newAABBMins, vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs)
void BSPUtil::updateAABB(const vec3_t& newAABBMins, const vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs)
{
AABBMins.x = std::min(AABBMins.x, newAABBMins.x);
AABBMaxs.x = std::max(AABBMaxs.x, newAABBMaxs.x);
@@ -43,7 +43,7 @@ namespace BSP
AABBMaxs.z = std::max(AABBMaxs.z, newAABBMaxs.z);
}
void BSPUtil::updateAABBWithPoint(vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs)
void BSPUtil::updateAABBWithPoint(const vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs)
{
AABBMins.x = std::min(AABBMins.x, point.x);
AABBMaxs.x = std::max(AABBMaxs.x, point.x);
@@ -55,7 +55,7 @@ namespace BSP
AABBMaxs.z = std::max(AABBMaxs.z, point.z);
}
vec3_t BSPUtil::calcMiddleOfAABB(vec3_t& mins, vec3_t& maxs)
vec3_t BSPUtil::calcMiddleOfAABB(const vec3_t& mins, const vec3_t& maxs)
{
vec3_t result;
result.x = (mins.x + maxs.x) * 0.5f;
@@ -64,7 +64,7 @@ namespace BSP
return result;
}
vec3_t BSPUtil::calcHalfSizeOfAABB(vec3_t& mins, vec3_t& maxs)
vec3_t BSPUtil::calcHalfSizeOfAABB(const vec3_t& mins, const vec3_t& maxs)
{
vec3_t result;
result.x = (maxs.x - mins.x) * 0.5f;
@@ -73,27 +73,28 @@ namespace BSP
return result;
}
float BSPUtil::distBetweenPoints(vec3_t& p1, vec3_t& p2)
float BSPUtil::distBetweenPoints(const vec3_t& p1, const vec3_t& p2)
{
float x = p2.x - p1.x;
float y = p2.y - p1.y;
float z = p2.z - p1.z;
const float x = p2.x - p1.x;
const float y = p2.y - p1.y;
const 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)
void BSPUtil::convertAnglesToAxis(const 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
const float xRadians = angles->x * 0.017453292f; // M_PI / 180.0f
const float yRadians = angles->y * 0.017453292f; // M_PI / 180.0f
const float zRadians = angles->z * 0.017453292f; // M_PI / 180.0f
float cosX = cos(xRadians);
float sinX = sin(xRadians);
float cosY = cos(yRadians);
float sinY = sin(yRadians);
float cosZ = cos(zRadians);
float sinZ = sin(zRadians);
const float cosX = cos(xRadians);
const float sinX = sin(xRadians);
const float cosY = cos(yRadians);
const float sinY = sin(yRadians);
const float cosZ = cos(zRadians);
const float sinZ = sin(zRadians);
axis[0].x = cosX * cosY;
axis[0].y = cosX * sinY;
+9 -9
View File
@@ -7,15 +7,15 @@ namespace BSP
class BSPUtil
{
public:
static std::string getFileNameForBSPAsset(std::string& assetName);
static T6::vec3_t convertToBO2Coords(T6::vec3_t& OGL_coordinate);
static T6::vec3_t convertFromBO2Coords(T6::vec3_t& bo2_coordinate);
static void updateAABB(T6::vec3_t& newAABBMins, T6::vec3_t& newAABBMaxs, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static void updateAABBWithPoint(T6::vec3_t& point, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static T6::vec3_t calcMiddleOfAABB(T6::vec3_t& mins, T6::vec3_t& maxs);
static T6::vec3_t calcHalfSizeOfAABB(T6::vec3_t& mins, T6::vec3_t& maxs);
static float distBetweenPoints(T6::vec3_t& p1, T6::vec3_t& p2);
static void convertAnglesToAxis(T6::vec3_t* angles, T6::vec3_t* axis);
static std::string getFileNameForBSPAsset(const std::string& assetName);
static T6::vec3_t convertToBO2Coords(const T6::vec3_t& OGL_coordinate);
static T6::vec3_t convertFromBO2Coords(const T6::vec3_t& bo2_coordinate);
static void updateAABB(const T6::vec3_t& newAABBMins, const T6::vec3_t& newAABBMaxs, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static void updateAABBWithPoint(const T6::vec3_t& point, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static T6::vec3_t calcMiddleOfAABB(const T6::vec3_t& mins, const T6::vec3_t& maxs);
static T6::vec3_t calcHalfSizeOfAABB(const T6::vec3_t& mins, const T6::vec3_t& maxs);
static float distBetweenPoints(const T6::vec3_t& p1, const T6::vec3_t& p2);
static void convertAnglesToAxis(const T6::vec3_t* angles, T6::vec3_t* axis);
static void matrixTranspose3x3(const T6::vec3_t* in, T6::vec3_t* out);
};
} // namespace BSP
@@ -11,7 +11,7 @@ using namespace T6;
namespace BSP
{
FootstepTableDef* BSPLinker::addEmptyFootstepTableAsset(std::string assetName)
FootstepTableDef* BSPLinker::addEmptyFootstepTableAsset(const std::string& assetName) const
{
if (assetName.length() == 0)
return nullptr;
@@ -25,20 +25,20 @@ namespace BSP
return footstepTable;
}
bool BSPLinker::addDefaultRequiredAssets(BSPData* bsp)
bool BSPLinker::addDefaultRequiredAssets(const BSPData& bsp) const
{
if (m_context.LoadDependency<AssetScript>("maps/mp/" + bsp->name + ".gsc") == nullptr)
if (m_context.LoadDependency<AssetScript>("maps/mp/" + bsp.name + ".gsc") == nullptr)
return false;
if (m_context.LoadDependency<AssetScript>("maps/mp/" + bsp->name + "_amb.gsc") == nullptr)
if (m_context.LoadDependency<AssetScript>("maps/mp/" + bsp.name + "_amb.gsc") == nullptr)
return false;
if (m_context.LoadDependency<AssetScript>("maps/mp/" + bsp->name + "_fx.gsc") == nullptr)
if (m_context.LoadDependency<AssetScript>("maps/mp/" + bsp.name + "_fx.gsc") == nullptr)
return false;
if (m_context.LoadDependency<AssetScript>("clientscripts/mp/" + bsp->name + ".csc") == nullptr)
if (m_context.LoadDependency<AssetScript>("clientscripts/mp/" + bsp.name + ".csc") == nullptr)
return false;
if (m_context.LoadDependency<AssetScript>("clientscripts/mp/" + bsp->name + "_amb.csc") == nullptr)
if (m_context.LoadDependency<AssetScript>("clientscripts/mp/" + bsp.name + "_amb.csc") == nullptr)
return false;
if (m_context.LoadDependency<AssetScript>("clientscripts/mp/" + bsp->name + "_fx.csc") == nullptr)
if (m_context.LoadDependency<AssetScript>("clientscripts/mp/" + bsp.name + "_fx.csc") == nullptr)
return false;
addEmptyFootstepTableAsset("default_1st_person");
@@ -61,7 +61,7 @@ namespace BSP
{
}
bool BSPLinker::linkBSP(BSPData* bsp)
bool BSPLinker::linkBSP(const BSPData& bsp) const
{
if (!addDefaultRequiredAssets(bsp))
return false;
@@ -11,11 +11,12 @@ namespace BSP
{
public:
BSPLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
bool linkBSP(BSPData* bsp);
bool linkBSP(const BSPData& bsp) const;
private:
T6::FootstepTableDef* addEmptyFootstepTableAsset(std::string assetName);
bool addDefaultRequiredAssets(BSPData* bsp);
T6::FootstepTableDef* addEmptyFootstepTableAsset(const std::string& assetName) const;
bool addDefaultRequiredAssets(const BSPData& bsp) const;
MemoryManager& m_memory;
ISearchPath& m_search_path;
@@ -2,6 +2,8 @@
#include "Game/T6/BSP/BSPUtil.h"
#include <cassert>
using namespace T6;
namespace BSP
@@ -13,45 +15,45 @@ namespace BSP
{
}
void ClipMapLinker::loadDynEnts(clipMap_t* clipMap)
void ClipMapLinker::loadDynEnts(clipMap_t& clipMap) const
{
int dynEntCount = 0;
clipMap->originalDynEntCount = dynEntCount;
clipMap->dynEntCount[0] = clipMap->originalDynEntCount + 256; // the game allocs 256 empty dynents, as they may be used ingame
clipMap->dynEntCount[1] = 0;
clipMap->dynEntCount[2] = 0;
clipMap->dynEntCount[3] = 0;
clipMap.originalDynEntCount = dynEntCount;
clipMap.dynEntCount[0] = clipMap.originalDynEntCount + 256; // the game allocs 256 empty dynents, as they may be used ingame
clipMap.dynEntCount[1] = 0;
clipMap.dynEntCount[2] = 0;
clipMap.dynEntCount[3] = 0;
clipMap->dynEntClientList[0] = m_memory.Alloc<DynEntityClient>(clipMap->dynEntCount[0]);
clipMap->dynEntClientList[1] = nullptr;
clipMap.dynEntClientList[0] = m_memory.Alloc<DynEntityClient>(clipMap.dynEntCount[0]);
clipMap.dynEntClientList[1] = nullptr;
clipMap->dynEntServerList[0] = nullptr;
clipMap->dynEntServerList[1] = nullptr;
clipMap.dynEntServerList[0] = nullptr;
clipMap.dynEntServerList[1] = nullptr;
clipMap->dynEntCollList[0] = m_memory.Alloc<DynEntityColl>(clipMap->dynEntCount[0]);
clipMap->dynEntCollList[1] = nullptr;
clipMap->dynEntCollList[2] = nullptr;
clipMap->dynEntCollList[3] = nullptr;
clipMap.dynEntCollList[0] = m_memory.Alloc<DynEntityColl>(clipMap.dynEntCount[0]);
clipMap.dynEntCollList[1] = nullptr;
clipMap.dynEntCollList[2] = nullptr;
clipMap.dynEntCollList[3] = nullptr;
clipMap->dynEntPoseList[0] = m_memory.Alloc<DynEntityPose>(clipMap->dynEntCount[0]);
clipMap->dynEntPoseList[1] = nullptr;
clipMap.dynEntPoseList[0] = m_memory.Alloc<DynEntityPose>(clipMap.dynEntCount[0]);
clipMap.dynEntPoseList[1] = nullptr;
clipMap->dynEntDefList[0] = m_memory.Alloc<DynEntityDef>(clipMap->dynEntCount[0]);
clipMap->dynEntDefList[1] = nullptr;
clipMap.dynEntDefList[0] = m_memory.Alloc<DynEntityDef>(clipMap.dynEntCount[0]);
clipMap.dynEntDefList[1] = nullptr;
}
void ClipMapLinker::loadVisibility(clipMap_t* clipMap)
void ClipMapLinker::loadVisibility(clipMap_t& clipMap) const
{
// Only use one visbility cluster for the entire map
clipMap->numClusters = 1;
clipMap->vised = 0;
clipMap->clusterBytes = ((clipMap->numClusters + 63) >> 3) & 0xFFFFFFF8;
clipMap->visibility = m_memory.Alloc<char>(clipMap->clusterBytes);
clipMap.numClusters = 1;
clipMap.vised = 0;
clipMap.clusterBytes = ((clipMap.numClusters + 63) >> 3) & 0xFFFFFFF8;
clipMap.visibility = m_memory.Alloc<char>(clipMap.clusterBytes);
// Official maps set visibility to all 0xFF
memset(clipMap->visibility, 0xFF, clipMap->clusterBytes);
memset(clipMap.visibility, 0xFF, clipMap.clusterBytes);
}
void ClipMapLinker::loadBoxData(clipMap_t* clipMap)
void ClipMapLinker::loadBoxData(clipMap_t& clipMap) const
{
// box_model and box_brush are what are used by game traces as "temporary" collision when
// no brush or model is specified to do the trace with.
@@ -64,108 +66,108 @@ namespace BSP
// so we use the hex representation and set it using int pointers.
unsigned int box_mins = 0x7F7FFFFF;
unsigned int box_maxs = 0xFF7FFFFF;
*(reinterpret_cast<unsigned int*>(&clipMap->box_model.leaf.mins.x)) = box_mins;
*(reinterpret_cast<unsigned int*>(&clipMap->box_model.leaf.mins.y)) = box_mins;
*(reinterpret_cast<unsigned int*>(&clipMap->box_model.leaf.mins.z)) = box_mins;
*(reinterpret_cast<unsigned int*>(&clipMap->box_model.leaf.maxs.x)) = box_maxs;
*(reinterpret_cast<unsigned int*>(&clipMap->box_model.leaf.maxs.y)) = box_maxs;
*(reinterpret_cast<unsigned int*>(&clipMap->box_model.leaf.maxs.z)) = box_maxs;
*(reinterpret_cast<unsigned int*>(&clipMap.box_model.leaf.mins.x)) = box_mins;
*(reinterpret_cast<unsigned int*>(&clipMap.box_model.leaf.mins.y)) = box_mins;
*(reinterpret_cast<unsigned int*>(&clipMap.box_model.leaf.mins.z)) = box_mins;
*(reinterpret_cast<unsigned int*>(&clipMap.box_model.leaf.maxs.x)) = box_maxs;
*(reinterpret_cast<unsigned int*>(&clipMap.box_model.leaf.maxs.y)) = box_maxs;
*(reinterpret_cast<unsigned int*>(&clipMap.box_model.leaf.maxs.z)) = box_maxs;
clipMap->box_model.leaf.brushContents = -1;
clipMap->box_model.leaf.terrainContents = 0;
clipMap->box_model.leaf.cluster = 0;
clipMap->box_model.leaf.collAabbCount = 0;
clipMap->box_model.leaf.firstCollAabbIndex = 0;
clipMap->box_model.leaf.leafBrushNode = 0;
clipMap->box_model.mins.x = 0.0f;
clipMap->box_model.mins.y = 0.0f;
clipMap->box_model.mins.z = 0.0f;
clipMap->box_model.maxs.x = 0.0f;
clipMap->box_model.maxs.y = 0.0f;
clipMap->box_model.maxs.z = 0.0f;
clipMap->box_model.radius = 0.0f;
clipMap->box_model.info = nullptr;
clipMap.box_model.leaf.brushContents = -1;
clipMap.box_model.leaf.terrainContents = 0;
clipMap.box_model.leaf.cluster = 0;
clipMap.box_model.leaf.collAabbCount = 0;
clipMap.box_model.leaf.firstCollAabbIndex = 0;
clipMap.box_model.leaf.leafBrushNode = 0;
clipMap.box_model.mins.x = 0.0f;
clipMap.box_model.mins.y = 0.0f;
clipMap.box_model.mins.z = 0.0f;
clipMap.box_model.maxs.x = 0.0f;
clipMap.box_model.maxs.y = 0.0f;
clipMap.box_model.maxs.z = 0.0f;
clipMap.box_model.radius = 0.0f;
clipMap.box_model.info = nullptr;
clipMap->box_brush = m_memory.Alloc<cbrush_t>();
clipMap->box_brush->axial_sflags[0][0] = -1;
clipMap->box_brush->axial_sflags[0][1] = -1;
clipMap->box_brush->axial_sflags[0][2] = -1;
clipMap->box_brush->axial_sflags[1][0] = -1;
clipMap->box_brush->axial_sflags[1][1] = -1;
clipMap->box_brush->axial_sflags[1][2] = -1;
clipMap->box_brush->axial_cflags[0][0] = -1;
clipMap->box_brush->axial_cflags[0][1] = -1;
clipMap->box_brush->axial_cflags[0][2] = -1;
clipMap->box_brush->axial_cflags[1][0] = -1;
clipMap->box_brush->axial_cflags[1][1] = -1;
clipMap->box_brush->axial_cflags[1][2] = -1;
clipMap->box_brush->contents = -1;
clipMap->box_brush->mins.x = 0.0f;
clipMap->box_brush->mins.y = 0.0f;
clipMap->box_brush->mins.z = 0.0f;
clipMap->box_brush->maxs.x = 0.0f;
clipMap->box_brush->maxs.y = 0.0f;
clipMap->box_brush->maxs.z = 0.0f;
clipMap->box_brush->numsides = 0;
clipMap->box_brush->numverts = 0;
clipMap->box_brush->sides = nullptr;
clipMap->box_brush->verts = nullptr;
clipMap.box_brush = m_memory.Alloc<cbrush_t>();
clipMap.box_brush->axial_sflags[0][0] = -1;
clipMap.box_brush->axial_sflags[0][1] = -1;
clipMap.box_brush->axial_sflags[0][2] = -1;
clipMap.box_brush->axial_sflags[1][0] = -1;
clipMap.box_brush->axial_sflags[1][1] = -1;
clipMap.box_brush->axial_sflags[1][2] = -1;
clipMap.box_brush->axial_cflags[0][0] = -1;
clipMap.box_brush->axial_cflags[0][1] = -1;
clipMap.box_brush->axial_cflags[0][2] = -1;
clipMap.box_brush->axial_cflags[1][0] = -1;
clipMap.box_brush->axial_cflags[1][1] = -1;
clipMap.box_brush->axial_cflags[1][2] = -1;
clipMap.box_brush->contents = -1;
clipMap.box_brush->mins.x = 0.0f;
clipMap.box_brush->mins.y = 0.0f;
clipMap.box_brush->mins.z = 0.0f;
clipMap.box_brush->maxs.x = 0.0f;
clipMap.box_brush->maxs.y = 0.0f;
clipMap.box_brush->maxs.z = 0.0f;
clipMap.box_brush->numsides = 0;
clipMap.box_brush->numverts = 0;
clipMap.box_brush->sides = nullptr;
clipMap.box_brush->verts = nullptr;
}
void ClipMapLinker::loadRopesAndConstraints(clipMap_t* clipMap)
void ClipMapLinker::loadRopesAndConstraints(clipMap_t& clipMap) const
{
clipMap->num_constraints = 0; // max 511
clipMap->constraints = nullptr;
clipMap.num_constraints = 0; // max 511
clipMap.constraints = nullptr;
// The game allocates 32 empty ropes
clipMap->max_ropes = 32; // max 300
clipMap->ropes = m_memory.Alloc<rope_t>(clipMap->max_ropes);
clipMap.max_ropes = 32; // max 300
clipMap.ropes = m_memory.Alloc<rope_t>(clipMap.max_ropes);
}
void ClipMapLinker::loadSubModelCollision(clipMap_t* clipMap, BSPData* bsp)
void ClipMapLinker::loadSubModelCollision(clipMap_t& clipMap, const BSPData& bsp) const
{
// Submodels are used for the world and map ent collision (triggers, bomb zones, etc)
auto gfxWorldAsset = m_context.LoadDependency<AssetGfxWorld>(bsp->bspName);
auto gfxWorldAsset = m_context.LoadDependency<AssetGfxWorld>(bsp.bspName);
assert(gfxWorldAsset != nullptr);
GfxWorld* gfxWorld = gfxWorldAsset->Asset();
// Right now there is only one submodel, the world sub model
assert(gfxWorld->modelCount == 1);
clipMap->numSubModels = 1;
clipMap->cmodels = m_memory.Alloc<cmodel_t>(clipMap->numSubModels);
clipMap.numSubModels = 1;
clipMap.cmodels = m_memory.Alloc<cmodel_t>(clipMap.numSubModels);
GfxBrushModel* gfxModel = &gfxWorld->models[0];
clipMap->cmodels[0].mins.x = gfxModel->bounds[0].x;
clipMap->cmodels[0].mins.y = gfxModel->bounds[0].y;
clipMap->cmodels[0].mins.z = gfxModel->bounds[0].z;
clipMap->cmodels[0].maxs.x = gfxModel->bounds[1].x;
clipMap->cmodels[0].maxs.y = gfxModel->bounds[1].y;
clipMap->cmodels[0].maxs.z = gfxModel->bounds[1].z;
clipMap->cmodels[0].radius = BSPUtil::distBetweenPoints(clipMap->cmodels[0].mins, clipMap->cmodels[0].maxs) / 2;
clipMap.cmodels[0].mins.x = gfxModel->bounds[0].x;
clipMap.cmodels[0].mins.y = gfxModel->bounds[0].y;
clipMap.cmodels[0].mins.z = gfxModel->bounds[0].z;
clipMap.cmodels[0].maxs.x = gfxModel->bounds[1].x;
clipMap.cmodels[0].maxs.y = gfxModel->bounds[1].y;
clipMap.cmodels[0].maxs.z = gfxModel->bounds[1].z;
clipMap.cmodels[0].radius = BSPUtil::distBetweenPoints(clipMap.cmodels[0].mins, clipMap.cmodels[0].maxs) / 2;
// The world sub model has no leafs associated with it
clipMap->cmodels[0].leaf.firstCollAabbIndex = 0;
clipMap->cmodels[0].leaf.collAabbCount = 0;
clipMap->cmodels[0].leaf.brushContents = 0;
clipMap->cmodels[0].leaf.terrainContents = 0;
clipMap->cmodels[0].leaf.mins.x = 0.0f;
clipMap->cmodels[0].leaf.mins.y = 0.0f;
clipMap->cmodels[0].leaf.mins.z = 0.0f;
clipMap->cmodels[0].leaf.maxs.x = 0.0f;
clipMap->cmodels[0].leaf.maxs.y = 0.0f;
clipMap->cmodels[0].leaf.maxs.z = 0.0f;
clipMap->cmodels[0].leaf.leafBrushNode = 0;
clipMap->cmodels[0].leaf.cluster = 0;
clipMap.cmodels[0].leaf.firstCollAabbIndex = 0;
clipMap.cmodels[0].leaf.collAabbCount = 0;
clipMap.cmodels[0].leaf.brushContents = 0;
clipMap.cmodels[0].leaf.terrainContents = 0;
clipMap.cmodels[0].leaf.mins.x = 0.0f;
clipMap.cmodels[0].leaf.mins.y = 0.0f;
clipMap.cmodels[0].leaf.mins.z = 0.0f;
clipMap.cmodels[0].leaf.maxs.x = 0.0f;
clipMap.cmodels[0].leaf.maxs.y = 0.0f;
clipMap.cmodels[0].leaf.maxs.z = 0.0f;
clipMap.cmodels[0].leaf.leafBrushNode = 0;
clipMap.cmodels[0].leaf.cluster = 0;
clipMap->cmodels[0].info = nullptr; // always set to 0
clipMap.cmodels[0].info = nullptr; // always set to 0
}
void ClipMapLinker::loadXModelCollision(clipMap_t* clipMap)
void ClipMapLinker::loadXModelCollision(clipMap_t& clipMap) const
{
// Right now XModels aren't supported
clipMap->numStaticModels = 0;
clipMap->staticModelList = nullptr;
clipMap.numStaticModels = 0;
clipMap.staticModelList = nullptr;
// WIP code left in for future support
/*
@@ -211,11 +213,11 @@ namespace BSP
*/
}
void ClipMapLinker::addAABBTreeFromLeaf(clipMap_t* clipMap, BSPTree* tree, size_t* out_parentCount, size_t* out_parentStartIndex)
void ClipMapLinker::addAABBTreeFromLeaf(clipMap_t& clipMap, const BSPTree& tree, size_t& outParentCount, size_t& outParentStartIndex)
{
assert(tree->isLeaf);
assert(tree.isLeaf);
size_t leafObjectCount = tree->leaf->getObjectCount();
size_t leafObjectCount = tree.leaf->getObjectCount();
assert(leafObjectCount > 0);
highestLeafObjectCount = std::max(leafObjectCount, highestLeafObjectCount);
@@ -244,12 +246,12 @@ namespace BSP
vec3_t parentMaxs;
for (size_t objectIdx = 0; objectIdx < childObjectCount; objectIdx++)
{
int partitionIndex = tree->leaf->getObject(addedObjectCount + objectIdx)->partitionIndex;
CollisionPartition* partition = &clipMap->partitions[partitionIndex];
int partitionIndex = tree.leaf->getObject(addedObjectCount + objectIdx)->partitionIndex;
CollisionPartition* partition = &clipMap.partitions[partitionIndex];
for (int uindIdx = 0; uindIdx < partition->nuinds; uindIdx++)
{
uint16_t uind = clipMap->info.uinds[partition->fuind + uindIdx];
vec3_t vert = clipMap->verts[uind];
uint16_t uind = clipMap.info.uinds[partition->fuind + uindIdx];
vec3_t vert = clipMap.verts[uind];
// initalise the parent AABB with the first vertex
if (objectIdx == 0 && uindIdx == 0)
@@ -274,14 +276,14 @@ namespace BSP
// add child AABBs
for (size_t objectIdx = 0; objectIdx < childObjectCount; objectIdx++)
{
int partitionIndex = tree->leaf->getObject(addedObjectCount + objectIdx)->partitionIndex;
CollisionPartition* partition = &clipMap->partitions[partitionIndex];
int partitionIndex = tree.leaf->getObject(addedObjectCount + objectIdx)->partitionIndex;
CollisionPartition* partition = &clipMap.partitions[partitionIndex];
vec3_t childMins;
vec3_t childMaxs;
for (int uindIdx = 0; uindIdx < partition->nuinds; uindIdx++)
{
uint16_t uind = clipMap->info.uinds[partition->fuind + uindIdx];
vec3_t vert = clipMap->verts[uind];
uint16_t uind = clipMap.info.uinds[partition->fuind + uindIdx];
vec3_t vert = clipMap.verts[uind];
// initalise the child AABB with the first vertex
if (uindIdx == 0)
@@ -305,8 +307,8 @@ namespace BSP
addedObjectCount += childObjectCount;
}
*out_parentCount = parentCount;
*out_parentStartIndex = parentAABBArrayIndex;
outParentCount = parentCount;
outParentStartIndex = parentAABBArrayIndex;
}
constexpr vec3_t normalX = {1.0f, 0.0f, 0.0f};
@@ -317,9 +319,9 @@ namespace BSP
// Nodes are indexed by their index in the node array
// Leafs are indexed by (-1 - <leaf index>)
// See https://developer.valvesoftware.com/wiki/BSP_(Source)
int16_t ClipMapLinker::loadBSPNode(clipMap_t* clipMap, BSPTree* tree)
int16_t ClipMapLinker::loadBSPNode(clipMap_t& clipMap, const BSPTree& tree)
{
if (tree->isLeaf)
if (tree.isLeaf)
{
cLeaf_s leaf;
@@ -336,11 +338,11 @@ namespace BSP
leaf.maxs.z = 0.0f;
leaf.leafBrushNode = 0;
if (tree->leaf->getObjectCount() > 0)
if (tree.leaf->getObjectCount() > 0)
{
size_t parentCount = 0;
size_t parentStartIndex = 0;
addAABBTreeFromLeaf(clipMap, tree, &parentCount, &parentStartIndex);
addAABBTreeFromLeaf(clipMap, tree, parentCount, parentStartIndex);
leaf.collAabbCount = static_cast<uint16_t>(parentCount);
leaf.firstCollAabbIndex = static_cast<uint16_t>(parentStartIndex);
}
@@ -358,13 +360,13 @@ namespace BSP
else
{
cplane_s plane;
plane.dist = tree->node->distance;
if (tree->node->axis == AXIS_X)
plane.dist = tree.node->distance;
if (tree.node->axis == AXIS_X)
{
plane.normal = normalX;
plane.type = 0;
}
else if (tree->node->axis == AXIS_Y)
else if (tree.node->axis == AXIS_Y)
{
plane.normal = normalY;
plane.type = 1;
@@ -394,8 +396,8 @@ namespace BSP
cNode_t node;
node.plane = nullptr; // initalised after the BSP tree has been loaded
node.children[0] = loadBSPNode(clipMap, tree->node->front.get());
node.children[1] = loadBSPNode(clipMap, tree->node->back.get());
node.children[0] = loadBSPNode(clipMap, *tree.node->front);
node.children[1] = loadBSPNode(clipMap, *tree.node->back);
nodeVec.at(nodeIndex) = node;
@@ -403,13 +405,13 @@ namespace BSP
}
}
void ClipMapLinker::loadBSPTree(clipMap_t* clipMap, BSPData* bsp)
void ClipMapLinker::loadBSPTree(clipMap_t& clipMap, const BSPData& bsp)
{
vec3_t worldMins;
vec3_t worldMaxs;
for (unsigned int vertIdx = 0; vertIdx < clipMap->vertCount; vertIdx++)
for (unsigned int vertIdx = 0; vertIdx < clipMap.vertCount; vertIdx++)
{
vec3_t vertex = clipMap->verts[vertIdx];
vec3_t vertex = clipMap.verts[vertIdx];
// initalise AABB with the first vertex
if (vertIdx == 0)
{
@@ -421,15 +423,15 @@ namespace BSP
std::unique_ptr<BSPTree> tree = std::make_unique<BSPTree>(worldMins.x, worldMins.y, worldMins.z, worldMaxs.x, worldMaxs.y, worldMaxs.z, 0);
assert(!tree->isLeaf);
for (int partitionIdx = 0; partitionIdx < clipMap->partitionCount; partitionIdx++)
for (int partitionIdx = 0; partitionIdx < clipMap.partitionCount; partitionIdx++)
{
vec3_t partitionMins;
vec3_t partitionMaxs;
CollisionPartition* partition = &clipMap->partitions[partitionIdx];
CollisionPartition* partition = &clipMap.partitions[partitionIdx];
for (int uindIdx = 0; uindIdx < partition->nuinds; uindIdx++)
{
uint16_t uind = clipMap->info.uinds[partition->fuind + uindIdx];
vec3_t vert = clipMap->verts[uind];
uint16_t uind = clipMap.info.uinds[partition->fuind + uindIdx];
vec3_t vert = clipMap.verts[uind];
// initalise the AABB with the first vertex
if (uindIdx == 0)
{
@@ -444,74 +446,74 @@ namespace BSP
}
// load planes, nodes, leafs, and AABB trees
loadBSPNode(clipMap, tree.get());
loadBSPNode(clipMap, *tree);
clipMap->info.planeCount = static_cast<int>(planeVec.size());
clipMap->info.planes = m_memory.Alloc<cplane_s>(planeVec.size());
memcpy(clipMap->info.planes, planeVec.data(), sizeof(cplane_s) * planeVec.size());
clipMap.info.planeCount = static_cast<int>(planeVec.size());
clipMap.info.planes = m_memory.Alloc<cplane_s>(planeVec.size());
memcpy(clipMap.info.planes, planeVec.data(), sizeof(cplane_s) * planeVec.size());
clipMap->numNodes = static_cast<unsigned int>(nodeVec.size());
clipMap->nodes = m_memory.Alloc<cNode_t>(nodeVec.size());
memcpy(clipMap->nodes, nodeVec.data(), sizeof(cNode_t) * nodeVec.size());
clipMap.numNodes = static_cast<unsigned int>(nodeVec.size());
clipMap.nodes = m_memory.Alloc<cNode_t>(nodeVec.size());
memcpy(clipMap.nodes, nodeVec.data(), sizeof(cNode_t) * nodeVec.size());
clipMap->numLeafs = static_cast<unsigned int>(leafVec.size());
clipMap->leafs = m_memory.Alloc<cLeaf_s>(leafVec.size());
memcpy(clipMap->leafs, leafVec.data(), sizeof(cLeaf_s) * leafVec.size());
clipMap.numLeafs = static_cast<unsigned int>(leafVec.size());
clipMap.leafs = m_memory.Alloc<cLeaf_s>(leafVec.size());
memcpy(clipMap.leafs, leafVec.data(), sizeof(cLeaf_s) * leafVec.size());
clipMap->aabbTreeCount = static_cast<unsigned int>(AABBTreeVec.size());
clipMap->aabbTrees = m_memory.Alloc<CollisionAabbTree>(AABBTreeVec.size());
memcpy(clipMap->aabbTrees, AABBTreeVec.data(), sizeof(CollisionAabbTree) * AABBTreeVec.size());
clipMap.aabbTreeCount = static_cast<unsigned int>(AABBTreeVec.size());
clipMap.aabbTrees = m_memory.Alloc<CollisionAabbTree>(AABBTreeVec.size());
memcpy(clipMap.aabbTrees, AABBTreeVec.data(), sizeof(CollisionAabbTree) * AABBTreeVec.size());
// The plane of each node have the same index
for (size_t nodeIdx = 0; nodeIdx < nodeVec.size(); nodeIdx++)
clipMap->nodes[nodeIdx].plane = &clipMap->info.planes[nodeIdx];
clipMap.nodes[nodeIdx].plane = &clipMap.info.planes[nodeIdx];
con::info("Highest leaf object count: {}", highestLeafObjectCount);
}
bool ClipMapLinker::loadPartitions(clipMap_t* clipMap, BSPData* bsp)
bool ClipMapLinker::loadPartitions(clipMap_t& clipMap, const BSPData& bsp) const
{
// due to tris using uint16_t as the type for indexing the vert array,
// any vertex count over the uint16_t max means the vertices above the uint16_t max can't be indexed
if (static_cast<unsigned int>(bsp->colWorld.vertices.size()) > BSPGameConstants::MAX_COLLISION_VERTS)
if (static_cast<unsigned int>(bsp.colWorld.vertices.size()) > BSPGameConstants::MAX_COLLISION_VERTS)
{
con::error("ERROR: collision vertex count %i exceeds the maximum number: %i!\n", clipMap->vertCount, BSPGameConstants::MAX_COLLISION_VERTS);
con::error("ERROR: collision vertex count %i exceeds the maximum number: %i!\n", clipMap.vertCount, BSPGameConstants::MAX_COLLISION_VERTS);
return false;
}
clipMap->vertCount = static_cast<unsigned int>(bsp->colWorld.vertices.size());
clipMap->verts = m_memory.Alloc<vec3_t>(clipMap->vertCount);
for (unsigned int vertIdx = 0; vertIdx < clipMap->vertCount; vertIdx++)
clipMap->verts[vertIdx] = bsp->colWorld.vertices[vertIdx].pos;
clipMap.vertCount = static_cast<unsigned int>(bsp.colWorld.vertices.size());
clipMap.verts = m_memory.Alloc<vec3_t>(clipMap.vertCount);
for (unsigned int vertIdx = 0; vertIdx < clipMap.vertCount; vertIdx++)
clipMap.verts[vertIdx] = bsp.colWorld.vertices[vertIdx].pos;
// 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)
for (const BSPSurface& surface : bsp.colWorld.surfaces)
{
int indexOfFirstIndex = surface.indexOfFirstIndex;
int indexOfFirstVertex = surface.indexOfFirstVertex;
const int indexOfFirstIndex = surface.indexOfFirstIndex;
const int indexOfFirstVertex = surface.indexOfFirstVertex;
for (int indexIdx = 0; indexIdx < surface.triCount * 3; indexIdx++)
{
int triIndex = bsp->colWorld.indices[indexOfFirstIndex + indexIdx] + indexOfFirstVertex;
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());
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.data(), 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 (BSPSurface& surface : bsp->colWorld.surfaces)
for (const BSPSurface& surface : bsp.colWorld.surfaces)
{
// 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;
const int indexOfFirstTri = surface.indexOfFirstIndex / 3;
const int indexOfFirstVertex = surface.indexOfFirstVertex;
for (int triIdx = 0; triIdx < surface.triCount; triIdx++)
{
CollisionPartition partition;
@@ -522,7 +524,7 @@ namespace BSP
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];
uint16_t* tri = clipMap.triIndices[partition.firstTri];
uniqueIndicesVec.emplace_back(tri[0]);
uniqueIndicesVec.emplace_back(tri[1]);
uniqueIndicesVec.emplace_back(tri[2]);
@@ -530,13 +532,13 @@ namespace BSP
partitionVec.emplace_back(partition);
}
}
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.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());
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());
return true;
@@ -581,21 +583,21 @@ namespace BSP
*/
}
bool ClipMapLinker::loadWorldCollision(clipMap_t* clipMap, BSPData* bsp)
bool ClipMapLinker::loadWorldCollision(clipMap_t& clipMap, const BSPData& bsp)
{
// No support for brushes, only tris right now
clipMap->info.numBrushSides = 0;
clipMap->info.brushsides = nullptr;
clipMap->info.leafbrushNodesCount = 0;
clipMap->info.leafbrushNodes = nullptr;
clipMap->info.numLeafBrushes = 0;
clipMap->info.leafbrushes = nullptr;
clipMap->info.numBrushVerts = 0;
clipMap->info.brushVerts = nullptr;
clipMap->info.numBrushes = 0;
clipMap->info.brushes = nullptr;
clipMap->info.brushBounds = nullptr;
clipMap->info.brushContents = nullptr;
clipMap.info.numBrushSides = 0;
clipMap.info.brushsides = nullptr;
clipMap.info.leafbrushNodesCount = 0;
clipMap.info.leafbrushNodes = nullptr;
clipMap.info.numLeafBrushes = 0;
clipMap.info.leafbrushes = nullptr;
clipMap.info.numBrushVerts = 0;
clipMap.info.brushVerts = nullptr;
clipMap.info.numBrushes = 0;
clipMap.info.brushes = nullptr;
clipMap.info.brushBounds = nullptr;
clipMap.info.brushContents = nullptr;
// load verts, tris, uinds and partitions
if (!loadPartitions(clipMap, bsp))
@@ -606,31 +608,31 @@ namespace BSP
return true;
}
clipMap_t* ClipMapLinker::linkClipMap(BSPData* bsp)
clipMap_t* ClipMapLinker::linkClipMap(const BSPData& bsp)
{
clipMap_t* clipMap = m_memory.Alloc<clipMap_t>();
clipMap->name = m_memory.Dup(bsp->bspName.c_str());
clipMap->name = m_memory.Dup(bsp.bspName.c_str());
clipMap->isInUse = true;
clipMap->checksum = 0;
clipMap->pInfo = nullptr;
std::string mapEntsName = bsp->bspName;
std::string mapEntsName = bsp.bspName;
auto mapEntsAsset = m_context.LoadDependency<AssetMapEnts>(mapEntsName);
assert(mapEntsAsset != nullptr);
clipMap->mapEnts = mapEntsAsset->Asset();
loadBoxData(clipMap);
loadBoxData(*clipMap);
loadVisibility(clipMap);
loadVisibility(*clipMap);
loadRopesAndConstraints(clipMap);
loadRopesAndConstraints(*clipMap);
loadSubModelCollision(clipMap, bsp);
loadSubModelCollision(*clipMap, bsp);
loadDynEnts(clipMap);
loadDynEnts(*clipMap);
loadXModelCollision(clipMap);
loadXModelCollision(*clipMap);
// Clipmap materials define the properties of a material (bullet penetration, no collision, water, etc)
// Right now there is no way to define properties per material so only one material is used
@@ -646,7 +648,7 @@ namespace BSP
clipMap->triEdgeIsWalkable = new char[walkableEdgeSize];
memset(clipMap->triEdgeIsWalkable, 1, walkableEdgeSize * sizeof(char));
if (!loadWorldCollision(clipMap, bsp))
if (!loadWorldCollision(*clipMap, bsp))
return nullptr;
return clipMap;
@@ -12,29 +12,31 @@ namespace BSP
{
public:
ClipMapLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
T6::clipMap_t* linkClipMap(BSPData* bsp);
T6::clipMap_t* linkClipMap(const BSPData& bsp);
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
AssetCreationContext& m_context;
void loadBoxData(T6::clipMap_t* clipMap);
void loadVisibility(T6::clipMap_t* clipMap);
void loadDynEnts(T6::clipMap_t* clipMap);
void loadRopesAndConstraints(T6::clipMap_t* clipMap);
void loadSubModelCollision(T6::clipMap_t* clipMap, BSPData* bsp);
void loadXModelCollision(T6::clipMap_t* clipMap);
void loadBoxData(T6::clipMap_t& clipMap) const;
void loadVisibility(T6::clipMap_t& clipMap) const;
void loadDynEnts(T6::clipMap_t& clipMap) const;
void loadRopesAndConstraints(T6::clipMap_t& clipMap) const;
void loadSubModelCollision(T6::clipMap_t& clipMap, const BSPData& bsp) const;
void loadXModelCollision(T6::clipMap_t& clipMap) const;
std::vector<T6::cplane_s> planeVec;
std::vector<T6::cNode_t> nodeVec;
std::vector<T6::cLeaf_s> leafVec;
std::vector<T6::CollisionAabbTree> AABBTreeVec;
size_t highestLeafObjectCount = 0;
void addAABBTreeFromLeaf(T6::clipMap_t* clipMap, BSPTree* tree, size_t* out_parentCount, size_t* out_parentStartIndex);
int16_t loadBSPNode(T6::clipMap_t* clipMap, BSPTree* tree);
void loadBSPTree(T6::clipMap_t* clipMap, BSPData* bsp);
bool loadPartitions(T6::clipMap_t* clipMap, BSPData* bsp);
bool loadWorldCollision(T6::clipMap_t* clipMap, BSPData* bsp);
void addAABBTreeFromLeaf(T6::clipMap_t& clipMap, const BSPTree& tree, size_t& out_parentCount, size_t& out_parentStartIndex);
int16_t loadBSPNode(T6::clipMap_t& clipMap, const BSPTree& tree);
void loadBSPTree(T6::clipMap_t& clipMap, const BSPData& bsp);
bool loadPartitions(T6::clipMap_t& clipMap, const BSPData& bsp) const;
bool loadWorldCollision(T6::clipMap_t& clipMap, const BSPData& bsp);
};
} // namespace BSP
@@ -11,11 +11,11 @@ namespace BSP
{
}
ComWorld* ComWorldLinker::linkComWorld(BSPData* bsp)
ComWorld* ComWorldLinker::linkComWorld(const BSPData& bsp) const
{
// all lights that aren't the sunlight or default light need their own GfxLightDef asset
ComWorld* comWorld = m_memory.Alloc<ComWorld>();
comWorld->name = m_memory.Dup(bsp->bspName.c_str());
comWorld->name = m_memory.Dup(bsp.bspName.c_str());
comWorld->isInUse = 1;
comWorld->primaryLightCount = BSPGameConstants::BSP_DEFAULT_LIGHT_COUNT;
comWorld->primaryLights = m_memory.Alloc<ComPrimaryLight>(comWorld->primaryLightCount);
@@ -11,7 +11,7 @@ namespace BSP
{
public:
ComWorldLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
T6::ComWorld* linkComWorld(BSPData* bsp);
T6::ComWorld* linkComWorld(const BSPData& bsp) const;
private:
MemoryManager& m_memory;
@@ -11,11 +11,11 @@ namespace BSP
{
}
GameWorldMp* GameWorldMpLinker::linkGameWorldMp(BSPData* bsp)
GameWorldMp* GameWorldMpLinker::linkGameWorldMp(const BSPData& bsp) const
{
GameWorldMp* gameWorldMp = m_memory.Alloc<GameWorldMp>();
gameWorldMp->name = m_memory.Dup(bsp->bspName.c_str());
gameWorldMp->name = m_memory.Dup(bsp.bspName.c_str());
gameWorldMp->path.nodeCount = 0;
gameWorldMp->path.originalNodeCount = 0;
@@ -24,7 +24,7 @@ namespace BSP
gameWorldMp->path.nodeTreeCount = 0;
// The game has 128 empty nodes allocated
int extraNodeCount = gameWorldMp->path.nodeCount + 128;
const int extraNodeCount = gameWorldMp->path.nodeCount + 128;
gameWorldMp->path.nodes = m_memory.Alloc<pathnode_t>(extraNodeCount);
gameWorldMp->path.basenodes = m_memory.Alloc<pathbasenode_t>(extraNodeCount);
gameWorldMp->path.pathVis = nullptr;
@@ -11,7 +11,7 @@ namespace BSP
{
public:
GameWorldMpLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
T6::GameWorldMp* linkGameWorldMp(BSPData* bsp);
T6::GameWorldMp* linkGameWorldMp(const BSPData& bsp) const;
private:
MemoryManager& m_memory;
@@ -4,6 +4,8 @@
#include "Utils/Alignment.h"
#include "Utils/Pack.h"
#include <cassert>
using namespace T6;
namespace BSP
@@ -15,15 +17,15 @@ namespace BSP
{
}
void GfxWorldLinker::loadDrawData(BSPData* bsp, GfxWorld* gfxWorld)
void GfxWorldLinker::loadDrawData(const BSPData& bsp, GfxWorld& gfxWorld) const
{
size_t vertexCount = bsp->gfxWorld.vertices.size();
gfxWorld->draw.vertexCount = static_cast<unsigned int>(vertexCount);
gfxWorld->draw.vertexDataSize0 = static_cast<unsigned int>(vertexCount * sizeof(GfxPackedWorldVertex));
size_t vertexCount = bsp.gfxWorld.vertices.size();
gfxWorld.draw.vertexCount = static_cast<unsigned int>(vertexCount);
gfxWorld.draw.vertexDataSize0 = static_cast<unsigned int>(vertexCount * sizeof(GfxPackedWorldVertex));
GfxPackedWorldVertex* vertexBuffer = m_memory.Alloc<GfxPackedWorldVertex>(vertexCount);
for (size_t vertIdx = 0; vertIdx < vertexCount; vertIdx++)
{
BSPVertex& bspVertex = bsp->gfxWorld.vertices.at(vertIdx);
const BSPVertex& bspVertex = bsp.gfxWorld.vertices.at(vertIdx);
GfxPackedWorldVertex* gfxVertex = &vertexBuffer[vertIdx];
gfxVertex->xyz = bspVertex.pos;
@@ -36,35 +38,35 @@ namespace BSP
gfxVertex->binormalSign = 0.0f;
gfxVertex->lmapCoord.packed = 0;
}
gfxWorld->draw.vd0.data = reinterpret_cast<char*>(vertexBuffer);
gfxWorld.draw.vd0.data = reinterpret_cast<char*>(vertexBuffer);
// vd1 is unused but still needs to be initialised
// the data type varies and 0x20 is enough for all types
gfxWorld->draw.vertexDataSize1 = 0x20;
gfxWorld->draw.vd1.data = m_memory.Alloc<char>(gfxWorld->draw.vertexDataSize1);
gfxWorld.draw.vertexDataSize1 = 0x20;
gfxWorld.draw.vd1.data = m_memory.Alloc<char>(gfxWorld.draw.vertexDataSize1);
size_t indexCount = bsp->gfxWorld.indices.size();
size_t indexCount = bsp.gfxWorld.indices.size();
assert(indexCount % 3 == 0);
gfxWorld->draw.indexCount = static_cast<int>(indexCount);
gfxWorld->draw.indices = m_memory.Alloc<uint16_t>(indexCount);
gfxWorld.draw.indexCount = static_cast<int>(indexCount);
gfxWorld.draw.indices = m_memory.Alloc<uint16_t>(indexCount);
for (size_t indexIdx = 0; indexIdx < indexCount; indexIdx++)
{
gfxWorld->draw.indices[indexIdx] = bsp->gfxWorld.indices.at(indexIdx);
gfxWorld.draw.indices[indexIdx] = bsp.gfxWorld.indices.at(indexIdx);
}
}
bool GfxWorldLinker::loadMapSurfaces(BSPData* bsp, GfxWorld* gfxWorld)
bool GfxWorldLinker::loadMapSurfaces(const BSPData& bsp, GfxWorld& gfxWorld) const
{
loadDrawData(bsp, gfxWorld);
size_t surfaceCount = bsp->gfxWorld.surfaces.size();
gfxWorld->surfaceCount = static_cast<int>(surfaceCount);
gfxWorld->dpvs.staticSurfaceCount = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.surfaces = m_memory.Alloc<GfxSurface>(surfaceCount);
size_t surfaceCount = bsp.gfxWorld.surfaces.size();
gfxWorld.surfaceCount = static_cast<int>(surfaceCount);
gfxWorld.dpvs.staticSurfaceCount = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.surfaces = m_memory.Alloc<GfxSurface>(surfaceCount);
for (size_t surfIdx = 0; surfIdx < surfaceCount; surfIdx++)
{
BSPSurface& bspSurface = bsp->gfxWorld.surfaces.at(surfIdx);
GfxSurface* gfxSurface = &gfxWorld->dpvs.surfaces[surfIdx];
const BSPSurface& bspSurface = bsp.gfxWorld.surfaces.at(surfIdx);
GfxSurface* gfxSurface = &gfxWorld.dpvs.surfaces[surfIdx];
gfxSurface->primaryLightIndex = BSPEditableConstants::DEFAULT_SURFACE_LIGHT;
gfxSurface->lightmapIndex = BSPEditableConstants::DEFAULT_SURFACE_LIGHTMAP;
@@ -96,7 +98,7 @@ namespace BSP
}
gfxSurface->material = surfMaterialAsset->Asset();
GfxPackedWorldVertex* firstVert = reinterpret_cast<GfxPackedWorldVertex*>(&gfxWorld->draw.vd0.data[gfxSurface->tris.vertexDataOffset0]);
GfxPackedWorldVertex* firstVert = reinterpret_cast<GfxPackedWorldVertex*>(&gfxWorld.draw.vd0.data[gfxSurface->tris.vertexDataOffset0]);
gfxSurface->bounds[0].x = firstVert[0].xyz.x;
gfxSurface->bounds[0].y = firstVert[0].xyz.y;
gfxSurface->bounds[0].z = firstVert[0].xyz.z;
@@ -105,7 +107,7 @@ namespace BSP
gfxSurface->bounds[1].z = firstVert[0].xyz.z;
for (size_t indexIdx = 0; indexIdx < static_cast<size_t>(gfxSurface->tris.triCount * 3); indexIdx++)
{
uint16_t vertIndex = gfxWorld->draw.indices[gfxSurface->tris.baseIndex + indexIdx];
uint16_t vertIndex = gfxWorld.draw.indices[gfxSurface->tris.baseIndex + indexIdx];
BSPUtil::updateAABBWithPoint(firstVert[vertIndex].xyz, gfxSurface->bounds[0], gfxSurface->bounds[1]);
}
@@ -122,52 +124,52 @@ namespace BSP
}
// doesn't seem to matter what order the sorted surfs go in
gfxWorld->dpvs.sortedSurfIndex = m_memory.Alloc<uint16_t>(surfaceCount);
gfxWorld.dpvs.sortedSurfIndex = m_memory.Alloc<uint16_t>(surfaceCount);
for (size_t surfIdx = 0; surfIdx < surfaceCount; surfIdx++)
gfxWorld->dpvs.sortedSurfIndex[surfIdx] = static_cast<uint16_t>(surfIdx);
gfxWorld.dpvs.sortedSurfIndex[surfIdx] = static_cast<uint16_t>(surfIdx);
// surface materials are written to by the game
gfxWorld->dpvs.surfaceMaterials = m_memory.Alloc<GfxDrawSurf_align4>(surfaceCount);
gfxWorld.dpvs.surfaceMaterials = m_memory.Alloc<GfxDrawSurf_align4>(surfaceCount);
// set all surface types to lit opaque
gfxWorld->dpvs.litSurfsBegin = 0;
gfxWorld->dpvs.litSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.emissiveOpaqueSurfsBegin = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.emissiveOpaqueSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.emissiveTransSurfsBegin = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.emissiveTransSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.litTransSurfsBegin = static_cast<unsigned int>(surfaceCount);
gfxWorld->dpvs.litTransSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.litSurfsBegin = 0;
gfxWorld.dpvs.litSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.emissiveOpaqueSurfsBegin = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.emissiveOpaqueSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.emissiveTransSurfsBegin = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.emissiveTransSurfsEnd = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.litTransSurfsBegin = static_cast<unsigned int>(surfaceCount);
gfxWorld.dpvs.litTransSurfsEnd = static_cast<unsigned int>(surfaceCount);
// visdata is written to by the game
// all visdata is alligned by 128
auto alignedSurfaceCount = utils::Align(surfaceCount, 128uz);
gfxWorld->dpvs.surfaceVisDataCount = static_cast<unsigned int>(alignedSurfaceCount);
gfxWorld->dpvs.surfaceVisData[0] = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld->dpvs.surfaceVisData[1] = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld->dpvs.surfaceVisData[2] = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld->dpvs.surfaceVisDataCameraSaved = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld->dpvs.surfaceCastsShadow = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld->dpvs.surfaceCastsSunShadow = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceVisDataCount = static_cast<unsigned int>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceVisData[0] = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceVisData[1] = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceVisData[2] = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceVisDataCameraSaved = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceCastsShadow = m_memory.Alloc<char>(alignedSurfaceCount);
gfxWorld.dpvs.surfaceCastsSunShadow = m_memory.Alloc<char>(alignedSurfaceCount);
return true;
}
void GfxWorldLinker::loadXModels(BSPData* bsp, GfxWorld* gfxWorld)
void GfxWorldLinker::loadXModels(const BSPData& bsp, GfxWorld& gfxWorld) const
{
/*
Models are unsupported right now
Code is left in in case it is supported later on
unsigned int modelCount = projInfo->modelCount;
gfxWorld->dpvs.smodelCount = modelCount;
gfxWorld->dpvs.smodelInsts = new GfxStaticModelInst[modelCount];
gfxWorld->dpvs.smodelDrawInsts = new GfxStaticModelDrawInst[modelCount];
gfxWorld.dpvs.smodelCount = modelCount;
gfxWorld.dpvs.smodelInsts = new GfxStaticModelInst[modelCount];
gfxWorld.dpvs.smodelDrawInsts = new GfxStaticModelDrawInst[modelCount];
for (unsigned int i = 0; i < modelCount; i++)
{
auto currModel = &gfxWorld->dpvs.smodelDrawInsts[i];
auto currModelInst = &gfxWorld->dpvs.smodelInsts[i];
auto currModel = &gfxWorld.dpvs.smodelDrawInsts[i];
auto currModelInst = &gfxWorld.dpvs.smodelInsts[i];
customMapModel* inModel = &projInfo->models[i];
auto xModelAsset = m_context.LoadDependency<AssetXModel>(inModel->name);
@@ -223,172 +225,172 @@ namespace BSP
*/
unsigned int modelCount = 0;
gfxWorld->dpvs.smodelCount = modelCount;
gfxWorld->dpvs.smodelInsts = m_memory.Alloc<GfxStaticModelInst>(modelCount);
gfxWorld->dpvs.smodelDrawInsts = m_memory.Alloc<GfxStaticModelDrawInst>(modelCount);
gfxWorld.dpvs.smodelCount = modelCount;
gfxWorld.dpvs.smodelInsts = m_memory.Alloc<GfxStaticModelInst>(modelCount);
gfxWorld.dpvs.smodelDrawInsts = m_memory.Alloc<GfxStaticModelDrawInst>(modelCount);
// visdata is written to by the game
// all visdata is alligned by 128
const auto alignedModelCount = utils::Align(modelCount, 128u);
gfxWorld->dpvs.smodelVisDataCount = static_cast<unsigned int>(alignedModelCount);
gfxWorld->dpvs.smodelVisData[0] = m_memory.Alloc<char>(alignedModelCount);
gfxWorld->dpvs.smodelVisData[1] = m_memory.Alloc<char>(alignedModelCount);
gfxWorld->dpvs.smodelVisData[2] = m_memory.Alloc<char>(alignedModelCount);
gfxWorld->dpvs.smodelVisDataCameraSaved = m_memory.Alloc<char>(alignedModelCount);
gfxWorld->dpvs.smodelCastsShadow = m_memory.Alloc<char>(alignedModelCount);
gfxWorld.dpvs.smodelVisDataCount = static_cast<unsigned int>(alignedModelCount);
gfxWorld.dpvs.smodelVisData[0] = m_memory.Alloc<char>(alignedModelCount);
gfxWorld.dpvs.smodelVisData[1] = m_memory.Alloc<char>(alignedModelCount);
gfxWorld.dpvs.smodelVisData[2] = m_memory.Alloc<char>(alignedModelCount);
gfxWorld.dpvs.smodelVisDataCameraSaved = m_memory.Alloc<char>(alignedModelCount);
gfxWorld.dpvs.smodelCastsShadow = m_memory.Alloc<char>(alignedModelCount);
for (unsigned int i = 0; i < modelCount; i++)
{
if ((gfxWorld->dpvs.smodelDrawInsts[i].flags & STATIC_MODEL_FLAG_NO_SHADOW) == 0)
gfxWorld->dpvs.smodelCastsShadow[i] = 1;
if ((gfxWorld.dpvs.smodelDrawInsts[i].flags & STATIC_MODEL_FLAG_NO_SHADOW) == 0)
gfxWorld.dpvs.smodelCastsShadow[i] = 1;
else
gfxWorld->dpvs.smodelCastsShadow[i] = 0;
gfxWorld.dpvs.smodelCastsShadow[i] = 0;
}
// official maps set this to 0
gfxWorld->dpvs.usageCount = 0;
gfxWorld.dpvs.usageCount = 0;
}
void GfxWorldLinker::cleanGfxWorld(GfxWorld* gfxWorld)
void GfxWorldLinker::cleanGfxWorld(GfxWorld& gfxWorld) const
{
// checksum is generated by the game
gfxWorld->checksum = 0;
gfxWorld.checksum = 0;
// Remove Coronas
gfxWorld->coronaCount = 0;
gfxWorld->coronas = nullptr;
gfxWorld.coronaCount = 0;
gfxWorld.coronas = nullptr;
// Remove exposure volumes
gfxWorld->exposureVolumeCount = 0;
gfxWorld->exposureVolumes = nullptr;
gfxWorld->exposureVolumePlaneCount = 0;
gfxWorld->exposureVolumePlanes = nullptr;
gfxWorld.exposureVolumeCount = 0;
gfxWorld.exposureVolumes = nullptr;
gfxWorld.exposureVolumePlaneCount = 0;
gfxWorld.exposureVolumePlanes = nullptr;
// Remove hero lights
gfxWorld->heroLightCount = 0;
gfxWorld->heroLights = nullptr;
gfxWorld->heroLightTreeCount = 0;
gfxWorld->heroLightTree = nullptr;
gfxWorld.heroLightCount = 0;
gfxWorld.heroLights = nullptr;
gfxWorld.heroLightTreeCount = 0;
gfxWorld.heroLightTree = nullptr;
// remove LUT data
gfxWorld->lutVolumeCount = 0;
gfxWorld->lutVolumes = nullptr;
gfxWorld->lutVolumePlaneCount = 0;
gfxWorld->lutVolumePlanes = nullptr;
gfxWorld.lutVolumeCount = 0;
gfxWorld.lutVolumes = nullptr;
gfxWorld.lutVolumePlaneCount = 0;
gfxWorld.lutVolumePlanes = nullptr;
// remove occluders
gfxWorld->numOccluders = 0;
gfxWorld->occluders = nullptr;
gfxWorld.numOccluders = 0;
gfxWorld.occluders = nullptr;
// remove Siege Skins
gfxWorld->numSiegeSkinInsts = 0;
gfxWorld->siegeSkinInsts = nullptr;
gfxWorld.numSiegeSkinInsts = 0;
gfxWorld.siegeSkinInsts = nullptr;
// remove outdoor bounds
gfxWorld->numOutdoorBounds = 0;
gfxWorld->outdoorBounds = nullptr;
gfxWorld.numOutdoorBounds = 0;
gfxWorld.outdoorBounds = nullptr;
// remove materials
gfxWorld->ropeMaterial = nullptr;
gfxWorld->lutMaterial = nullptr;
gfxWorld->waterMaterial = nullptr;
gfxWorld->coronaMaterial = nullptr;
gfxWorld.ropeMaterial = nullptr;
gfxWorld.lutMaterial = nullptr;
gfxWorld.waterMaterial = nullptr;
gfxWorld.coronaMaterial = nullptr;
// remove shadow maps
gfxWorld->shadowMapVolumeCount = 0;
gfxWorld->shadowMapVolumes = nullptr;
gfxWorld->shadowMapVolumePlaneCount = 0;
gfxWorld->shadowMapVolumePlanes = nullptr;
gfxWorld.shadowMapVolumeCount = 0;
gfxWorld.shadowMapVolumes = nullptr;
gfxWorld.shadowMapVolumePlaneCount = 0;
gfxWorld.shadowMapVolumePlanes = nullptr;
// remove stream info
gfxWorld->streamInfo.aabbTreeCount = 0;
gfxWorld->streamInfo.aabbTrees = nullptr;
gfxWorld->streamInfo.leafRefCount = 0;
gfxWorld->streamInfo.leafRefs = nullptr;
gfxWorld.streamInfo.aabbTreeCount = 0;
gfxWorld.streamInfo.aabbTrees = nullptr;
gfxWorld.streamInfo.leafRefCount = 0;
gfxWorld.streamInfo.leafRefs = nullptr;
// remove sun data
memset(&gfxWorld->sun, 0, sizeof(sunflare_t));
gfxWorld->sun.hasValidData = false;
memset(&gfxWorld.sun, 0, sizeof(sunflare_t));
gfxWorld.sun.hasValidData = false;
// Remove Water
gfxWorld->waterDirection = 0.0f;
gfxWorld->waterBuffers[0].bufferSize = 0;
gfxWorld->waterBuffers[0].buffer = nullptr;
gfxWorld->waterBuffers[1].bufferSize = 0;
gfxWorld->waterBuffers[1].buffer = nullptr;
gfxWorld.waterDirection = 0.0f;
gfxWorld.waterBuffers[0].bufferSize = 0;
gfxWorld.waterBuffers[0].buffer = nullptr;
gfxWorld.waterBuffers[1].bufferSize = 0;
gfxWorld.waterBuffers[1].buffer = nullptr;
// Remove Fog
gfxWorld->worldFogModifierVolumeCount = 0;
gfxWorld->worldFogModifierVolumes = nullptr;
gfxWorld->worldFogModifierVolumePlaneCount = 0;
gfxWorld->worldFogModifierVolumePlanes = nullptr;
gfxWorld->worldFogVolumeCount = 0;
gfxWorld->worldFogVolumes = nullptr;
gfxWorld->worldFogVolumePlaneCount = 0;
gfxWorld->worldFogVolumePlanes = nullptr;
gfxWorld.worldFogModifierVolumeCount = 0;
gfxWorld.worldFogModifierVolumes = nullptr;
gfxWorld.worldFogModifierVolumePlaneCount = 0;
gfxWorld.worldFogModifierVolumePlanes = nullptr;
gfxWorld.worldFogVolumeCount = 0;
gfxWorld.worldFogVolumes = nullptr;
gfxWorld.worldFogVolumePlaneCount = 0;
gfxWorld.worldFogVolumePlanes = nullptr;
// materialMemory is unused
gfxWorld->materialMemoryCount = 0;
gfxWorld->materialMemory = nullptr;
gfxWorld.materialMemoryCount = 0;
gfxWorld.materialMemory = nullptr;
// sunLight is overwritten by the game, just needs to be a valid pointer
gfxWorld->sunLight = m_memory.Alloc<GfxLight>();
gfxWorld.sunLight = m_memory.Alloc<GfxLight>();
}
void GfxWorldLinker::loadGfxLights(GfxWorld* gfxWorld)
void GfxWorldLinker::loadGfxLights(GfxWorld& gfxWorld) const
{
// there must be 2 or more lights, first is the static light and second is the sun light
gfxWorld->primaryLightCount = BSPGameConstants::BSP_DEFAULT_LIGHT_COUNT;
gfxWorld->sunPrimaryLightIndex = BSPGameConstants::SUN_LIGHT_INDEX;
gfxWorld.primaryLightCount = BSPGameConstants::BSP_DEFAULT_LIGHT_COUNT;
gfxWorld.sunPrimaryLightIndex = BSPGameConstants::SUN_LIGHT_INDEX;
gfxWorld->shadowGeom = m_memory.Alloc<GfxShadowGeometry>(gfxWorld->primaryLightCount);
for (unsigned int lightIdx = 0; lightIdx < gfxWorld->primaryLightCount; lightIdx++)
gfxWorld.shadowGeom = m_memory.Alloc<GfxShadowGeometry>(gfxWorld.primaryLightCount);
for (unsigned int lightIdx = 0; lightIdx < gfxWorld.primaryLightCount; lightIdx++)
{
gfxWorld->shadowGeom[lightIdx].smodelCount = 0;
gfxWorld->shadowGeom[lightIdx].surfaceCount = 0;
gfxWorld->shadowGeom[lightIdx].smodelIndex = nullptr;
gfxWorld->shadowGeom[lightIdx].sortedSurfIndex = nullptr;
gfxWorld.shadowGeom[lightIdx].smodelCount = 0;
gfxWorld.shadowGeom[lightIdx].surfaceCount = 0;
gfxWorld.shadowGeom[lightIdx].smodelIndex = nullptr;
gfxWorld.shadowGeom[lightIdx].sortedSurfIndex = nullptr;
}
gfxWorld->lightRegion = m_memory.Alloc<GfxLightRegion>(gfxWorld->primaryLightCount);
for (unsigned int lightIdx = 0; lightIdx < gfxWorld->primaryLightCount; lightIdx++)
gfxWorld.lightRegion = m_memory.Alloc<GfxLightRegion>(gfxWorld.primaryLightCount);
for (unsigned int lightIdx = 0; lightIdx < gfxWorld.primaryLightCount; lightIdx++)
{
gfxWorld->lightRegion[lightIdx].hullCount = 0;
gfxWorld->lightRegion[lightIdx].hulls = nullptr;
gfxWorld.lightRegion[lightIdx].hullCount = 0;
gfxWorld.lightRegion[lightIdx].hulls = nullptr;
}
unsigned int lightEntShadowVisSize = (gfxWorld->primaryLightCount - gfxWorld->sunPrimaryLightIndex - 1) * 8192;
unsigned int lightEntShadowVisSize = (gfxWorld.primaryLightCount - gfxWorld.sunPrimaryLightIndex - 1) * 8192;
if (lightEntShadowVisSize != 0)
gfxWorld->primaryLightEntityShadowVis = m_memory.Alloc<unsigned int>(lightEntShadowVisSize);
gfxWorld.primaryLightEntityShadowVis = m_memory.Alloc<unsigned int>(lightEntShadowVisSize);
else
gfxWorld->primaryLightEntityShadowVis = nullptr;
gfxWorld.primaryLightEntityShadowVis = nullptr;
}
void GfxWorldLinker::loadLightGrid(GfxWorld* gfxWorld)
void GfxWorldLinker::loadLightGrid(GfxWorld& gfxWorld) const
{
// there is almost no basis for the values in this code, they were chosen based on what looks correct when reverse engineering.
// mins and maxs define the range that the lightgrid will work in.
// unknown how these values are calculated, but the below values are larger
// than official map values
gfxWorld->lightGrid.mins[0] = 0;
gfxWorld->lightGrid.mins[1] = 0;
gfxWorld->lightGrid.mins[2] = 0;
gfxWorld->lightGrid.maxs[0] = 200;
gfxWorld->lightGrid.maxs[1] = 200;
gfxWorld->lightGrid.maxs[2] = 50;
gfxWorld.lightGrid.mins[0] = 0;
gfxWorld.lightGrid.mins[1] = 0;
gfxWorld.lightGrid.mins[2] = 0;
gfxWorld.lightGrid.maxs[0] = 200;
gfxWorld.lightGrid.maxs[1] = 200;
gfxWorld.lightGrid.maxs[2] = 50;
gfxWorld->lightGrid.rowAxis = 0; // default value
gfxWorld->lightGrid.colAxis = 1; // default value
gfxWorld->lightGrid.sunPrimaryLightIndex = BSPGameConstants::SUN_LIGHT_INDEX;
gfxWorld->lightGrid.offset = 0.0f; // default value
gfxWorld.lightGrid.rowAxis = 0; // default value
gfxWorld.lightGrid.colAxis = 1; // default value
gfxWorld.lightGrid.sunPrimaryLightIndex = BSPGameConstants::SUN_LIGHT_INDEX;
gfxWorld.lightGrid.offset = 0.0f; // default value
// setting all rowDataStart indexes to 0 will always index the first row in rawRowData
int rowDataStartSize = gfxWorld->lightGrid.maxs[gfxWorld->lightGrid.rowAxis] - gfxWorld->lightGrid.mins[gfxWorld->lightGrid.rowAxis] + 1;
gfxWorld->lightGrid.rowDataStart = m_memory.Alloc<uint16_t>(rowDataStartSize);
int rowDataStartSize = gfxWorld.lightGrid.maxs[gfxWorld.lightGrid.rowAxis] - gfxWorld.lightGrid.mins[gfxWorld.lightGrid.rowAxis] + 1;
gfxWorld.lightGrid.rowDataStart = m_memory.Alloc<uint16_t>(rowDataStartSize);
// Adding 0x0F so the lookup table will be 0x10 bytes in size
gfxWorld->lightGrid.rawRowDataSize = static_cast<unsigned int>(sizeof(GfxLightGridRow) + 0x0F);
GfxLightGridRow* row = static_cast<GfxLightGridRow*>(m_memory.AllocRaw(gfxWorld->lightGrid.rawRowDataSize));
gfxWorld.lightGrid.rawRowDataSize = static_cast<unsigned int>(sizeof(GfxLightGridRow) + 0x0F);
GfxLightGridRow* row = static_cast<GfxLightGridRow*>(m_memory.AllocRaw(gfxWorld.lightGrid.rawRowDataSize));
row->colStart = 0;
row->colCount = 0x1000; // 0x1000 as this is large enough for all checks done by the game
row->zStart = 0;
@@ -396,127 +398,127 @@ namespace BSP
row->firstEntry = 0;
for (int i = 0; i < 0x10; i++) // set the lookup table to all 0
row->lookupTable[i] = 0;
gfxWorld->lightGrid.rawRowData = reinterpret_cast<aligned_byte_pointer*>(row);
gfxWorld.lightGrid.rawRowData = reinterpret_cast<aligned_byte_pointer*>(row);
// entries are looked up based on the lightgrid sample pos (given ingame) and the lightgrid lookup table
gfxWorld->lightGrid.entryCount = 60000; // 60000 as it should be enough entries to be indexed by all lightgrid sample positions
GfxLightGridEntry* entryArray = m_memory.Alloc<GfxLightGridEntry>(gfxWorld->lightGrid.entryCount);
for (unsigned int i = 0; i < gfxWorld->lightGrid.entryCount; i++)
gfxWorld.lightGrid.entryCount = 60000; // 60000 as it should be enough entries to be indexed by all lightgrid sample positions
GfxLightGridEntry* entryArray = m_memory.Alloc<GfxLightGridEntry>(gfxWorld.lightGrid.entryCount);
for (unsigned int i = 0; i < gfxWorld.lightGrid.entryCount; i++)
{
entryArray[i].colorsIndex = 0; // always index first colour
entryArray[i].primaryLightIndex = BSPGameConstants::SUN_LIGHT_INDEX;
entryArray[i].visibility = 0;
}
gfxWorld->lightGrid.entries = entryArray;
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.colors = m_memory.Alloc<GfxCompressedLightGridColors>(gfxWorld->lightGrid.colorCount);
memset(gfxWorld->lightGrid.colors, BSPEditableConstants::LIGHTGRID_COLOUR, rowDataStartSize * sizeof(uint16_t));
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));
// we use the colours array instead of coeffs array
gfxWorld->lightGrid.coeffCount = 0;
gfxWorld->lightGrid.coeffs = nullptr;
gfxWorld->lightGrid.skyGridVolumeCount = 0;
gfxWorld->lightGrid.skyGridVolumes = nullptr;
gfxWorld.lightGrid.coeffCount = 0;
gfxWorld.lightGrid.coeffs = nullptr;
gfxWorld.lightGrid.skyGridVolumeCount = 0;
gfxWorld.lightGrid.skyGridVolumes = nullptr;
}
void GfxWorldLinker::loadGfxCells(GfxWorld* gfxWorld)
void GfxWorldLinker::loadGfxCells(GfxWorld& gfxWorld) const
{
// Cells are basically data used to determine what can be seen and what cant be seen
// Right now custom maps have no optimisation so there is only 1 cell
int cellCount = 1;
gfxWorld->dpvsPlanes.cellCount = cellCount;
gfxWorld->cellBitsCount = ((cellCount + 127) >> 3) & 0x1FFFFFF0;
gfxWorld.dpvsPlanes.cellCount = cellCount;
gfxWorld.cellBitsCount = ((cellCount + 127) >> 3) & 0x1FFFFFF0;
int cellCasterBitsCount = cellCount * ((cellCount + 31) / 32);
gfxWorld->cellCasterBits = m_memory.Alloc<unsigned int>(cellCasterBitsCount);
gfxWorld.cellCasterBits = m_memory.Alloc<unsigned int>(cellCasterBitsCount);
int sceneEntCellBitsCount = cellCount * 512;
gfxWorld->dpvsPlanes.sceneEntCellBits = m_memory.Alloc<unsigned int>(sceneEntCellBitsCount);
gfxWorld.dpvsPlanes.sceneEntCellBits = m_memory.Alloc<unsigned int>(sceneEntCellBitsCount);
gfxWorld->cells = m_memory.Alloc<GfxCell>(cellCount);
gfxWorld->cells[0].portalCount = 0;
gfxWorld->cells[0].portals = nullptr;
gfxWorld->cells[0].mins.x = gfxWorld->mins.x;
gfxWorld->cells[0].mins.y = gfxWorld->mins.y;
gfxWorld->cells[0].mins.z = gfxWorld->mins.z;
gfxWorld->cells[0].maxs.x = gfxWorld->maxs.x;
gfxWorld->cells[0].maxs.y = gfxWorld->maxs.y;
gfxWorld->cells[0].maxs.z = gfxWorld->maxs.z;
gfxWorld.cells = m_memory.Alloc<GfxCell>(cellCount);
gfxWorld.cells[0].portalCount = 0;
gfxWorld.cells[0].portals = nullptr;
gfxWorld.cells[0].mins.x = gfxWorld.mins.x;
gfxWorld.cells[0].mins.y = gfxWorld.mins.y;
gfxWorld.cells[0].mins.z = gfxWorld.mins.z;
gfxWorld.cells[0].maxs.x = gfxWorld.maxs.x;
gfxWorld.cells[0].maxs.y = gfxWorld.maxs.y;
gfxWorld.cells[0].maxs.z = gfxWorld.maxs.z;
// there is only 1 reflection probe
gfxWorld->cells[0].reflectionProbeCount = 1;
gfxWorld->cells[0].reflectionProbes = m_memory.Alloc<char>(gfxWorld->cells[0].reflectionProbeCount);
gfxWorld->cells[0].reflectionProbes[0] = BSPEditableConstants::DEFAULT_SURFACE_REFLECTION_PROBE;
gfxWorld.cells[0].reflectionProbeCount = 1;
gfxWorld.cells[0].reflectionProbes = m_memory.Alloc<char>(gfxWorld.cells[0].reflectionProbeCount);
gfxWorld.cells[0].reflectionProbes[0] = BSPEditableConstants::DEFAULT_SURFACE_REFLECTION_PROBE;
// AABB trees are used to detect what should be rendered and what shouldn't
// Just use the first AABB node to hold all models, no optimisation but all models/surfaces wil lbe drawn
gfxWorld->cells[0].aabbTreeCount = 1;
gfxWorld->cells[0].aabbTree = m_memory.Alloc<GfxAabbTree>(gfxWorld->cells[0].aabbTreeCount);
gfxWorld->cells[0].aabbTree[0].childCount = 0;
gfxWorld->cells[0].aabbTree[0].childrenOffset = 0;
gfxWorld->cells[0].aabbTree[0].startSurfIndex = 0;
gfxWorld->cells[0].aabbTree[0].surfaceCount = static_cast<uint16_t>(gfxWorld->surfaceCount);
gfxWorld->cells[0].aabbTree[0].smodelIndexCount = static_cast<uint16_t>(gfxWorld->dpvs.smodelCount);
gfxWorld->cells[0].aabbTree[0].smodelIndexes = m_memory.Alloc<unsigned short>(gfxWorld->dpvs.smodelCount);
for (unsigned short smodelIdx = 0; smodelIdx < gfxWorld->dpvs.smodelCount; smodelIdx++)
gfxWorld.cells[0].aabbTreeCount = 1;
gfxWorld.cells[0].aabbTree = m_memory.Alloc<GfxAabbTree>(gfxWorld.cells[0].aabbTreeCount);
gfxWorld.cells[0].aabbTree[0].childCount = 0;
gfxWorld.cells[0].aabbTree[0].childrenOffset = 0;
gfxWorld.cells[0].aabbTree[0].startSurfIndex = 0;
gfxWorld.cells[0].aabbTree[0].surfaceCount = static_cast<uint16_t>(gfxWorld.surfaceCount);
gfxWorld.cells[0].aabbTree[0].smodelIndexCount = static_cast<uint16_t>(gfxWorld.dpvs.smodelCount);
gfxWorld.cells[0].aabbTree[0].smodelIndexes = m_memory.Alloc<unsigned short>(gfxWorld.dpvs.smodelCount);
for (unsigned short smodelIdx = 0; smodelIdx < gfxWorld.dpvs.smodelCount; smodelIdx++)
{
gfxWorld->cells[0].aabbTree[0].smodelIndexes[smodelIdx] = smodelIdx;
gfxWorld.cells[0].aabbTree[0].smodelIndexes[smodelIdx] = smodelIdx;
}
gfxWorld->cells[0].aabbTree[0].mins.x = gfxWorld->mins.x;
gfxWorld->cells[0].aabbTree[0].mins.y = gfxWorld->mins.y;
gfxWorld->cells[0].aabbTree[0].mins.z = gfxWorld->mins.z;
gfxWorld->cells[0].aabbTree[0].maxs.x = gfxWorld->maxs.x;
gfxWorld->cells[0].aabbTree[0].maxs.y = gfxWorld->maxs.y;
gfxWorld->cells[0].aabbTree[0].maxs.z = gfxWorld->maxs.z;
gfxWorld.cells[0].aabbTree[0].mins.x = gfxWorld.mins.x;
gfxWorld.cells[0].aabbTree[0].mins.y = gfxWorld.mins.y;
gfxWorld.cells[0].aabbTree[0].mins.z = gfxWorld.mins.z;
gfxWorld.cells[0].aabbTree[0].maxs.x = gfxWorld.maxs.x;
gfxWorld.cells[0].aabbTree[0].maxs.y = gfxWorld.maxs.y;
gfxWorld.cells[0].aabbTree[0].maxs.z = gfxWorld.maxs.z;
// nodes have the struct mnode_t, and there must be at least 1 node (similar to BSP nodes)
// Nodes mnode_t.cellIndex indexes gfxWorld->cells
// and (mnode_t.cellIndex - (world->dpvsPlanes.cellCount + 1) indexes world->dpvsPlanes.planes
// Use only one node as there is no optimisation in custom maps
gfxWorld->nodeCount = 1;
gfxWorld->dpvsPlanes.nodes = m_memory.Alloc<uint16_t>(gfxWorld->nodeCount);
gfxWorld->dpvsPlanes.nodes[0] = 1; // nodes reference cells by index + 1
gfxWorld.nodeCount = 1;
gfxWorld.dpvsPlanes.nodes = m_memory.Alloc<uint16_t>(gfxWorld.nodeCount);
gfxWorld.dpvsPlanes.nodes[0] = 1; // nodes reference cells by index + 1
// planes are overwritten by the clipmap loading code ingame
gfxWorld->planeCount = 0;
gfxWorld->dpvsPlanes.planes = nullptr;
gfxWorld.planeCount = 0;
gfxWorld.dpvsPlanes.planes = nullptr;
}
void GfxWorldLinker::loadWorldBounds(GfxWorld* gfxWorld)
void GfxWorldLinker::loadWorldBounds(GfxWorld& gfxWorld) const
{
gfxWorld->mins.x = 0.0f;
gfxWorld->mins.y = 0.0f;
gfxWorld->mins.z = 0.0f;
gfxWorld->maxs.x = 0.0f;
gfxWorld->maxs.y = 0.0f;
gfxWorld->maxs.z = 0.0f;
gfxWorld.mins.x = 0.0f;
gfxWorld.mins.y = 0.0f;
gfxWorld.mins.z = 0.0f;
gfxWorld.maxs.x = 0.0f;
gfxWorld.maxs.y = 0.0f;
gfxWorld.maxs.z = 0.0f;
for (int surfIdx = 0; surfIdx < gfxWorld->surfaceCount; surfIdx++)
for (int surfIdx = 0; surfIdx < gfxWorld.surfaceCount; surfIdx++)
{
BSPUtil::updateAABB(gfxWorld->dpvs.surfaces[surfIdx].bounds[0], gfxWorld->dpvs.surfaces[surfIdx].bounds[1], gfxWorld->mins, gfxWorld->maxs);
BSPUtil::updateAABB(gfxWorld.dpvs.surfaces[surfIdx].bounds[0], gfxWorld.dpvs.surfaces[surfIdx].bounds[1], gfxWorld.mins, gfxWorld.maxs);
}
}
void GfxWorldLinker::loadModels(GfxWorld* gfxWorld)
void GfxWorldLinker::loadModels(GfxWorld& gfxWorld) const
{
// Models (Submodels in the clipmap code) are used for the world and map ent collision (triggers, bomb zones, etc)
// Right now there is only one submodel, the world sub model
gfxWorld->modelCount = 1;
gfxWorld->models = m_memory.Alloc<GfxBrushModel>(gfxWorld->modelCount);
gfxWorld.modelCount = 1;
gfxWorld.models = m_memory.Alloc<GfxBrushModel>(gfxWorld.modelCount);
// first model is always the world model
gfxWorld->models[0].startSurfIndex = 0;
gfxWorld->models[0].surfaceCount = static_cast<unsigned int>(gfxWorld->surfaceCount);
gfxWorld->models[0].bounds[0].x = gfxWorld->mins.x;
gfxWorld->models[0].bounds[0].y = gfxWorld->mins.y;
gfxWorld->models[0].bounds[0].z = gfxWorld->mins.z;
gfxWorld->models[0].bounds[1].x = gfxWorld->maxs.x;
gfxWorld->models[0].bounds[1].y = gfxWorld->maxs.y;
gfxWorld->models[0].bounds[1].z = gfxWorld->maxs.z;
memset(&gfxWorld->models[0].writable, 0, sizeof(GfxBrushModelWritable));
gfxWorld.models[0].startSurfIndex = 0;
gfxWorld.models[0].surfaceCount = static_cast<unsigned int>(gfxWorld.surfaceCount);
gfxWorld.models[0].bounds[0].x = gfxWorld.mins.x;
gfxWorld.models[0].bounds[0].y = gfxWorld.mins.y;
gfxWorld.models[0].bounds[0].z = gfxWorld.mins.z;
gfxWorld.models[0].bounds[1].x = gfxWorld.maxs.x;
gfxWorld.models[0].bounds[1].y = gfxWorld.maxs.y;
gfxWorld.models[0].bounds[1].z = gfxWorld.maxs.z;
memset(&gfxWorld.models[0].writable, 0, sizeof(GfxBrushModelWritable));
// Other models aren't implemented yet
// Code kept for future use
@@ -537,79 +539,79 @@ namespace BSP
//}
}
void GfxWorldLinker::loadSunData(GfxWorld* gfxWorld)
void GfxWorldLinker::loadSunData(GfxWorld& gfxWorld) const
{
// default values taken from mp_dig
gfxWorld->sunParse.fogTransitionTime = 0.001f;
gfxWorld->sunParse.name[0] = 0x00;
gfxWorld.sunParse.fogTransitionTime = 0.001f;
gfxWorld.sunParse.name[0] = 0x00;
gfxWorld->sunParse.initWorldSun->control = 0;
gfxWorld->sunParse.initWorldSun->exposure = 2.5f;
gfxWorld->sunParse.initWorldSun->angles.x = -29.0f;
gfxWorld->sunParse.initWorldSun->angles.y = 254.0f;
gfxWorld->sunParse.initWorldSun->angles.z = 0.0f;
gfxWorld->sunParse.initWorldSun->sunCd.x = 1.0f;
gfxWorld->sunParse.initWorldSun->sunCd.y = 0.89f;
gfxWorld->sunParse.initWorldSun->sunCd.z = 0.69f;
gfxWorld->sunParse.initWorldSun->sunCd.w = 13.5f;
gfxWorld->sunParse.initWorldSun->ambientColor.x = 0.0f;
gfxWorld->sunParse.initWorldSun->ambientColor.y = 0.0f;
gfxWorld->sunParse.initWorldSun->ambientColor.z = 0.0f;
gfxWorld->sunParse.initWorldSun->ambientColor.w = 0.0f;
gfxWorld->sunParse.initWorldSun->skyColor.x = 0.0f;
gfxWorld->sunParse.initWorldSun->skyColor.y = 0.0f;
gfxWorld->sunParse.initWorldSun->skyColor.z = 0.0f;
gfxWorld->sunParse.initWorldSun->skyColor.w = 0.0f;
gfxWorld->sunParse.initWorldSun->sunCs.x = 0.0f;
gfxWorld->sunParse.initWorldSun->sunCs.y = 0.0f;
gfxWorld->sunParse.initWorldSun->sunCs.z = 0.0f;
gfxWorld->sunParse.initWorldSun->sunCs.w = 0.0f;
gfxWorld.sunParse.initWorldSun->control = 0;
gfxWorld.sunParse.initWorldSun->exposure = 2.5f;
gfxWorld.sunParse.initWorldSun->angles.x = -29.0f;
gfxWorld.sunParse.initWorldSun->angles.y = 254.0f;
gfxWorld.sunParse.initWorldSun->angles.z = 0.0f;
gfxWorld.sunParse.initWorldSun->sunCd.x = 1.0f;
gfxWorld.sunParse.initWorldSun->sunCd.y = 0.89f;
gfxWorld.sunParse.initWorldSun->sunCd.z = 0.69f;
gfxWorld.sunParse.initWorldSun->sunCd.w = 13.5f;
gfxWorld.sunParse.initWorldSun->ambientColor.x = 0.0f;
gfxWorld.sunParse.initWorldSun->ambientColor.y = 0.0f;
gfxWorld.sunParse.initWorldSun->ambientColor.z = 0.0f;
gfxWorld.sunParse.initWorldSun->ambientColor.w = 0.0f;
gfxWorld.sunParse.initWorldSun->skyColor.x = 0.0f;
gfxWorld.sunParse.initWorldSun->skyColor.y = 0.0f;
gfxWorld.sunParse.initWorldSun->skyColor.z = 0.0f;
gfxWorld.sunParse.initWorldSun->skyColor.w = 0.0f;
gfxWorld.sunParse.initWorldSun->sunCs.x = 0.0f;
gfxWorld.sunParse.initWorldSun->sunCs.y = 0.0f;
gfxWorld.sunParse.initWorldSun->sunCs.z = 0.0f;
gfxWorld.sunParse.initWorldSun->sunCs.w = 0.0f;
gfxWorld->sunParse.initWorldFog->baseDist = 150.0f;
gfxWorld->sunParse.initWorldFog->baseHeight = -100.0f;
gfxWorld->sunParse.initWorldFog->fogColor.x = 2.35f;
gfxWorld->sunParse.initWorldFog->fogColor.y = 3.10f;
gfxWorld->sunParse.initWorldFog->fogColor.z = 3.84f;
gfxWorld->sunParse.initWorldFog->fogOpacity = 0.52f;
gfxWorld->sunParse.initWorldFog->halfDist = 4450.f;
gfxWorld->sunParse.initWorldFog->halfHeight = 2000.f;
gfxWorld->sunParse.initWorldFog->sunFogColor.x = 5.27f;
gfxWorld->sunParse.initWorldFog->sunFogColor.y = 4.73f;
gfxWorld->sunParse.initWorldFog->sunFogColor.z = 3.88f;
gfxWorld->sunParse.initWorldFog->sunFogInner = 0.0f;
gfxWorld->sunParse.initWorldFog->sunFogOpacity = 0.67f;
gfxWorld->sunParse.initWorldFog->sunFogOuter = 80.84f;
gfxWorld->sunParse.initWorldFog->sunFogPitch = -29.0f;
gfxWorld->sunParse.initWorldFog->sunFogYaw = 254.0f;
gfxWorld.sunParse.initWorldFog->baseDist = 150.0f;
gfxWorld.sunParse.initWorldFog->baseHeight = -100.0f;
gfxWorld.sunParse.initWorldFog->fogColor.x = 2.35f;
gfxWorld.sunParse.initWorldFog->fogColor.y = 3.10f;
gfxWorld.sunParse.initWorldFog->fogColor.z = 3.84f;
gfxWorld.sunParse.initWorldFog->fogOpacity = 0.52f;
gfxWorld.sunParse.initWorldFog->halfDist = 4450.f;
gfxWorld.sunParse.initWorldFog->halfHeight = 2000.f;
gfxWorld.sunParse.initWorldFog->sunFogColor.x = 5.27f;
gfxWorld.sunParse.initWorldFog->sunFogColor.y = 4.73f;
gfxWorld.sunParse.initWorldFog->sunFogColor.z = 3.88f;
gfxWorld.sunParse.initWorldFog->sunFogInner = 0.0f;
gfxWorld.sunParse.initWorldFog->sunFogOpacity = 0.67f;
gfxWorld.sunParse.initWorldFog->sunFogOuter = 80.84f;
gfxWorld.sunParse.initWorldFog->sunFogPitch = -29.0f;
gfxWorld.sunParse.initWorldFog->sunFogYaw = 254.0f;
}
bool GfxWorldLinker::loadReflectionProbeData(GfxWorld* gfxWorld)
bool GfxWorldLinker::loadReflectionProbeData(GfxWorld& gfxWorld) const
{
gfxWorld->draw.reflectionProbeCount = 1;
gfxWorld.draw.reflectionProbeCount = 1;
gfxWorld->draw.reflectionProbeTextures = m_memory.Alloc<GfxTexture>(gfxWorld->draw.reflectionProbeCount);
gfxWorld.draw.reflectionProbeTextures = m_memory.Alloc<GfxTexture>(gfxWorld.draw.reflectionProbeCount);
// default values taken from mp_dig
gfxWorld->draw.reflectionProbes = m_memory.Alloc<GfxReflectionProbe>(gfxWorld->draw.reflectionProbeCount);
gfxWorld->draw.reflectionProbes[0].mipLodBias = -8.0;
gfxWorld->draw.reflectionProbes[0].origin.x = 0.0f;
gfxWorld->draw.reflectionProbes[0].origin.y = 0.0f;
gfxWorld->draw.reflectionProbes[0].origin.z = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V0.x = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V0.y = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V0.z = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V0.w = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V1.x = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V1.y = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V1.z = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V1.w = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V2.x = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V2.y = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V2.z = 0.0f;
gfxWorld->draw.reflectionProbes[0].lightingSH.V2.w = 0.0f;
gfxWorld.draw.reflectionProbes = m_memory.Alloc<GfxReflectionProbe>(gfxWorld.draw.reflectionProbeCount);
gfxWorld.draw.reflectionProbes[0].mipLodBias = -8.0;
gfxWorld.draw.reflectionProbes[0].origin.x = 0.0f;
gfxWorld.draw.reflectionProbes[0].origin.y = 0.0f;
gfxWorld.draw.reflectionProbes[0].origin.z = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V0.x = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V0.y = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V0.z = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V0.w = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V1.x = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V1.y = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V1.z = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V1.w = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V2.x = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V2.y = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V2.z = 0.0f;
gfxWorld.draw.reflectionProbes[0].lightingSH.V2.w = 0.0f;
gfxWorld->draw.reflectionProbes[0].probeVolumeCount = 0;
gfxWorld->draw.reflectionProbes[0].probeVolumes = nullptr;
gfxWorld.draw.reflectionProbes[0].probeVolumeCount = 0;
gfxWorld.draw.reflectionProbes[0].probeVolumes = nullptr;
std::string probeImageName = "reflection_probe0";
auto probeImageAsset = m_context.LoadDependency<AssetImage>(probeImageName);
@@ -618,17 +620,17 @@ namespace BSP
con::error("ERROR! unable to find reflection probe image {}!", probeImageName);
return false;
}
gfxWorld->draw.reflectionProbes[0].reflectionImage = probeImageAsset->Asset();
gfxWorld.draw.reflectionProbes[0].reflectionImage = probeImageAsset->Asset();
return true;
}
bool GfxWorldLinker::loadLightmapData(GfxWorld* gfxWorld)
bool GfxWorldLinker::loadLightmapData(GfxWorld& gfxWorld) const
{
gfxWorld->draw.lightmapCount = 1;
gfxWorld.draw.lightmapCount = 1;
gfxWorld->draw.lightmapPrimaryTextures = m_memory.Alloc<GfxTexture>(gfxWorld->draw.lightmapCount);
gfxWorld->draw.lightmapSecondaryTextures = m_memory.Alloc<GfxTexture>(gfxWorld->draw.lightmapCount);
gfxWorld.draw.lightmapPrimaryTextures = m_memory.Alloc<GfxTexture>(gfxWorld.draw.lightmapCount);
gfxWorld.draw.lightmapSecondaryTextures = m_memory.Alloc<GfxTexture>(gfxWorld.draw.lightmapCount);
std::string secondaryTexture = "lightmap0_secondary";
auto secondaryTextureAsset = m_context.LoadDependency<AssetImage>(secondaryTexture);
@@ -637,17 +639,17 @@ namespace BSP
con::error("ERROR! unable to find lightmap image {}!", secondaryTexture);
return false;
}
gfxWorld->draw.lightmaps = m_memory.Alloc<GfxLightmapArray>(gfxWorld->draw.lightmapCount);
gfxWorld->draw.lightmaps[0].primary = nullptr; // always nullptr
gfxWorld->draw.lightmaps[0].secondary = secondaryTextureAsset->Asset();
gfxWorld.draw.lightmaps = m_memory.Alloc<GfxLightmapArray>(gfxWorld.draw.lightmapCount);
gfxWorld.draw.lightmaps[0].primary = nullptr; // always nullptr
gfxWorld.draw.lightmaps[0].secondary = secondaryTextureAsset->Asset();
return true;
}
void GfxWorldLinker::loadSkyBox(BSPData* projInfo, GfxWorld* gfxWorld)
void GfxWorldLinker::loadSkyBox(const BSPData& projInfo, GfxWorld& gfxWorld) const
{
std::string skyBoxName = "skybox_" + projInfo->name;
gfxWorld->skyBoxModel = m_memory.Dup(skyBoxName.c_str());
const std::string skyBoxName = "skybox_" + projInfo.name;
gfxWorld.skyBoxModel = m_memory.Dup(skyBoxName.c_str());
if (m_context.LoadDependency<AssetXModel>(skyBoxName) == nullptr)
{
@@ -655,120 +657,120 @@ namespace BSP
}
// default skybox values from mp_dig
gfxWorld->skyDynIntensity.angle0 = 0.0f;
gfxWorld->skyDynIntensity.angle1 = 0.0f;
gfxWorld->skyDynIntensity.factor0 = 1.0f;
gfxWorld->skyDynIntensity.factor1 = 1.0f;
gfxWorld.skyDynIntensity.angle0 = 0.0f;
gfxWorld.skyDynIntensity.angle1 = 0.0f;
gfxWorld.skyDynIntensity.factor0 = 1.0f;
gfxWorld.skyDynIntensity.factor1 = 1.0f;
}
void GfxWorldLinker::loadDynEntData(GfxWorld* gfxWorld)
void GfxWorldLinker::loadDynEntData(GfxWorld& gfxWorld) const
{
int dynEntCount = 0;
gfxWorld->dpvsDyn.dynEntClientCount[0] = dynEntCount + 256; // the game allocs 256 empty dynents, as they may be used ingame
gfxWorld->dpvsDyn.dynEntClientCount[1] = 0;
gfxWorld.dpvsDyn.dynEntClientCount[0] = dynEntCount + 256; // the game allocs 256 empty dynents, as they may be used ingame
gfxWorld.dpvsDyn.dynEntClientCount[1] = 0;
// +100: there is a crash that happens when regdolls are created, and dynEntClientWordCount[0] is the issue.
// Making the value much larger than required fixes it, but unsure what the root cause is
gfxWorld->dpvsDyn.dynEntClientWordCount[0] = ((gfxWorld->dpvsDyn.dynEntClientCount[0] + 31) >> 5) + 100;
gfxWorld->dpvsDyn.dynEntClientWordCount[1] = 0;
gfxWorld->dpvsDyn.usageCount = 0;
gfxWorld.dpvsDyn.dynEntClientWordCount[0] = ((gfxWorld.dpvsDyn.dynEntClientCount[0] + 31) >> 5) + 100;
gfxWorld.dpvsDyn.dynEntClientWordCount[1] = 0;
gfxWorld.dpvsDyn.usageCount = 0;
int dynEntCellBitsSize = gfxWorld->dpvsDyn.dynEntClientWordCount[0] * gfxWorld->dpvsPlanes.cellCount;
gfxWorld->dpvsDyn.dynEntCellBits[0] = m_memory.Alloc<unsigned int>(dynEntCellBitsSize);
gfxWorld->dpvsDyn.dynEntCellBits[1] = nullptr;
const int dynEntCellBitsSize = gfxWorld.dpvsDyn.dynEntClientWordCount[0] * gfxWorld.dpvsPlanes.cellCount;
gfxWorld.dpvsDyn.dynEntCellBits[0] = m_memory.Alloc<unsigned int>(dynEntCellBitsSize);
gfxWorld.dpvsDyn.dynEntCellBits[1] = nullptr;
int dynEntVisData0Size = gfxWorld->dpvsDyn.dynEntClientWordCount[0] * 32;
gfxWorld->dpvsDyn.dynEntVisData[0][0] = m_memory.Alloc<char>(dynEntVisData0Size);
gfxWorld->dpvsDyn.dynEntVisData[0][1] = m_memory.Alloc<char>(dynEntVisData0Size);
gfxWorld->dpvsDyn.dynEntVisData[0][2] = m_memory.Alloc<char>(dynEntVisData0Size);
gfxWorld->dpvsDyn.dynEntVisData[1][0] = nullptr;
gfxWorld->dpvsDyn.dynEntVisData[1][1] = nullptr;
gfxWorld->dpvsDyn.dynEntVisData[1][2] = nullptr;
const int dynEntVisData0Size = gfxWorld.dpvsDyn.dynEntClientWordCount[0] * 32;
gfxWorld.dpvsDyn.dynEntVisData[0][0] = m_memory.Alloc<char>(dynEntVisData0Size);
gfxWorld.dpvsDyn.dynEntVisData[0][1] = m_memory.Alloc<char>(dynEntVisData0Size);
gfxWorld.dpvsDyn.dynEntVisData[0][2] = m_memory.Alloc<char>(dynEntVisData0Size);
gfxWorld.dpvsDyn.dynEntVisData[1][0] = nullptr;
gfxWorld.dpvsDyn.dynEntVisData[1][1] = nullptr;
gfxWorld.dpvsDyn.dynEntVisData[1][2] = nullptr;
unsigned int dynEntShadowVisCount = gfxWorld->dpvsDyn.dynEntClientCount[0] * (gfxWorld->primaryLightCount - gfxWorld->sunPrimaryLightIndex - 1);
gfxWorld->primaryLightDynEntShadowVis[0] = m_memory.Alloc<unsigned int>(dynEntShadowVisCount);
gfxWorld->primaryLightDynEntShadowVis[1] = nullptr;
const unsigned int dynEntShadowVisCount = gfxWorld.dpvsDyn.dynEntClientCount[0] * (gfxWorld.primaryLightCount - gfxWorld.sunPrimaryLightIndex - 1);
gfxWorld.primaryLightDynEntShadowVis[0] = m_memory.Alloc<unsigned int>(dynEntShadowVisCount);
gfxWorld.primaryLightDynEntShadowVis[1] = nullptr;
gfxWorld->sceneDynModel = m_memory.Alloc<GfxSceneDynModel>(gfxWorld->dpvsDyn.dynEntClientCount[0]);
gfxWorld->sceneDynBrush = nullptr;
gfxWorld.sceneDynModel = m_memory.Alloc<GfxSceneDynModel>(gfxWorld.dpvsDyn.dynEntClientCount[0]);
gfxWorld.sceneDynBrush = nullptr;
}
bool GfxWorldLinker::loadOutdoors(GfxWorld* gfxWorld)
bool GfxWorldLinker::loadOutdoors(GfxWorld& gfxWorld) const
{
float xRecip = 1.0f / (gfxWorld->maxs.x - gfxWorld->mins.x);
float xScale = -(xRecip * gfxWorld->mins.x);
const float xRecip = 1.0f / (gfxWorld.maxs.x - gfxWorld.mins.x);
const float xScale = -(xRecip * gfxWorld.mins.x);
float yRecip = 1.0f / (gfxWorld->maxs.y - gfxWorld->mins.y);
float yScale = -(yRecip * gfxWorld->mins.y);
const float yRecip = 1.0f / (gfxWorld.maxs.y - gfxWorld.mins.y);
const float yScale = -(yRecip * gfxWorld.mins.y);
float zRecip = 1.0f / (gfxWorld->maxs.z - gfxWorld->mins.z);
float zScale = -(zRecip * gfxWorld->mins.z);
const float zRecip = 1.0f / (gfxWorld.maxs.z - gfxWorld.mins.z);
const float zScale = -(zRecip * gfxWorld.mins.z);
memset(gfxWorld->outdoorLookupMatrix, 0, sizeof(gfxWorld->outdoorLookupMatrix));
memset(gfxWorld.outdoorLookupMatrix, 0, sizeof(gfxWorld.outdoorLookupMatrix));
gfxWorld->outdoorLookupMatrix[0].x = xRecip;
gfxWorld->outdoorLookupMatrix[1].y = yRecip;
gfxWorld->outdoorLookupMatrix[2].z = zRecip;
gfxWorld->outdoorLookupMatrix[3].x = xScale;
gfxWorld->outdoorLookupMatrix[3].y = yScale;
gfxWorld->outdoorLookupMatrix[3].z = zScale;
gfxWorld->outdoorLookupMatrix[3].w = 1.0f;
gfxWorld.outdoorLookupMatrix[0].x = xRecip;
gfxWorld.outdoorLookupMatrix[1].y = yRecip;
gfxWorld.outdoorLookupMatrix[2].z = zRecip;
gfxWorld.outdoorLookupMatrix[3].x = xScale;
gfxWorld.outdoorLookupMatrix[3].y = yScale;
gfxWorld.outdoorLookupMatrix[3].z = zScale;
gfxWorld.outdoorLookupMatrix[3].w = 1.0f;
std::string outdoorImageName = std::string("$outdoor");
const std::string outdoorImageName = std::string("$outdoor");
auto outdoorImageAsset = m_context.LoadDependency<AssetImage>(outdoorImageName);
if (outdoorImageAsset == nullptr)
{
con::error("ERROR! unable to find outdoor image $outdoor!");
return false;
}
gfxWorld->outdoorImage = outdoorImageAsset->Asset();
gfxWorld.outdoorImage = outdoorImageAsset->Asset();
return true;
}
GfxWorld* GfxWorldLinker::linkGfxWorld(BSPData* bsp)
GfxWorld* GfxWorldLinker::linkGfxWorld(const BSPData& bsp) const
{
GfxWorld* gfxWorld = m_memory.Alloc<GfxWorld>();
gfxWorld->baseName = m_memory.Dup(bsp->name.c_str());
gfxWorld->name = m_memory.Dup(bsp->bspName.c_str());
gfxWorld->baseName = m_memory.Dup(bsp.name.c_str());
gfxWorld->name = m_memory.Dup(bsp.bspName.c_str());
// Default values taken from official maps
gfxWorld->lightingFlags = 0;
gfxWorld->lightingQuality = 4096;
cleanGfxWorld(gfxWorld);
cleanGfxWorld(*gfxWorld);
if (!loadMapSurfaces(bsp, gfxWorld))
if (!loadMapSurfaces(bsp, *gfxWorld))
return nullptr;
loadXModels(bsp, gfxWorld);
loadXModels(bsp, *gfxWorld);
if (!loadLightmapData(gfxWorld))
if (!loadLightmapData(*gfxWorld))
return nullptr;
loadSkyBox(bsp, gfxWorld);
loadSkyBox(bsp, *gfxWorld);
if (!loadReflectionProbeData(gfxWorld))
if (!loadReflectionProbeData(*gfxWorld))
return nullptr;
// world bounds are based on loaded surface mins/maxs
loadWorldBounds(gfxWorld);
loadWorldBounds(*gfxWorld);
if (!loadOutdoors(gfxWorld))
if (!loadOutdoors(*gfxWorld))
return nullptr;
// gfx cells depend on surface/smodel count
loadGfxCells(gfxWorld);
loadGfxCells(*gfxWorld);
loadLightGrid(gfxWorld);
loadLightGrid(*gfxWorld);
loadGfxLights(gfxWorld);
loadGfxLights(*gfxWorld);
loadModels(gfxWorld);
loadModels(*gfxWorld);
loadSunData(gfxWorld);
loadSunData(*gfxWorld);
loadDynEntData(gfxWorld);
loadDynEntData(*gfxWorld);
return gfxWorld;
}
@@ -11,27 +11,27 @@ namespace BSP
{
public:
GfxWorldLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
T6::GfxWorld* linkGfxWorld(BSPData* bsp);
T6::GfxWorld* linkGfxWorld(const BSPData& bsp) const;
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
AssetCreationContext& m_context;
void loadDrawData(BSPData* projInfo, T6::GfxWorld* gfxWorld);
bool loadMapSurfaces(BSPData* projInfo, T6::GfxWorld* gfxWorld);
void loadXModels(BSPData* projInfo, T6::GfxWorld* gfxWorld);
void cleanGfxWorld(T6::GfxWorld* gfxWorld);
void loadGfxLights(T6::GfxWorld* gfxWorld);
void loadLightGrid(T6::GfxWorld* gfxWorld);
void loadGfxCells(T6::GfxWorld* gfxWorld);
void loadModels(T6::GfxWorld* gfxWorld);
bool loadReflectionProbeData(T6::GfxWorld* gfxWorld);
bool loadLightmapData(T6::GfxWorld* gfxWorld);
void loadSkyBox(BSPData* projInfo, T6::GfxWorld* gfxWorld);
void loadDynEntData(T6::GfxWorld* gfxWorld);
bool loadOutdoors(T6::GfxWorld* gfxWorld);
void loadSunData(T6::GfxWorld* gfxWorld);
void loadWorldBounds(T6::GfxWorld* gfxWorld);
void loadDrawData(const BSPData& projInfo, T6::GfxWorld& gfxWorld) const;
bool loadMapSurfaces(const BSPData& projInfo, T6::GfxWorld& gfxWorld) const;
void loadXModels(const BSPData& projInfo, T6::GfxWorld& gfxWorld) const;
void cleanGfxWorld(T6::GfxWorld& gfxWorld) const;
void loadGfxLights(T6::GfxWorld& gfxWorld) const;
void loadLightGrid(T6::GfxWorld& gfxWorld) const;
void loadGfxCells(T6::GfxWorld& gfxWorld) const;
void loadModels(T6::GfxWorld& gfxWorld) const;
bool loadReflectionProbeData(T6::GfxWorld& gfxWorld) const;
bool loadLightmapData(T6::GfxWorld& gfxWorld) const;
void loadSkyBox(const BSPData& projInfo, T6::GfxWorld& gfxWorld) const;
void loadDynEntData(T6::GfxWorld& gfxWorld) const;
bool loadOutdoors(T6::GfxWorld& gfxWorld) const;
void loadSunData(T6::GfxWorld& gfxWorld) const;
void loadWorldBounds(T6::GfxWorld& gfxWorld) const;
};
} // namespace BSP
@@ -74,7 +74,7 @@ namespace BSP
{
}
MapEnts* MapEntsLinker::linkMapEnts(BSPData* bsp)
MapEnts* MapEntsLinker::linkMapEnts(const BSPData& bsp) const
{
try
{
@@ -116,7 +116,7 @@ namespace BSP
parseSpawnpointJSON(spawnJs["FFA"], entityString, BSPGameConstants::FFA_SPAWN_POINT_NAMES, ffaNameCount);
MapEnts* mapEnts = m_memory.Alloc<MapEnts>();
mapEnts->name = m_memory.Dup(bsp->bspName.c_str());
mapEnts->name = m_memory.Dup(bsp.bspName.c_str());
mapEnts->entityString = m_memory.Dup(entityString.c_str());
mapEnts->numEntityChars = static_cast<int>(entityString.length() + 1); // numEntityChars includes the null character
@@ -11,7 +11,7 @@ namespace BSP
{
public:
MapEntsLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
T6::MapEnts* linkMapEnts(BSPData* bsp);
T6::MapEnts* linkMapEnts(const BSPData& bsp) const;
private:
MemoryManager& m_memory;
@@ -9,13 +9,13 @@ namespace BSP
{
}
T6::SkinnedVertsDef* SkinnedVertsLinker::linkSkinnedVerts(BSPData* bsp)
T6::SkinnedVertsDef* SkinnedVertsLinker::linkSkinnedVerts(const BSPData& bsp) const
{
// Pretty sure maxSkinnedVerts relates to the max amount of xmodel skinned verts a map will have
// But setting it to the world vertex count seems to work
T6::SkinnedVertsDef* skinnedVerts = m_memory.Alloc<T6::SkinnedVertsDef>();
skinnedVerts->name = m_memory.Dup("skinnedverts");
skinnedVerts->maxSkinnedVerts = static_cast<unsigned int>(bsp->gfxWorld.vertices.size());
skinnedVerts->maxSkinnedVerts = static_cast<unsigned int>(bsp.gfxWorld.vertices.size());
return skinnedVerts;
}
@@ -11,7 +11,7 @@ namespace BSP
{
public:
SkinnedVertsLinker(MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context);
T6::SkinnedVertsDef* linkSkinnedVerts(BSPData* bsp);
T6::SkinnedVertsDef* linkSkinnedVerts(const BSPData& bsp) const;
private:
MemoryManager& m_memory;
+2 -2
View File
@@ -32,12 +32,12 @@ namespace
bool FinalizeZone(AssetCreationContext& context) override
{
std::unique_ptr<BSPData> bsp = BSP::createBSPData(m_zone.m_name, m_search_path);
const std::unique_ptr<BSPData> bsp = BSP::createBSPData(m_zone.m_name, m_search_path);
if (bsp == nullptr)
return false;
BSPLinker linker(m_memory, m_search_path, context);
bool result = linker.linkBSP(bsp.get());
const bool result = linker.linkBSP(*bsp);
if (!result)
con::error("BSP link has failed.");