From f10eb2f1bfac38826f77e1e52abdd0d0d3d2481b Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 23 Oct 2025 19:50:56 +0200 Subject: Core/Vmaps: Use unique_ptr in RegularGrid2D and DynamicTree classes --- src/common/Collision/RegularGrid.h | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'src/common/Collision/RegularGrid.h') 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 #include #include +#include #include template @@ -50,19 +51,7 @@ public: typedef std::unordered_multimap 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 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); } }; -- cgit v1.2.3