diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/Collision/BoundingIntervalHierarchy.cpp | 1 | ||||
| -rw-r--r-- | src/common/Collision/BoundingIntervalHierarchy.h | 2 | ||||
| -rw-r--r-- | src/common/Collision/DynamicTree.cpp | 5 | ||||
| -rw-r--r-- | src/common/Collision/DynamicTree.h | 3 | ||||
| -rw-r--r-- | src/common/Collision/Management/MMapManager.cpp | 1 | ||||
| -rw-r--r-- | src/common/Collision/Management/VMapManager2.cpp | 7 | ||||
| -rw-r--r-- | src/common/Collision/Management/VMapManager2.h | 1 | ||||
| -rw-r--r-- | src/common/Collision/RegularGrid.h | 60 |
8 files changed, 34 insertions, 46 deletions
diff --git a/src/common/Collision/BoundingIntervalHierarchy.cpp b/src/common/Collision/BoundingIntervalHierarchy.cpp index e37d00b802a..7e58d6c9003 100644 --- a/src/common/Collision/BoundingIntervalHierarchy.cpp +++ b/src/common/Collision/BoundingIntervalHierarchy.cpp @@ -16,6 +16,7 @@ */ #include "BoundingIntervalHierarchy.h" +#include <stdexcept> void BIH::buildHierarchy(std::vector<uint32>& tempTree, buildData& dat, BuildStats& stats) const { diff --git a/src/common/Collision/BoundingIntervalHierarchy.h b/src/common/Collision/BoundingIntervalHierarchy.h index 5c9c69ed1b6..5674ee2057d 100644 --- a/src/common/Collision/BoundingIntervalHierarchy.h +++ b/src/common/Collision/BoundingIntervalHierarchy.h @@ -24,8 +24,6 @@ #include <G3D/Ray.h> #include <G3D/Vector3.h> #include <algorithm> -#include <limits> -#include <stdexcept> #include <vector> #define MAX_STACK_SIZE 64 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/Management/MMapManager.cpp b/src/common/Collision/Management/MMapManager.cpp index 8c926d79a6e..c10d64bfd36 100644 --- a/src/common/Collision/Management/MMapManager.cpp +++ b/src/common/Collision/Management/MMapManager.cpp @@ -21,6 +21,7 @@ #include "Log.h" #include "MMapDefines.h" #include "Memory.h" +#include <algorithm> namespace MMAP { diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 93a1f7e4995..481b1cdb0ea 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -88,6 +88,13 @@ namespace VMAP thread_safe_environment = false; } + void VMapManager2::InitializeThreadUnsafe(uint32 mapId, int32 parentMapId) + { + iInstanceMapTrees[mapId] = nullptr; + if (parentMapId >= 0) + iParentMapData[mapId] = parentMapId; + } + Vector3 VMapManager2::convertPositionToInternalRep(float x, float y, float z) const { Vector3 pos; diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h index 5abe003056c..8fbc9b05ed1 100644 --- a/src/common/Collision/Management/VMapManager2.h +++ b/src/common/Collision/Management/VMapManager2.h @@ -84,6 +84,7 @@ namespace VMAP ~VMapManager2(); void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData); + void InitializeThreadUnsafe(uint32 mapId, int32 parentMapId); LoadResult loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override; diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h index 0110a17f412..459388d2662 100644 --- a/src/common/Collision/RegularGrid.h +++ b/src/common/Collision/RegularGrid.h @@ -22,7 +22,7 @@ #include "IteratorPair.h" #include <G3D/Ray.h> #include <G3D/BoundsTrait.h> -#include <G3D/PositionTrait.h> +#include <memory> #include <unordered_map> template<class Node> @@ -33,8 +33,7 @@ struct NodeCreator{ template<class T, class Node, class NodeCreatorFunc = NodeCreator<Node>, -class BoundsFunc = BoundsTrait<T>, -class PositionFunc = PositionTrait<T> +class BoundsFunc = BoundsTrait<T> > class TC_COMMON_API RegularGrid2D { @@ -44,27 +43,14 @@ public: CELL_NUMBER = 64, }; - #define HGRID_MAP_SIZE (533.33333f * 64.f) // shouldn't be changed - #define CELL_SIZE float(HGRID_MAP_SIZE/(float)CELL_NUMBER) + #define CELL_SIZE 533.33333f - typedef std::unordered_multimap<const T*, Node*> MemberTable; + typedef std::unordered_multimap<T const*, Node*> MemberTable; MemberTable memberTable; - Node* nodes[CELL_NUMBER][CELL_NUMBER]; + std::unique_ptr<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]; - } - - void insert(const T& value) + void insert(T const& value) { G3D::AABox bounds = G3D::AABox::empty(); BoundsFunc::getBounds(value, bounds); @@ -81,7 +67,7 @@ public: } } - void remove(const T& value) + void remove(T const& value) { for (auto& p : Trinity::Containers::MapEqualRange(memberTable, &value)) p.second->remove(value); @@ -93,25 +79,22 @@ 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(); } - bool contains(const T& value) const { return memberTable.count(&value) > 0; } + bool contains(T const& value) const { return memberTable.contains(&value); } bool empty() const { return memberTable.empty(); } struct Cell { int x, y; - bool operator==(Cell const& c2) const - { - return x == c2.x && y == c2.y; - } + + friend bool operator==(Cell const&, Cell const&) = default; static Cell ComputeCell(float fx, float fy) { - Cell c = { int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) }; - return c; + return { .x = int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), .y = int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) }; } bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER; } @@ -121,18 +104,18 @@ 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]; } template<typename RayCallback> - void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float max_dist) + void intersectRay(G3D::Ray const& ray, RayCallback& intersectCallback, float max_dist) { intersectRay(ray, intersectCallback, max_dist, ray.origin() + ray.direction() * max_dist); } template<typename RayCallback> - void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& max_dist, const G3D::Vector3& end) + void intersectRay(G3D::Ray const& ray, RayCallback& intersectCallback, float& max_dist, G3D::Vector3 const& end) { Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y); if (!cell.isValid()) @@ -142,7 +125,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 +169,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); @@ -208,28 +191,27 @@ public: } template<typename IsectCallback> - void intersectPoint(const G3D::Vector3& point, IsectCallback& intersectCallback) + void intersectPoint(G3D::Vector3 const& point, IsectCallback& intersectCallback) { 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); } // Optimized verson of intersectRay function for rays with vertical directions template<typename RayCallback> - void intersectZAllignedRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& max_dist) + void intersectZAllignedRay(G3D::Ray const& ray, RayCallback& intersectCallback, float& max_dist) { 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); } }; #undef CELL_SIZE -#undef HGRID_MAP_SIZE #endif |
