diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-10-23 19:50:56 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-10-23 19:50:56 +0200 |
| commit | f10eb2f1bfac38826f77e1e52abdd0d0d3d2481b (patch) | |
| tree | 1987862a21ae10a48700633833aeb74836b2d0b6 /src | |
| parent | 01df927c0f5a78d0af67f3c39d0aff64f96ece48 (diff) | |
Core/Vmaps: Use unique_ptr in RegularGrid2D and DynamicTree classes
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/Collision/DynamicTree.cpp | 5 | ||||
| -rw-r--r-- | src/common/Collision/DynamicTree.h | 3 | ||||
| -rw-r--r-- | src/common/Collision/RegularGrid.h | 27 |
3 files changed, 11 insertions, 24 deletions
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp index 073e317e4ae..7566edb473d 100644 --- a/src/common/Collision/DynamicTree.cpp +++ b/src/common/Collision/DynamicTree.cpp @@ -101,10 +101,7 @@ struct DynTreeImpl : public ParentTree/*, public Intersectable*/ DynamicMapTree::DynamicMapTree() : impl(new DynTreeImpl()) { } -DynamicMapTree::~DynamicMapTree() -{ - delete impl; -} +DynamicMapTree::~DynamicMapTree() = default; void DynamicMapTree::insert(GameObjectModel const& mdl) { diff --git a/src/common/Collision/DynamicTree.h b/src/common/Collision/DynamicTree.h index 50dc3d92993..11d701ebd7c 100644 --- a/src/common/Collision/DynamicTree.h +++ b/src/common/Collision/DynamicTree.h @@ -20,6 +20,7 @@ #include "Define.h" #include "Optional.h" +#include <memory> namespace G3D { @@ -38,7 +39,7 @@ namespace VMAP class TC_COMMON_API DynamicMapTree { - DynTreeImpl *impl; + std::unique_ptr<DynTreeImpl> impl; public: 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); } }; |
