aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision/RegularGrid.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-10-23 19:50:56 +0200
committerShauren <shauren.trinity@gmail.com>2025-10-23 19:50:56 +0200
commitf10eb2f1bfac38826f77e1e52abdd0d0d3d2481b (patch)
tree1987862a21ae10a48700633833aeb74836b2d0b6 /src/common/Collision/RegularGrid.h
parent01df927c0f5a78d0af67f3c39d0aff64f96ece48 (diff)
Core/Vmaps: Use unique_ptr in RegularGrid2D and DynamicTree classes
Diffstat (limited to 'src/common/Collision/RegularGrid.h')
-rw-r--r--src/common/Collision/RegularGrid.h27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h
index 0110a17f412..ec89e3825ff 100644
--- a/src/common/Collision/RegularGrid.h
+++ b/src/common/Collision/RegularGrid.h
@@ -23,6 +23,7 @@
#include <G3D/Ray.h>
#include <G3D/BoundsTrait.h>
#include <G3D/PositionTrait.h>
+#include <memory>
#include <unordered_map>
template<class Node>
@@ -50,19 +51,7 @@ public:
typedef std::unordered_multimap<const T*, Node*> MemberTable;
MemberTable memberTable;
- Node* nodes[CELL_NUMBER][CELL_NUMBER];
-
- RegularGrid2D()
- {
- memset(nodes, 0, sizeof(nodes));
- }
-
- ~RegularGrid2D()
- {
- for (int x = 0; x < CELL_NUMBER; ++x)
- for (int y = 0; y < CELL_NUMBER; ++y)
- delete nodes[x][y];
- }
+ std::unique_ptr<Node> nodes[CELL_NUMBER][CELL_NUMBER] = { };
void insert(const T& value)
{
@@ -93,7 +82,7 @@ public:
{
for (int x = 0; x < CELL_NUMBER; ++x)
for (int y = 0; y < CELL_NUMBER; ++y)
- if (Node* n = nodes[x][y])
+ if (Node* n = nodes[x][y].get())
n->balance();
}
@@ -121,7 +110,7 @@ public:
{
ASSERT(x < CELL_NUMBER && y < CELL_NUMBER);
if (!nodes[x][y])
- nodes[x][y] = NodeCreatorFunc::makeNode(x, y);
+ nodes[x][y].reset(NodeCreatorFunc::makeNode(x, y));
return *nodes[x][y];
}
@@ -142,7 +131,7 @@ public:
if (cell == last_cell)
{
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
node->intersectRay(ray, intersectCallback, max_dist);
return;
}
@@ -186,7 +175,7 @@ public:
float tDeltaY = voxel * std::fabs(ky_inv);
do
{
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
{
//float enterdist = max_dist;
node->intersectRay(ray, intersectCallback, max_dist);
@@ -213,7 +202,7 @@ public:
Cell cell = Cell::ComputeCell(point.x, point.y);
if (!cell.isValid())
return;
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
node->intersectPoint(point, intersectCallback);
}
@@ -224,7 +213,7 @@ public:
Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
if (!cell.isValid())
return;
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
node->intersectRay(ray, intersectCallback, max_dist);
}
};