Browse Source

Replace UniquePtr by std::unique_ptr [cache clear]

1vanK 3 years ago
parent
commit
6cd3a253ee
32 changed files with 263 additions and 275 deletions
  1. 8 8
      Source/Urho3D/AngelScript/Generated_Members.h
  2. 0 118
      Source/Urho3D/Container/Ptr.h
  3. 3 1
      Source/Urho3D/Core/StringHashRegister.cpp
  4. 4 1
      Source/Urho3D/Core/StringHashRegister.h
  5. 3 1
      Source/Urho3D/Input/Input.cpp
  6. 4 1
      Source/Urho3D/Input/Input.h
  7. 10 8
      Source/Urho3D/Navigation/DynamicNavigationMesh.cpp
  8. 12 3
      Source/Urho3D/Navigation/DynamicNavigationMesh.h
  9. 7 7
      Source/Urho3D/Navigation/NavigationMesh.cpp
  10. 9 2
      Source/Urho3D/Navigation/NavigationMesh.h
  11. 33 30
      Source/Urho3D/Physics/CollisionShape.cpp
  12. 16 6
      Source/Urho3D/Physics/CollisionShape.h
  13. 17 15
      Source/Urho3D/Physics/Constraint.cpp
  14. 6 2
      Source/Urho3D/Physics/Constraint.h
  15. 19 17
      Source/Urho3D/Physics/PhysicsWorld.cpp
  16. 12 5
      Source/Urho3D/Physics/PhysicsWorld.h
  17. 12 10
      Source/Urho3D/Physics/RigidBody.cpp
  18. 10 5
      Source/Urho3D/Physics/RigidBody.h
  19. 3 1
      Source/Urho3D/Physics2D/PhysicsWorld2D.cpp
  20. 5 2
      Source/Urho3D/Physics2D/PhysicsWorld2D.h
  21. 13 8
      Source/Urho3D/Resource/XMLElement.cpp
  22. 8 4
      Source/Urho3D/Resource/XMLElement.h
  23. 6 2
      Source/Urho3D/Resource/XMLFile.cpp
  24. 4 2
      Source/Urho3D/Resource/XMLFile.h
  25. 3 1
      Source/Urho3D/Scene/Node.cpp
  26. 4 1
      Source/Urho3D/Scene/Node.h
  27. 5 3
      Source/Urho3D/Scene/Serializable.cpp
  28. 6 3
      Source/Urho3D/Scene/Serializable.h
  29. 5 3
      Source/Urho3D/Urho2D/AnimatedSprite2D.cpp
  30. 3 1
      Source/Urho3D/Urho2D/AnimatedSprite2D.h
  31. 4 2
      Source/Urho3D/Urho2D/AnimationSet2D.cpp
  32. 9 2
      Source/Urho3D/Urho2D/AnimationSet2D.h

+ 8 - 8
Source/Urho3D/AngelScript/Generated_Members.h

@@ -13107,8 +13107,8 @@ template <class T> void RegisterMembers_GImpactMeshData(asIScriptEngine* engine,
 {
 {
     RegisterMembers_CollisionGeometryData<T>(engine, className);
     RegisterMembers_CollisionGeometryData<T>(engine, className);
 
 
-    // UniquePtr<TriangleMeshInterface> GImpactMeshData::meshInterface_
-    // Error: type "UniquePtr<TriangleMeshInterface>" can not automatically bind
+    // std::unique_ptr<TriangleMeshInterface> GImpactMeshData::meshInterface_
+    // Error: type "std::unique_ptr<TriangleMeshInterface>" can not automatically bind
 
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_GImpactMeshData
     #ifdef REGISTER_MEMBERS_MANUAL_PART_GImpactMeshData
         REGISTER_MEMBERS_MANUAL_PART_GImpactMeshData();
         REGISTER_MEMBERS_MANUAL_PART_GImpactMeshData();
@@ -13145,12 +13145,12 @@ template <class T> void RegisterMembers_TriangleMeshData(asIScriptEngine* engine
 {
 {
     RegisterMembers_CollisionGeometryData<T>(engine, className);
     RegisterMembers_CollisionGeometryData<T>(engine, className);
 
 
-    // UniquePtr<TriangleMeshInterface> TriangleMeshData::meshInterface_
-    // Error: type "UniquePtr<TriangleMeshInterface>" can not automatically bind
-    // UniquePtr<btBvhTriangleMeshShape> TriangleMeshData::shape_
-    // Error: type "UniquePtr<btBvhTriangleMeshShape>" can not automatically bind
-    // UniquePtr<btTriangleInfoMap> TriangleMeshData::infoMap_
-    // Error: type "UniquePtr<btTriangleInfoMap>" can not automatically bind
+    // std::unique_ptr<TriangleMeshInterface> TriangleMeshData::meshInterface_
+    // Error: type "std::unique_ptr<TriangleMeshInterface>" can not automatically bind
+    // std::unique_ptr<btBvhTriangleMeshShape> TriangleMeshData::shape_
+    // Error: type "std::unique_ptr<btBvhTriangleMeshShape>" can not automatically bind
+    // std::unique_ptr<btTriangleInfoMap> TriangleMeshData::infoMap_
+    // Error: type "std::unique_ptr<btTriangleInfoMap>" can not automatically bind
 
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_TriangleMeshData
     #ifdef REGISTER_MEMBERS_MANUAL_PART_TriangleMeshData
         REGISTER_MEMBERS_MANUAL_PART_TriangleMeshData();
         REGISTER_MEMBERS_MANUAL_PART_TriangleMeshData();

+ 0 - 118
Source/Urho3D/Container/Ptr.h

@@ -563,124 +563,6 @@ template<class T> inline void CheckedDelete(T* x)
     delete x;
     delete x;
 }
 }
 
 
-/// Unique pointer template class.
-template <class T> class UniquePtr
-{
-public:
-    /// Construct empty.
-    UniquePtr() { }
-
-    /// Construct from pointer.
-    explicit UniquePtr(T* ptr) : ptr_(ptr) { }
-
-    /// Prevent copy construction.
-    UniquePtr(const UniquePtr&) = delete;
-    /// Prevent assignment.
-    UniquePtr& operator=(const UniquePtr&) = delete;
-
-    /// Assign from pointer.
-    UniquePtr& operator = (T* ptr)
-    {
-        Reset(ptr);
-        return *this;
-    }
-
-    /// Construct empty.
-    UniquePtr(std::nullptr_t) { }   // NOLINT(google-explicit-constructor)
-
-    /// Move-construct from UniquePtr.
-    UniquePtr(UniquePtr&& up) noexcept :
-        ptr_(up.Detach()) {}
-
-    /// Move-assign from UniquePtr.
-    UniquePtr& operator =(UniquePtr&& up) noexcept
-    {
-        Reset(up.Detach());
-        return *this;
-    }
-
-    /// Point to the object.
-    T* operator ->() const
-    {
-        assert(ptr_);
-        return ptr_;
-    }
-
-    /// Dereference the object.
-    T& operator *() const
-    {
-        assert(ptr_);
-        return *ptr_;
-    }
-
-    /// Test for less than with another unique pointer.
-    template <class U>
-    bool operator <(const UniquePtr<U>& rhs) const { return ptr_ < rhs.ptr_; }
-
-    /// Test for equality with another unique pointer.
-    template <class U>
-    bool operator ==(const UniquePtr<U>& rhs) const { return ptr_ == rhs.ptr_; }
-
-    /// Test for inequality with another unique pointer.
-    template <class U>
-    bool operator !=(const UniquePtr<U>& rhs) const { return ptr_ != rhs.ptr_; }
-
-    /// Cast pointer to bool.
-    operator bool() const { return !!ptr_; }    // NOLINT(google-explicit-constructor)
-
-    /// Swap with another UniquePtr.
-    void Swap(UniquePtr& up) { Urho3D::Swap(ptr_, up.ptr_); }
-
-    /// Detach pointer from UniquePtr without destroying.
-    T* Detach()
-    {
-        T* ptr = ptr_;
-        ptr_ = nullptr;
-        return ptr;
-    }
-
-    /// Check if the pointer is null.
-    bool Null() const { return ptr_ == 0; }
-
-    /// Check if the pointer is not null.
-    bool NotNull() const { return ptr_ != 0; }
-
-    /// Return the raw pointer.
-    T* Get() const { return ptr_; }
-
-    /// Reset.
-    void Reset(T* ptr = nullptr)
-    {
-        CheckedDelete(ptr_);
-        ptr_ = ptr;
-    }
-
-    /// Return hash value for HashSet & HashMap.
-    unsigned ToHash() const { return (unsigned)((size_t)ptr_ / sizeof(T)); }
-
-    /// Destruct.
-    ~UniquePtr()
-    {
-        Reset();
-    }
-
-private:
-    T* ptr_{};
-
-};
-
-/// Swap two UniquePtr-s.
-template <class T> void Swap(UniquePtr<T>& first, UniquePtr<T>& second)
-{
-    first.Swap(second);
-}
-
-/// Construct UniquePtr.
-template <class T, class ... Args> UniquePtr<T> MakeUnique(Args && ... args)
-{
-    return UniquePtr<T>(new T(std::forward<Args>(args)...));
-}
-
 /// Construct SharedPtr.
 /// Construct SharedPtr.
 template <class T, class ... Args> SharedPtr<T> MakeShared(Args && ... args)
 template <class T, class ... Args> SharedPtr<T> MakeShared(Args && ... args)
 {
 {

+ 3 - 1
Source/Urho3D/Core/StringHashRegister.cpp

@@ -30,13 +30,15 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
 StringHashRegister::StringHashRegister(bool threadSafe)
 StringHashRegister::StringHashRegister(bool threadSafe)
 {
 {
     if (threadSafe)
     if (threadSafe)
-        mutex_ = MakeUnique<Mutex>();
+        mutex_ = make_unique<Mutex>();
 }
 }
 
 
 
 

+ 4 - 1
Source/Urho3D/Core/StringHashRegister.h

@@ -26,6 +26,8 @@
 #include "../Container/Ptr.h"
 #include "../Container/Ptr.h"
 #include "../Math/StringHash.h"
 #include "../Math/StringHash.h"
 
 
+#include <memory>
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -57,8 +59,9 @@ public:
 private:
 private:
     /// Hash to string map.
     /// Hash to string map.
     StringMap map_;
     StringMap map_;
+    
     /// Mutex.
     /// Mutex.
-    UniquePtr<Mutex> mutex_;
+    std::unique_ptr<Mutex> mutex_;
 };
 };
 
 
 }
 }

+ 3 - 1
Source/Urho3D/Input/Input.cpp

@@ -51,6 +51,8 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 extern "C" int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char* name);
 extern "C" int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char* name);
 
 
 // Use a "click inside window to focus" mechanism on desktop platforms when the mouse cursor is hidden
 // Use a "click inside window to focus" mechanism on desktop platforms when the mouse cursor is hidden
@@ -391,7 +393,7 @@ Input::Input(Context* context) :
     SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
     SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
     SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
     SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
 #elif defined(__EMSCRIPTEN__)
 #elif defined(__EMSCRIPTEN__)
-    emscriptenInput_ = new EmscriptenInput(this);
+    emscriptenInput_ = make_unique<EmscriptenInput>(this);
 #endif
 #endif
 
 
     // Try to initialize right now, but skip if screen mode is not yet set
     // Try to initialize right now, but skip if screen mode is not yet set

+ 4 - 1
Source/Urho3D/Input/Input.h

@@ -479,11 +479,14 @@ private:
 
 
 #ifdef __EMSCRIPTEN__
 #ifdef __EMSCRIPTEN__
     /// Emscripten Input glue instance.
     /// Emscripten Input glue instance.
-    UniquePtr<EmscriptenInput> emscriptenInput_;
+    std::unique_ptr<EmscriptenInput> emscriptenInput_;
+    
     /// Flag used to detect mouse jump when exiting pointer-lock.
     /// Flag used to detect mouse jump when exiting pointer-lock.
     bool emscriptenExitingPointerLock_;
     bool emscriptenExitingPointerLock_;
+    
     /// Flag used to detect mouse jump on initial mouse click when entering pointer-lock.
     /// Flag used to detect mouse jump on initial mouse click when entering pointer-lock.
     bool emscriptenEnteredPointerLock_;
     bool emscriptenEnteredPointerLock_;
+    
     /// Flag indicating current pointer-lock status.
     /// Flag indicating current pointer-lock status.
     bool emscriptenPointerLock_;
     bool emscriptenPointerLock_;
 #endif
 #endif

+ 10 - 8
Source/Urho3D/Navigation/DynamicNavigationMesh.cpp

@@ -46,6 +46,8 @@
 #include <DetourTileCache/DetourTileCacheBuilder.h>
 #include <DetourTileCache/DetourTileCacheBuilder.h>
 #include <Recast/Recast.h>
 #include <Recast/Recast.h>
 
 
+using namespace std;
+
 // DebugNew is deliberately not used because the macro 'free' conflicts with DetourTileCache's LinearAllocator interface
 // DebugNew is deliberately not used because the macro 'free' conflicts with DetourTileCache's LinearAllocator interface
 //#include "../DebugNew.h"
 //#include "../DebugNew.h"
 
 
@@ -215,9 +217,9 @@ DynamicNavigationMesh::DynamicNavigationMesh(Context* context) :
     // 64 is the largest tile-size that DetourTileCache will tolerate without silently failing
     // 64 is the largest tile-size that DetourTileCache will tolerate without silently failing
     tileSize_ = 64;
     tileSize_ = 64;
     partitionType_ = NAVMESH_PARTITION_MONOTONE;
     partitionType_ = NAVMESH_PARTITION_MONOTONE;
-    allocator_ = new LinearAllocator(32000); //32kb to start
-    compressor_ = new TileCompressor();
-    meshProcessor_ = new MeshProcess(this);
+    allocator_ = make_unique<LinearAllocator>(32000); //32kb to start
+    compressor_ = make_unique<TileCompressor>();
+    meshProcessor_ = make_unique<MeshProcess>(this);
 }
 }
 
 
 DynamicNavigationMesh::~DynamicNavigationMesh()
 DynamicNavigationMesh::~DynamicNavigationMesh()
@@ -304,7 +306,7 @@ bool DynamicNavigationMesh::Allocate(const BoundingBox& boundingBox, unsigned ma
         return false;
         return false;
     }
     }
 
 
-    if (dtStatusFailed(tileCache_->init(&tileCacheParams, allocator_.Get(), compressor_.Get(), meshProcessor_.Get())))
+    if (dtStatusFailed(tileCache_->init(&tileCacheParams, allocator_.get(), compressor_.get(), meshProcessor_.get())))
     {
     {
         URHO3D_LOGERROR("Could not initialize tile cache");
         URHO3D_LOGERROR("Could not initialize tile cache");
         ReleaseNavigationMesh();
         ReleaseNavigationMesh();
@@ -419,7 +421,7 @@ bool DynamicNavigationMesh::Build()
             return false;
             return false;
         }
         }
 
 
-        if (dtStatusFailed(tileCache_->init(&tileCacheParams, allocator_.Get(), compressor_.Get(), meshProcessor_.Get())))
+        if (dtStatusFailed(tileCache_->init(&tileCacheParams, allocator_.get(), compressor_.get(), meshProcessor_.get())))
         {
         {
             URHO3D_LOGERROR("Could not initialize tile cache");
             URHO3D_LOGERROR("Could not initialize tile cache");
             ReleaseNavigationMesh();
             ReleaseNavigationMesh();
@@ -711,7 +713,7 @@ void DynamicNavigationMesh::SetNavigationDataAttr(const PODVector<unsigned char>
         ReleaseNavigationMesh();
         ReleaseNavigationMesh();
         return;
         return;
     }
     }
-    if (dtStatusFailed(tileCache_->init(&tcParams, allocator_.Get(), compressor_.Get(), meshProcessor_.Get())))
+    if (dtStatusFailed(tileCache_->init(&tcParams, allocator_.get(), compressor_.get(), meshProcessor_.get())))
     {
     {
         URHO3D_LOGERROR("Could not initialize tile cache");
         URHO3D_LOGERROR("Could not initialize tile cache");
         ReleaseNavigationMesh();
         ReleaseNavigationMesh();
@@ -825,7 +827,7 @@ int DynamicNavigationMesh::BuildTile(Vector<NavigationGeometryInfo>& geometryLis
 
 
     const BoundingBox tileBoundingBox = GetTileBoundingBox(IntVector2(x, z));
     const BoundingBox tileBoundingBox = GetTileBoundingBox(IntVector2(x, z));
 
 
-    DynamicNavBuildData build(allocator_.Get());
+    DynamicNavBuildData build(allocator_.get());
 
 
     rcConfig cfg;   // NOLINT(hicpp-member-init)
     rcConfig cfg;   // NOLINT(hicpp-member-init)
     memset(&cfg, 0, sizeof cfg);
     memset(&cfg, 0, sizeof cfg);
@@ -972,7 +974,7 @@ int DynamicNavigationMesh::BuildTile(Vector<NavigationGeometryInfo>& geometryLis
         header.hmax = (unsigned short)layer->hmax;
         header.hmax = (unsigned short)layer->hmax;
 
 
         if (dtStatusFailed(
         if (dtStatusFailed(
-            dtBuildTileCacheLayer(compressor_.Get()/*compressor*/, &header, layer->heights, layer->areas/*areas*/, layer->cons,
+            dtBuildTileCacheLayer(compressor_.get(), &header, layer->heights, layer->areas, layer->cons,
                 &(tiles[retCt].data), &tiles[retCt].dataSize)))
                 &(tiles[retCt].data), &tiles[retCt].dataSize)))
         {
         {
             URHO3D_LOGERROR("Failed to build tile cache layers");
             URHO3D_LOGERROR("Failed to build tile cache layers");

+ 12 - 3
Source/Urho3D/Navigation/DynamicNavigationMesh.h

@@ -24,6 +24,8 @@
 
 
 #include "../Navigation/NavigationMesh.h"
 #include "../Navigation/NavigationMesh.h"
 
 
+#include <memory>
+
 class dtTileCache;
 class dtTileCache;
 struct dtTileCacheAlloc;
 struct dtTileCacheAlloc;
 struct dtTileCacheCompressor;
 struct dtTileCacheCompressor;
@@ -139,18 +141,25 @@ private:
 
 
     /// Detour tile cache instance that works with the nav mesh.
     /// Detour tile cache instance that works with the nav mesh.
     dtTileCache* tileCache_{};
     dtTileCache* tileCache_{};
+    
     /// Used by dtTileCache to allocate blocks of memory.
     /// Used by dtTileCache to allocate blocks of memory.
-    UniquePtr<dtTileCacheAlloc> allocator_;
+    std::unique_ptr<dtTileCacheAlloc> allocator_;
+    
     /// Used by dtTileCache to compress the original tiles to use when reconstructing for changes.
     /// Used by dtTileCache to compress the original tiles to use when reconstructing for changes.
-    UniquePtr<dtTileCacheCompressor> compressor_;
+    std::unique_ptr<dtTileCacheCompressor> compressor_;
+    
     /// Mesh processor used by Detour, in this case a 'pass-through' processor.
     /// Mesh processor used by Detour, in this case a 'pass-through' processor.
-    UniquePtr<dtTileCacheMeshProcess> meshProcessor_;
+    std::unique_ptr<dtTileCacheMeshProcess> meshProcessor_;
+    
     /// Maximum number of obstacle objects allowed.
     /// Maximum number of obstacle objects allowed.
     unsigned maxObstacles_{1024};
     unsigned maxObstacles_{1024};
+    
     /// Maximum number of layers that are allowed to be constructed.
     /// Maximum number of layers that are allowed to be constructed.
     unsigned maxLayers_{};
     unsigned maxLayers_{};
+    
     /// Debug draw Obstacles.
     /// Debug draw Obstacles.
     bool drawObstacles_{};
     bool drawObstacles_{};
+    
     /// Queue of tiles to be built.
     /// Queue of tiles to be built.
     PODVector<IntVector2> tileQueue_;
     PODVector<IntVector2> tileQueue_;
 };
 };

+ 7 - 7
Source/Urho3D/Navigation/NavigationMesh.cpp

@@ -619,7 +619,7 @@ Vector3 NavigationMesh::FindNearestPoint(const Vector3& point, const Vector3& ex
     dtPolyRef pointRef;
     dtPolyRef pointRef;
     if (!nearestRef)
     if (!nearestRef)
         nearestRef = &pointRef;
         nearestRef = &pointRef;
-    navMeshQuery_->findNearestPoly(&localPoint.x_, &extents.x_, filter ? filter : queryFilter_.Get(), nearestRef, &nearestPoint.x_);
+    navMeshQuery_->findNearestPoly(&localPoint.x_, &extents.x_, filter ? filter : queryFilter_.get(), nearestRef, &nearestPoint.x_);
     return *nearestRef ? transform * nearestPoint : point;
     return *nearestRef ? transform * nearestPoint : point;
 }
 }
 
 
@@ -635,7 +635,7 @@ Vector3 NavigationMesh::MoveAlongSurface(const Vector3& start, const Vector3& en
     Vector3 localStart = inverse * start;
     Vector3 localStart = inverse * start;
     Vector3 localEnd = inverse * end;
     Vector3 localEnd = inverse * end;
 
 
-    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.Get();
+    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.get();
     dtPolyRef startRef;
     dtPolyRef startRef;
     navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, nullptr);
     navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, nullptr);
     if (!startRef)
     if (!startRef)
@@ -677,7 +677,7 @@ void NavigationMesh::FindPath(PODVector<NavigationPathPoint>& dest, const Vector
     Vector3 localStart = inverse * start;
     Vector3 localStart = inverse * start;
     Vector3 localEnd = inverse * end;
     Vector3 localEnd = inverse * end;
 
 
-    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.Get();
+    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.get();
     dtPolyRef startRef;
     dtPolyRef startRef;
     dtPolyRef endRef;
     dtPolyRef endRef;
     navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, nullptr);
     navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, nullptr);
@@ -745,7 +745,7 @@ Vector3 NavigationMesh::GetRandomPoint(const dtQueryFilter* filter, dtPolyRef* r
     dtPolyRef polyRef;
     dtPolyRef polyRef;
     Vector3 point(Vector3::ZERO);
     Vector3 point(Vector3::ZERO);
 
 
-    navMeshQuery_->findRandomPoint(filter ? filter : queryFilter_.Get(), Random, randomRef ? randomRef : &polyRef, &point.x_);
+    navMeshQuery_->findRandomPoint(filter ? filter : queryFilter_.get(), Random, randomRef ? randomRef : &polyRef, &point.x_);
 
 
     return node_->GetWorldTransform() * point;
     return node_->GetWorldTransform() * point;
 }
 }
@@ -763,7 +763,7 @@ Vector3 NavigationMesh::GetRandomPointInCircle(const Vector3& center, float radi
     Matrix3x4 inverse = transform.Inverse();
     Matrix3x4 inverse = transform.Inverse();
     Vector3 localCenter = inverse * center;
     Vector3 localCenter = inverse * center;
 
 
-    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.Get();
+    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.get();
     dtPolyRef startRef;
     dtPolyRef startRef;
     navMeshQuery_->findNearestPoly(&localCenter.x_, &extents.x_, queryFilter, &startRef, nullptr);
     navMeshQuery_->findNearestPoly(&localCenter.x_, &extents.x_, queryFilter, &startRef, nullptr);
     if (!startRef)
     if (!startRef)
@@ -794,7 +794,7 @@ float NavigationMesh::GetDistanceToWall(const Vector3& point, float radius, cons
     Matrix3x4 inverse = transform.Inverse();
     Matrix3x4 inverse = transform.Inverse();
     Vector3 localPoint = inverse * point;
     Vector3 localPoint = inverse * point;
 
 
-    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.Get();
+    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.get();
     dtPolyRef startRef;
     dtPolyRef startRef;
     navMeshQuery_->findNearestPoly(&localPoint.x_, &extents.x_, queryFilter, &startRef, nullptr);
     navMeshQuery_->findNearestPoly(&localPoint.x_, &extents.x_, queryFilter, &startRef, nullptr);
     if (!startRef)
     if (!startRef)
@@ -827,7 +827,7 @@ Vector3 NavigationMesh::Raycast(const Vector3& start, const Vector3& end, const
     Vector3 localStart = inverse * start;
     Vector3 localStart = inverse * start;
     Vector3 localEnd = inverse * end;
     Vector3 localEnd = inverse * end;
 
 
-    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.Get();
+    const dtQueryFilter* queryFilter = filter ? filter : queryFilter_.get();
     dtPolyRef startRef;
     dtPolyRef startRef;
     navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, nullptr);
     navMeshQuery_->findNearestPoly(&localStart.x_, &extents.x_, queryFilter, &startRef, nullptr);
     if (!startRef)
     if (!startRef)

+ 9 - 2
Source/Urho3D/Navigation/NavigationMesh.h

@@ -30,6 +30,8 @@
 #include "../Math/Matrix3x4.h"
 #include "../Math/Matrix3x4.h"
 #include "../Scene/Component.h"
 #include "../Scene/Component.h"
 
 
+#include <memory>
+
 #ifdef DT_POLYREF64
 #ifdef DT_POLYREF64
 using dtPolyRef = uint64_t;
 using dtPolyRef = uint64_t;
 #else
 #else
@@ -339,14 +341,19 @@ protected:
 
 
     /// Identifying name for this navigation mesh.
     /// Identifying name for this navigation mesh.
     String meshName_;
     String meshName_;
+    
     /// Detour navigation mesh.
     /// Detour navigation mesh.
     dtNavMesh* navMesh_;
     dtNavMesh* navMesh_;
+    
     /// Detour navigation mesh query.
     /// Detour navigation mesh query.
     dtNavMeshQuery* navMeshQuery_;
     dtNavMeshQuery* navMeshQuery_;
+    
     /// Detour navigation mesh query filter.
     /// Detour navigation mesh query filter.
-    UniquePtr<dtQueryFilter> queryFilter_;
+    std::unique_ptr<dtQueryFilter> queryFilter_;
+    
     /// Temporary data for finding a path.
     /// Temporary data for finding a path.
-    UniquePtr<FindPathData> pathData_;
+    std::unique_ptr<FindPathData> pathData_;
+    
     /// Tile size.
     /// Tile size.
     int tileSize_;
     int tileSize_;
     /// Cell size.
     /// Cell size.

+ 33 - 30
Source/Urho3D/Physics/CollisionShape.cpp

@@ -57,6 +57,8 @@
 #include <Bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
 #include <Bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
 #include <StanHull/hull.h>
 #include <StanHull/hull.h>
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -198,30 +200,30 @@ private:
 
 
 TriangleMeshData::TriangleMeshData(Model* model, unsigned lodLevel)
 TriangleMeshData::TriangleMeshData(Model* model, unsigned lodLevel)
 {
 {
-    meshInterface_ = new TriangleMeshInterface(model, lodLevel);
-    shape_ = new btBvhTriangleMeshShape(meshInterface_.Get(), meshInterface_->useQuantize_, true);
+    meshInterface_ = make_unique<TriangleMeshInterface>(model, lodLevel);
+    shape_ = make_unique<btBvhTriangleMeshShape>(meshInterface_.get(), meshInterface_->useQuantize_, true);
 
 
-    infoMap_ = new btTriangleInfoMap();
-    btGenerateInternalEdgeInfo(shape_.Get(), infoMap_.Get());
+    infoMap_ = make_unique<btTriangleInfoMap>();
+    btGenerateInternalEdgeInfo(shape_.get(), infoMap_.get());
 }
 }
 
 
 TriangleMeshData::TriangleMeshData(CustomGeometry* custom)
 TriangleMeshData::TriangleMeshData(CustomGeometry* custom)
 {
 {
-    meshInterface_ = new TriangleMeshInterface(custom);
-    shape_ = new btBvhTriangleMeshShape(meshInterface_.Get(), meshInterface_->useQuantize_, true);
+    meshInterface_ = make_unique<TriangleMeshInterface>(custom);
+    shape_ = make_unique<btBvhTriangleMeshShape>(meshInterface_.get(), meshInterface_->useQuantize_, true);
 
 
-    infoMap_ = new btTriangleInfoMap();
-    btGenerateInternalEdgeInfo(shape_.Get(), infoMap_.Get());
+    infoMap_ = make_unique<btTriangleInfoMap>();
+    btGenerateInternalEdgeInfo(shape_.get(), infoMap_.get());
 }
 }
 
 
 GImpactMeshData::GImpactMeshData(Model* model, unsigned lodLevel)
 GImpactMeshData::GImpactMeshData(Model* model, unsigned lodLevel)
 {
 {
-    meshInterface_ = new TriangleMeshInterface(model, lodLevel);
+    meshInterface_ = make_unique<TriangleMeshInterface>(model, lodLevel);
 }
 }
 
 
 GImpactMeshData::GImpactMeshData(CustomGeometry* custom)
 GImpactMeshData::GImpactMeshData(CustomGeometry* custom)
 {
 {
-    meshInterface_ = new TriangleMeshInterface(custom);
+    meshInterface_ = make_unique<TriangleMeshInterface>(custom);
 }
 }
 
 
 ConvexData::ConvexData(Model* model, unsigned lodLevel)
 ConvexData::ConvexData(Model* model, unsigned lodLevel)
@@ -431,7 +433,7 @@ btCollisionShape* CreateCollisionGeometryDataShape(ShapeType shapeType, Collisio
     case SHAPE_TRIANGLEMESH:
     case SHAPE_TRIANGLEMESH:
         {
         {
             auto* triMesh = static_cast<TriangleMeshData*>(geometry);
             auto* triMesh = static_cast<TriangleMeshData*>(geometry);
-            return new btScaledBvhTriangleMeshShape(triMesh->shape_.Get(), ToBtVector3(scale));
+            return new btScaledBvhTriangleMeshShape(triMesh->shape_.get(), ToBtVector3(scale));
         }
         }
     case SHAPE_CONVEXHULL:
     case SHAPE_CONVEXHULL:
         {
         {
@@ -443,7 +445,7 @@ btCollisionShape* CreateCollisionGeometryDataShape(ShapeType shapeType, Collisio
     case SHAPE_GIMPACTMESH:
     case SHAPE_GIMPACTMESH:
         {
         {
             auto* gimpactMesh = static_cast<GImpactMeshData*>(geometry);
             auto* gimpactMesh = static_cast<GImpactMeshData*>(geometry);
-            auto* shape = new btGImpactMeshShape(gimpactMesh->meshInterface_.Get());
+            auto* shape = new btGImpactMeshShape(gimpactMesh->meshInterface_.get());
             shape->setLocalScaling(ToBtVector3(scale));
             shape->setLocalScaling(ToBtVector3(scale));
             shape->updateBound();
             shape->updateBound();
             return shape;
             return shape;
@@ -559,7 +561,7 @@ void CollisionShape::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
             Quaternion worldRotation(worldTransform.Rotation() * rotation_);
             Quaternion worldRotation(worldTransform.Rotation() * rotation_);
 
 
             btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
             btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
-            world->debugDrawObject(btTransform(ToBtQuaternion(worldRotation), ToBtVector3(worldPosition)), shape_.Get(), bodyActive ?
+            world->debugDrawObject(btTransform(ToBtQuaternion(worldRotation), ToBtVector3(worldPosition)), shape_.get(), bodyActive ?
                 WHITE : GREEN);
                 WHITE : GREEN);
 
 
             physicsWorld_->SetDebugRenderer(nullptr);
             physicsWorld_->SetDebugRenderer(nullptr);
@@ -848,7 +850,7 @@ void CollisionShape::NotifyRigidBody(bool updateMass)
     if (node_ && shape_ && compound)
     if (node_ && shape_ && compound)
     {
     {
         // Remove the shape first to ensure it is not added twice
         // Remove the shape first to ensure it is not added twice
-        compound->removeChildShape(shape_.Get());
+        compound->removeChildShape(shape_.get());
 
 
         if (IsEnabledEffective())
         if (IsEnabledEffective())
         {
         {
@@ -864,7 +866,7 @@ void CollisionShape::NotifyRigidBody(bool updateMass)
             btTransform offset;
             btTransform offset;
             offset.setOrigin(ToBtVector3(node_->GetWorldScale() * position));
             offset.setOrigin(ToBtVector3(node_->GetWorldScale() * position));
             offset.setRotation(ToBtQuaternion(rotation_));
             offset.setRotation(ToBtQuaternion(rotation_));
-            compound->addChildShape(offset, shape_.Get());
+            compound->addChildShape(offset, shape_.get());
         }
         }
 
 
         // Finally tell the rigid body to update its mass
         // Finally tell the rigid body to update its mass
@@ -891,12 +893,11 @@ void CollisionShape::ReleaseShape()
     btCompoundShape* compound = GetParentCompoundShape();
     btCompoundShape* compound = GetParentCompoundShape();
     if (shape_ && compound)
     if (shape_ && compound)
     {
     {
-        compound->removeChildShape(shape_.Get());
+        compound->removeChildShape(shape_.get());
         rigidBody_->UpdateMass();
         rigidBody_->UpdateMass();
     }
     }
 
 
-    shape_.Reset();
-
+    shape_.reset();
     geometry_.Reset();
     geometry_.Reset();
 
 
     if (physicsWorld_)
     if (physicsWorld_)
@@ -1018,31 +1019,31 @@ void CollisionShape::UpdateShape()
         switch (shapeType_)
         switch (shapeType_)
         {
         {
         case SHAPE_BOX:
         case SHAPE_BOX:
-            shape_ = new btBoxShape(ToBtVector3(size_ * 0.5f));
+            shape_ = make_unique<btBoxShape>(ToBtVector3(size_ * 0.5f));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             break;
             break;
 
 
         case SHAPE_SPHERE:
         case SHAPE_SPHERE:
-            shape_ = new btSphereShape(size_.x_ * 0.5f);
+            shape_ = make_unique<btSphereShape>(size_.x_ * 0.5f);
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             break;
             break;
 
 
         case SHAPE_STATICPLANE:
         case SHAPE_STATICPLANE:
-            shape_ = new btStaticPlaneShape(btVector3(0.0f, 1.0f, 0.0f), 0.0f);
+            shape_ = make_unique<btStaticPlaneShape>(btVector3(0.0f, 1.0f, 0.0f), 0.0f);
             break;
             break;
 
 
         case SHAPE_CYLINDER:
         case SHAPE_CYLINDER:
-            shape_ = new btCylinderShape(btVector3(size_.x_ * 0.5f, size_.y_ * 0.5f, size_.x_ * 0.5f));
+            shape_ = make_unique<btCylinderShape>(btVector3(size_.x_ * 0.5f, size_.y_ * 0.5f, size_.x_ * 0.5f));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             break;
             break;
 
 
         case SHAPE_CAPSULE:
         case SHAPE_CAPSULE:
-            shape_ = new btCapsuleShape(size_.x_ * 0.5f, Max(size_.y_ - size_.x_, 0.0f));
+            shape_ = make_unique<btCapsuleShape>(size_.x_ * 0.5f, Max(size_.y_ - size_.x_, 0.0f));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             break;
             break;
 
 
         case SHAPE_CONE:
         case SHAPE_CONE:
-            shape_ = new btConeShape(size_.x_ * 0.5f, size_.y_);
+            shape_ = make_unique<btConeShape>(size_.x_ * 0.5f, size_.y_);
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             shape_->setLocalScaling(ToBtVector3(cachedWorldScale_));
             break;
             break;
 
 
@@ -1067,9 +1068,10 @@ void CollisionShape::UpdateShape()
                     geometry_ = new HeightfieldData(terrain, lodLevel_);
                     geometry_ = new HeightfieldData(terrain, lodLevel_);
                     auto* heightfield = static_cast<HeightfieldData*>(geometry_.Get());
                     auto* heightfield = static_cast<HeightfieldData*>(geometry_.Get());
 
 
-                    shape_ =
-                        new btHeightfieldTerrainShape(heightfield->size_.x_, heightfield->size_.y_, heightfield->heightData_.Get(),
-                            1.0f, heightfield->minHeight_, heightfield->maxHeight_, 1, PHY_FLOAT, false);
+                    shape_ = make_unique<btHeightfieldTerrainShape>(
+                        heightfield->size_.x_, heightfield->size_.y_, heightfield->heightData_.Get(),
+                        1.0f, heightfield->minHeight_, heightfield->maxHeight_, 1, PHY_FLOAT, false);
+                    
                     shape_->setLocalScaling(
                     shape_->setLocalScaling(
                         ToBtVector3(Vector3(heightfield->spacing_.x_, 1.0f, heightfield->spacing_.z_) * cachedWorldScale_ * size_));
                         ToBtVector3(Vector3(heightfield->spacing_.x_, 1.0f, heightfield->spacing_.z_) * cachedWorldScale_ * size_));
                 }
                 }
@@ -1077,7 +1079,7 @@ void CollisionShape::UpdateShape()
             break;
             break;
 
 
         default:
         default:
-            shape_ = this->UpdateDerivedShape(shapeType_, cachedWorldScale_);
+            shape_.reset(this->UpdateDerivedShape(shapeType_, cachedWorldScale_));
             break;
             break;
         }
         }
 
 
@@ -1106,7 +1108,8 @@ void CollisionShape::UpdateCachedGeometryShape(CollisionGeometryDataCache& cache
         {
         {
             geometry_ = CreateCollisionGeometryData(shapeType_, custom);
             geometry_ = CreateCollisionGeometryData(shapeType_, custom);
             assert(geometry_);
             assert(geometry_);
-            shape_ = CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_);
+            
+            shape_.reset(CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_));
             assert(shape_);
             assert(shape_);
         }
         }
         else
         else
@@ -1129,7 +1132,7 @@ void CollisionShape::UpdateCachedGeometryShape(CollisionGeometryDataCache& cache
                 cache[id] = geometry_;
                 cache[id] = geometry_;
         }
         }
 
 
-        shape_ = CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_);
+        shape_.reset(CreateCollisionGeometryDataShape(shapeType_, geometry_.Get(), cachedWorldScale_ * size_));
         assert(shape_);
         assert(shape_);
         // Watch for live reloads of the collision model to reload the geometry if necessary
         // Watch for live reloads of the collision model to reload the geometry if necessary
         SubscribeToEvent(model_, E_RELOADFINISHED, URHO3D_HANDLER(CollisionShape, HandleModelReloadFinished));
         SubscribeToEvent(model_, E_RELOADFINISHED, URHO3D_HANDLER(CollisionShape, HandleModelReloadFinished));

+ 16 - 6
Source/Urho3D/Physics/CollisionShape.h

@@ -29,6 +29,8 @@
 #include "../Math/Quaternion.h"
 #include "../Math/Quaternion.h"
 #include "../Scene/Component.h"
 #include "../Scene/Component.h"
 
 
+#include <memory>
+
 class btBvhTriangleMeshShape;
 class btBvhTriangleMeshShape;
 class btCollisionShape;
 class btCollisionShape;
 class btCompoundShape;
 class btCompoundShape;
@@ -81,11 +83,13 @@ struct TriangleMeshData : public CollisionGeometryData
     explicit TriangleMeshData(CustomGeometry* custom);
     explicit TriangleMeshData(CustomGeometry* custom);
 
 
     /// Bullet triangle mesh interface.
     /// Bullet triangle mesh interface.
-    UniquePtr<TriangleMeshInterface> meshInterface_;
+    std::unique_ptr<TriangleMeshInterface> meshInterface_;
+    
     /// Bullet triangle mesh collision shape.
     /// Bullet triangle mesh collision shape.
-    UniquePtr<btBvhTriangleMeshShape> shape_;
+    std::unique_ptr<btBvhTriangleMeshShape> shape_;
+    
     /// Bullet triangle info map.
     /// Bullet triangle info map.
-    UniquePtr<btTriangleInfoMap> infoMap_;
+    std::unique_ptr<btTriangleInfoMap> infoMap_;
 };
 };
 
 
 /// Triangle mesh geometry data.
 /// Triangle mesh geometry data.
@@ -97,7 +101,7 @@ struct GImpactMeshData : public CollisionGeometryData
     explicit GImpactMeshData(CustomGeometry* custom);
     explicit GImpactMeshData(CustomGeometry* custom);
 
 
     /// Bullet triangle mesh interface.
     /// Bullet triangle mesh interface.
-    UniquePtr<TriangleMeshInterface> meshInterface_;
+    std::unique_ptr<TriangleMeshInterface> meshInterface_;
 };
 };
 
 
 /// Convex hull geometry data.
 /// Convex hull geometry data.
@@ -217,7 +221,7 @@ public:
     void SetLodLevel(unsigned lodLevel);
     void SetLodLevel(unsigned lodLevel);
 
 
     /// Return Bullet collision shape.
     /// Return Bullet collision shape.
-    btCollisionShape* GetCollisionShape() const { return shape_.Get(); }
+    btCollisionShape* GetCollisionShape() const { return shape_.get(); }
 
 
     /// Return the shared geometry data.
     /// Return the shared geometry data.
     CollisionGeometryData* GetGeometryData() const { return geometry_; }
     CollisionGeometryData* GetGeometryData() const { return geometry_; }
@@ -304,16 +308,22 @@ private:
 
 
     /// Physics world.
     /// Physics world.
     WeakPtr<PhysicsWorld> physicsWorld_;
     WeakPtr<PhysicsWorld> physicsWorld_;
+    
     /// Rigid body.
     /// Rigid body.
     WeakPtr<RigidBody> rigidBody_;
     WeakPtr<RigidBody> rigidBody_;
+    
     /// Model.
     /// Model.
     SharedPtr<Model> model_;
     SharedPtr<Model> model_;
+    
     /// Shared geometry data.
     /// Shared geometry data.
     SharedPtr<CollisionGeometryData> geometry_;
     SharedPtr<CollisionGeometryData> geometry_;
+    
     /// Bullet collision shape.
     /// Bullet collision shape.
-    UniquePtr<btCollisionShape> shape_;
+    std::unique_ptr<btCollisionShape> shape_;
+    
     /// Collision shape type.
     /// Collision shape type.
     ShapeType shapeType_;
     ShapeType shapeType_;
+    
     /// Offset position.
     /// Offset position.
     Vector3 position_;
     Vector3 position_;
     /// Offset rotation.
     /// Offset rotation.

+ 17 - 15
Source/Urho3D/Physics/Constraint.cpp

@@ -38,6 +38,8 @@
 #include <Bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.h>
 #include <Bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.h>
 #include <Bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
 #include <Bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -141,7 +143,7 @@ void Constraint::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
     {
     {
         physicsWorld_->SetDebugRenderer(debug);
         physicsWorld_->SetDebugRenderer(debug);
         physicsWorld_->SetDebugDepthTest(depthTest);
         physicsWorld_->SetDebugDepthTest(depthTest);
-        physicsWorld_->GetWorld()->debugDrawConstraint(constraint_.Get());
+        physicsWorld_->GetWorld()->debugDrawConstraint(constraint_.get());
         physicsWorld_->SetDebugRenderer(nullptr);
         physicsWorld_->SetDebugRenderer(nullptr);
     }
     }
 }
 }
@@ -354,9 +356,9 @@ void Constraint::ReleaseConstraint()
             otherBody_->RemoveConstraint(this);
             otherBody_->RemoveConstraint(this);
 
 
         if (physicsWorld_)
         if (physicsWorld_)
-            physicsWorld_->GetWorld()->removeConstraint(constraint_.Get());
+            physicsWorld_->GetWorld()->removeConstraint(constraint_.get());
 
 
-        constraint_.Reset();
+        constraint_.reset();
     }
     }
 }
 }
 
 
@@ -375,7 +377,7 @@ void Constraint::ApplyFrames()
     {
     {
     case POINT2POINT_CONSTRAINT_TYPE:
     case POINT2POINT_CONSTRAINT_TYPE:
         {
         {
-            auto* pointConstraint = static_cast<btPoint2PointConstraint*>(constraint_.Get());
+            auto* pointConstraint = static_cast<btPoint2PointConstraint*>(constraint_.get());
             pointConstraint->setPivotA(ToBtVector3(ownBodyScaledPosition));
             pointConstraint->setPivotA(ToBtVector3(ownBodyScaledPosition));
             pointConstraint->setPivotB(ToBtVector3(otherBodyScaledPosition));
             pointConstraint->setPivotB(ToBtVector3(otherBodyScaledPosition));
         }
         }
@@ -383,7 +385,7 @@ void Constraint::ApplyFrames()
 
 
     case HINGE_CONSTRAINT_TYPE:
     case HINGE_CONSTRAINT_TYPE:
         {
         {
-            auto* hingeConstraint = static_cast<btHingeConstraint*>(constraint_.Get());
+            auto* hingeConstraint = static_cast<btHingeConstraint*>(constraint_.get());
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             hingeConstraint->setFrames(ownFrame, otherFrame);
             hingeConstraint->setFrames(ownFrame, otherFrame);
@@ -392,7 +394,7 @@ void Constraint::ApplyFrames()
 
 
     case SLIDER_CONSTRAINT_TYPE:
     case SLIDER_CONSTRAINT_TYPE:
         {
         {
-            auto* sliderConstraint = static_cast<btSliderConstraint*>(constraint_.Get());
+            auto* sliderConstraint = static_cast<btSliderConstraint*>(constraint_.get());
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             sliderConstraint->setFrames(ownFrame, otherFrame);
             sliderConstraint->setFrames(ownFrame, otherFrame);
@@ -401,7 +403,7 @@ void Constraint::ApplyFrames()
 
 
     case CONETWIST_CONSTRAINT_TYPE:
     case CONETWIST_CONSTRAINT_TYPE:
         {
         {
-            auto* coneTwistConstraint = static_cast<btConeTwistConstraint*>(constraint_.Get());
+            auto* coneTwistConstraint = static_cast<btConeTwistConstraint*>(constraint_.get());
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             coneTwistConstraint->setFrames(ownFrame, otherFrame);
             coneTwistConstraint->setFrames(ownFrame, otherFrame);
@@ -485,7 +487,7 @@ void Constraint::CreateConstraint()
     {
     {
     case CONSTRAINT_POINT:
     case CONSTRAINT_POINT:
         {
         {
-            constraint_ = new btPoint2PointConstraint(*ownBody, *otherBody, ToBtVector3(ownBodyScaledPosition),
+            constraint_ = make_unique<btPoint2PointConstraint>(*ownBody, *otherBody, ToBtVector3(ownBodyScaledPosition),
                 ToBtVector3(otherBodyScaledPosition));
                 ToBtVector3(otherBodyScaledPosition));
         }
         }
         break;
         break;
@@ -494,7 +496,7 @@ void Constraint::CreateConstraint()
         {
         {
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
-            constraint_ = new btHingeConstraint(*ownBody, *otherBody, ownFrame, otherFrame);
+            constraint_ = make_unique<btHingeConstraint>(*ownBody, *otherBody, ownFrame, otherFrame);
         }
         }
         break;
         break;
 
 
@@ -502,7 +504,7 @@ void Constraint::CreateConstraint()
         {
         {
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
-            constraint_ = new btSliderConstraint(*ownBody, *otherBody, ownFrame, otherFrame, false);
+            constraint_ = make_unique<btSliderConstraint>(*ownBody, *otherBody, ownFrame, otherFrame, false);
         }
         }
         break;
         break;
 
 
@@ -510,7 +512,7 @@ void Constraint::CreateConstraint()
         {
         {
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform ownFrame(ToBtQuaternion(rotation_), ToBtVector3(ownBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
             btTransform otherFrame(ToBtQuaternion(otherRotation_), ToBtVector3(otherBodyScaledPosition));
-            constraint_ = new btConeTwistConstraint(*ownBody, *otherBody, ownFrame, otherFrame);
+            constraint_ = make_unique<btConeTwistConstraint>(*ownBody, *otherBody, ownFrame, otherFrame);
         }
         }
         break;
         break;
 
 
@@ -528,7 +530,7 @@ void Constraint::CreateConstraint()
 
 
         ApplyLimits();
         ApplyLimits();
 
 
-        physicsWorld_->GetWorld()->addConstraint(constraint_.Get(), disableCollision_);
+        physicsWorld_->GetWorld()->addConstraint(constraint_.get(), disableCollision_);
     }
     }
 
 
     recreateConstraint_ = false;
     recreateConstraint_ = false;
@@ -545,14 +547,14 @@ void Constraint::ApplyLimits()
     {
     {
     case HINGE_CONSTRAINT_TYPE:
     case HINGE_CONSTRAINT_TYPE:
         {
         {
-            auto* hingeConstraint = static_cast<btHingeConstraint*>(constraint_.Get());
+            auto* hingeConstraint = static_cast<btHingeConstraint*>(constraint_.get());
             hingeConstraint->setLimit(lowLimit_.x_ * M_DEGTORAD, highLimit_.x_ * M_DEGTORAD);
             hingeConstraint->setLimit(lowLimit_.x_ * M_DEGTORAD, highLimit_.x_ * M_DEGTORAD);
         }
         }
         break;
         break;
 
 
     case SLIDER_CONSTRAINT_TYPE:
     case SLIDER_CONSTRAINT_TYPE:
         {
         {
-            auto* sliderConstraint = static_cast<btSliderConstraint*>(constraint_.Get());
+            auto* sliderConstraint = static_cast<btSliderConstraint*>(constraint_.get());
             sliderConstraint->setUpperLinLimit(highLimit_.x_);
             sliderConstraint->setUpperLinLimit(highLimit_.x_);
             sliderConstraint->setUpperAngLimit(highLimit_.y_ * M_DEGTORAD);
             sliderConstraint->setUpperAngLimit(highLimit_.y_ * M_DEGTORAD);
             sliderConstraint->setLowerLinLimit(lowLimit_.x_);
             sliderConstraint->setLowerLinLimit(lowLimit_.x_);
@@ -562,7 +564,7 @@ void Constraint::ApplyLimits()
 
 
     case CONETWIST_CONSTRAINT_TYPE:
     case CONETWIST_CONSTRAINT_TYPE:
         {
         {
-            auto* coneTwistConstraint = static_cast<btConeTwistConstraint*>(constraint_.Get());
+            auto* coneTwistConstraint = static_cast<btConeTwistConstraint*>(constraint_.get());
             coneTwistConstraint->setLimit(highLimit_.y_ * M_DEGTORAD, highLimit_.y_ * M_DEGTORAD, highLimit_.x_ * M_DEGTORAD);
             coneTwistConstraint->setLimit(highLimit_.y_ * M_DEGTORAD, highLimit_.y_ * M_DEGTORAD, highLimit_.x_ * M_DEGTORAD);
         }
         }
         break;
         break;

+ 6 - 2
Source/Urho3D/Physics/Constraint.h

@@ -27,6 +27,8 @@
 #include "../Math/Vector3.h"
 #include "../Math/Vector3.h"
 #include "../Scene/Component.h"
 #include "../Scene/Component.h"
 
 
+#include <memory>
+
 class btTypedConstraint;
 class btTypedConstraint;
 
 
 namespace Urho3D
 namespace Urho3D
@@ -116,7 +118,7 @@ public:
     PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
     PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
 
 
     /// Return Bullet constraint.
     /// Return Bullet constraint.
-    btTypedConstraint* GetConstraint() const { return constraint_.Get(); }
+    btTypedConstraint* GetConstraint() const { return constraint_.get(); }
 
 
     /// Return constraint type.
     /// Return constraint type.
     /// @property
     /// @property
@@ -201,8 +203,10 @@ private:
     WeakPtr<RigidBody> ownBody_;
     WeakPtr<RigidBody> ownBody_;
     /// Other rigid body.
     /// Other rigid body.
     WeakPtr<RigidBody> otherBody_;
     WeakPtr<RigidBody> otherBody_;
+    
     /// Bullet constraint.
     /// Bullet constraint.
-    UniquePtr<btTypedConstraint> constraint_;
+    std::unique_ptr<btTypedConstraint> constraint_;
+    
     /// Constraint type.
     /// Constraint type.
     ConstraintType constraintType_;
     ConstraintType constraintType_;
     /// Constraint position.
     /// Constraint position.

+ 19 - 17
Source/Urho3D/Physics/PhysicsWorld.cpp

@@ -50,6 +50,8 @@
 
 
 extern ContactAddedCallback gContactAddedCallback;
 extern ContactAddedCallback gContactAddedCallback;
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -156,12 +158,12 @@ PhysicsWorld::PhysicsWorld(Context* context) :
     else
     else
         collisionConfiguration_ = new btDefaultCollisionConfiguration();
         collisionConfiguration_ = new btDefaultCollisionConfiguration();
 
 
-    collisionDispatcher_ = new btCollisionDispatcher(collisionConfiguration_);
-    btGImpactCollisionAlgorithm::registerAlgorithm(static_cast<btCollisionDispatcher*>(collisionDispatcher_.Get()));
+    collisionDispatcher_ = make_unique<btCollisionDispatcher>(collisionConfiguration_);
+    btGImpactCollisionAlgorithm::registerAlgorithm(static_cast<btCollisionDispatcher*>(collisionDispatcher_.get()));
 
 
-    broadphase_ = new btDbvtBroadphase();
-    solver_ = new btSequentialImpulseConstraintSolver();
-    world_ = new btDiscreteDynamicsWorld(collisionDispatcher_.Get(), broadphase_.Get(), solver_.Get(), collisionConfiguration_);
+    broadphase_ = make_unique<btDbvtBroadphase>();
+    solver_ = make_unique<btSequentialImpulseConstraintSolver>();
+    world_ = make_unique<btDiscreteDynamicsWorld>(collisionDispatcher_.get(), broadphase_.get(), solver_.get(), collisionConfiguration_);
 
 
     world_->setGravity(ToBtVector3(DEFAULT_GRAVITY));
     world_->setGravity(ToBtVector3(DEFAULT_GRAVITY));
     world_->getDispatchInfo().m_useContinuous = true;
     world_->getDispatchInfo().m_useContinuous = true;
@@ -187,10 +189,10 @@ PhysicsWorld::~PhysicsWorld()
             (*i)->ReleaseShape();
             (*i)->ReleaseShape();
     }
     }
 
 
-    world_.Reset();
-    solver_.Reset();
-    broadphase_.Reset();
-    collisionDispatcher_.Reset();
+    world_.reset();
+    solver_.reset();
+    broadphase_.reset();
+    collisionDispatcher_.reset();
 
 
     // Delete configuration only if it was the default created by PhysicsWorld
     // Delete configuration only if it was the default created by PhysicsWorld
     if (!PhysicsWorld::config.collisionConfig_)
     if (!PhysicsWorld::config.collisionConfig_)
@@ -625,16 +627,16 @@ void PhysicsWorld::GetRigidBodies(PODVector<RigidBody*>& result, const Sphere& s
     result.Clear();
     result.Clear();
 
 
     btSphereShape sphereShape(sphere.radius_);
     btSphereShape sphereShape(sphere.radius_);
-    UniquePtr<btRigidBody> tempRigidBody(new btRigidBody(1.0f, nullptr, &sphereShape));
+    unique_ptr<btRigidBody> tempRigidBody(new btRigidBody(1.0f, nullptr, &sphereShape));
     tempRigidBody->setWorldTransform(btTransform(btQuaternion::getIdentity(), ToBtVector3(sphere.center_)));
     tempRigidBody->setWorldTransform(btTransform(btQuaternion::getIdentity(), ToBtVector3(sphere.center_)));
     // Need to activate the temporary rigid body to get reliable results from static, sleeping objects
     // Need to activate the temporary rigid body to get reliable results from static, sleeping objects
     tempRigidBody->activate();
     tempRigidBody->activate();
-    world_->addRigidBody(tempRigidBody.Get());
+    world_->addRigidBody(tempRigidBody.get());
 
 
     PhysicsQueryCallback callback(result, collisionMask);
     PhysicsQueryCallback callback(result, collisionMask);
-    world_->contactTest(tempRigidBody.Get(), callback);
+    world_->contactTest(tempRigidBody.get(), callback);
 
 
-    world_->removeRigidBody(tempRigidBody.Get());
+    world_->removeRigidBody(tempRigidBody.get());
 }
 }
 
 
 void PhysicsWorld::GetRigidBodies(PODVector<RigidBody*>& result, const BoundingBox& box, unsigned collisionMask)
 void PhysicsWorld::GetRigidBodies(PODVector<RigidBody*>& result, const BoundingBox& box, unsigned collisionMask)
@@ -644,15 +646,15 @@ void PhysicsWorld::GetRigidBodies(PODVector<RigidBody*>& result, const BoundingB
     result.Clear();
     result.Clear();
 
 
     btBoxShape boxShape(ToBtVector3(box.HalfSize()));
     btBoxShape boxShape(ToBtVector3(box.HalfSize()));
-    UniquePtr<btRigidBody> tempRigidBody(new btRigidBody(1.0f, nullptr, &boxShape));
+    unique_ptr<btRigidBody> tempRigidBody(new btRigidBody(1.0f, nullptr, &boxShape));
     tempRigidBody->setWorldTransform(btTransform(btQuaternion::getIdentity(), ToBtVector3(box.Center())));
     tempRigidBody->setWorldTransform(btTransform(btQuaternion::getIdentity(), ToBtVector3(box.Center())));
     tempRigidBody->activate();
     tempRigidBody->activate();
-    world_->addRigidBody(tempRigidBody.Get());
+    world_->addRigidBody(tempRigidBody.get());
 
 
     PhysicsQueryCallback callback(result, collisionMask);
     PhysicsQueryCallback callback(result, collisionMask);
-    world_->contactTest(tempRigidBody.Get(), callback);
+    world_->contactTest(tempRigidBody.get(), callback);
 
 
-    world_->removeRigidBody(tempRigidBody.Get());
+    world_->removeRigidBody(tempRigidBody.get());
 }
 }
 
 
 void PhysicsWorld::GetRigidBodies(PODVector<RigidBody*>& result, const RigidBody* body)
 void PhysicsWorld::GetRigidBodies(PODVector<RigidBody*>& result, const RigidBody* body)

+ 12 - 5
Source/Urho3D/Physics/PhysicsWorld.h

@@ -31,6 +31,8 @@
 
 
 #include <Bullet/LinearMath/btIDebugDraw.h>
 #include <Bullet/LinearMath/btIDebugDraw.h>
 
 
+#include <memory>
+
 class btCollisionConfiguration;
 class btCollisionConfiguration;
 class btCollisionShape;
 class btCollisionShape;
 class btBroadphaseInterface;
 class btBroadphaseInterface;
@@ -277,7 +279,7 @@ public:
     void SetDebugDepthTest(bool enable);
     void SetDebugDepthTest(bool enable);
 
 
     /// Return the Bullet physics world.
     /// Return the Bullet physics world.
-    btDiscreteDynamicsWorld* GetWorld() { return world_.Get(); }
+    btDiscreteDynamicsWorld* GetWorld() { return world_.get(); }
 
 
     /// Clean up the geometry cache.
     /// Clean up the geometry cache.
     void CleanupGeometryCache();
     void CleanupGeometryCache();
@@ -319,14 +321,19 @@ private:
 
 
     /// Bullet collision configuration.
     /// Bullet collision configuration.
     btCollisionConfiguration* collisionConfiguration_{};
     btCollisionConfiguration* collisionConfiguration_{};
+    
     /// Bullet collision dispatcher.
     /// Bullet collision dispatcher.
-    UniquePtr<btDispatcher> collisionDispatcher_;
+    std::unique_ptr<btDispatcher> collisionDispatcher_;
+    
     /// Bullet collision broadphase.
     /// Bullet collision broadphase.
-    UniquePtr<btBroadphaseInterface> broadphase_;
+    std::unique_ptr<btBroadphaseInterface> broadphase_;
+    
     /// Bullet constraint solver.
     /// Bullet constraint solver.
-    UniquePtr<btConstraintSolver> solver_;
+    std::unique_ptr<btConstraintSolver> solver_;
+    
     /// Bullet physics world.
     /// Bullet physics world.
-    UniquePtr<btDiscreteDynamicsWorld> world_;
+    std::unique_ptr<btDiscreteDynamicsWorld> world_;
+    
     /// Extra weak pointer to scene to allow for cleanup in case the world is destroyed before other components.
     /// Extra weak pointer to scene to allow for cleanup in case the world is destroyed before other components.
     WeakPtr<Scene> scene_;
     WeakPtr<Scene> scene_;
     /// Rigid bodies in the world.
     /// Rigid bodies in the world.

+ 12 - 10
Source/Urho3D/Physics/RigidBody.cpp

@@ -41,6 +41,8 @@
 #include <Bullet/BulletDynamics/Dynamics/btRigidBody.h>
 #include <Bullet/BulletDynamics/Dynamics/btRigidBody.h>
 #include <Bullet/BulletCollision/CollisionShapes/btCompoundShape.h>
 #include <Bullet/BulletCollision/CollisionShapes/btCompoundShape.h>
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -79,8 +81,8 @@ RigidBody::RigidBody(Context* context) :
     enableMassUpdate_(true),
     enableMassUpdate_(true),
     hasSimulated_(false)
     hasSimulated_(false)
 {
 {
-    compoundShape_ = new btCompoundShape();
-    shiftedCompoundShape_ = new btCompoundShape();
+    compoundShape_ = make_unique<btCompoundShape>();
+    shiftedCompoundShape_ = make_unique<btCompoundShape>();
 }
 }
 
 
 RigidBody::~RigidBody()
 RigidBody::~RigidBody()
@@ -204,7 +206,7 @@ void RigidBody::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
         physicsWorld_->SetDebugDepthTest(depthTest);
         physicsWorld_->SetDebugDepthTest(depthTest);
 
 
         btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
         btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
-        world->debugDrawObject(body_->getWorldTransform(), shiftedCompoundShape_.Get(), IsActive() ? btVector3(1.0f, 1.0f, 1.0f) :
+        world->debugDrawObject(body_->getWorldTransform(), shiftedCompoundShape_.get(), IsActive() ? btVector3(1.0f, 1.0f, 1.0f) :
             btVector3(0.0f, 1.0f, 0.0f));
             btVector3(0.0f, 1.0f, 0.0f));
 
 
         physicsWorld_->SetDebugRenderer(nullptr);
         physicsWorld_->SetDebugRenderer(nullptr);
@@ -782,7 +784,7 @@ void RigidBody::UpdateMass()
     }
     }
 
 
     btCollisionShape* oldCollisionShape = body_->getCollisionShape();
     btCollisionShape* oldCollisionShape = body_->getCollisionShape();
-    body_->setCollisionShape(useCompound ? shiftedCompoundShape_.Get() : shiftedCompoundShape_->getChildShape(0));
+    body_->setCollisionShape(useCompound ? shiftedCompoundShape_.get() : shiftedCompoundShape_->getChildShape(0));
 
 
     // If we have one shape and this is a triangle mesh, we use a custom material callback in order to adjust internal edges
     // If we have one shape and this is a triangle mesh, we use a custom material callback in order to adjust internal edges
     if (!useCompound && body_->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE &&
     if (!useCompound && body_->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE &&
@@ -814,8 +816,8 @@ void RigidBody::UpdateMass()
     if (inWorld_ && body_->getCollisionShape() != oldCollisionShape && physicsWorld_)
     if (inWorld_ && body_->getCollisionShape() != oldCollisionShape && physicsWorld_)
     {
     {
         btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
         btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
-        world->removeRigidBody(body_.Get());
-        world->addRigidBody(body_.Get(), (short)collisionLayer_, (short)collisionMask_);
+        world->removeRigidBody(body_.get());
+        world->addRigidBody(body_.get(), (short)collisionLayer_, (short)collisionMask_);
     }
     }
 }
 }
 
 
@@ -884,7 +886,7 @@ void RigidBody::ReleaseBody()
 
 
         RemoveBodyFromWorld();
         RemoveBodyFromWorld();
 
 
-        body_.Reset();
+        body_.reset();
     }
     }
 }
 }
 
 
@@ -965,7 +967,7 @@ void RigidBody::AddBodyToWorld()
     {
     {
         // Correct inertia will be calculated below
         // Correct inertia will be calculated below
         btVector3 localInertia(0.0f, 0.0f, 0.0f);
         btVector3 localInertia(0.0f, 0.0f, 0.0f);
-        body_ = new btRigidBody(mass_, this, shiftedCompoundShape_.Get(), localInertia);
+        body_ = make_unique<btRigidBody>(mass_, this, shiftedCompoundShape_.get(), localInertia);
         body_->setUserPointer(this);
         body_->setUserPointer(this);
 
 
         // Check for existence of the SmoothedTransform component, which should be created by now in network client mode.
         // Check for existence of the SmoothedTransform component, which should be created by now in network client mode.
@@ -1011,7 +1013,7 @@ void RigidBody::AddBodyToWorld()
         return;
         return;
 
 
     btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
     btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
-    world->addRigidBody(body_.Get(), (short)collisionLayer_, (short)collisionMask_);
+    world->addRigidBody(body_.get(), (short)collisionLayer_, (short)collisionMask_);
     inWorld_ = true;
     inWorld_ = true;
     readdBody_ = false;
     readdBody_ = false;
     hasSimulated_ = false;
     hasSimulated_ = false;
@@ -1030,7 +1032,7 @@ void RigidBody::RemoveBodyFromWorld()
     if (physicsWorld_ && body_ && inWorld_)
     if (physicsWorld_ && body_ && inWorld_)
     {
     {
         btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
         btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld();
-        world->removeRigidBody(body_.Get());
+        world->removeRigidBody(body_.get());
         inWorld_ = false;
         inWorld_ = false;
     }
     }
 }
 }

+ 10 - 5
Source/Urho3D/Physics/RigidBody.h

@@ -29,6 +29,8 @@
 
 
 #include <Bullet/LinearMath/btMotionState.h>
 #include <Bullet/LinearMath/btMotionState.h>
 
 
+#include <memory>
+
 class btCompoundShape;
 class btCompoundShape;
 class btRigidBody;
 class btRigidBody;
 
 
@@ -181,10 +183,10 @@ public:
     PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
     PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
 
 
     /// Return Bullet rigid body.
     /// Return Bullet rigid body.
-    btRigidBody* GetBody() const { return body_.Get(); }
+    btRigidBody* GetBody() const { return body_.get(); }
 
 
     /// Return Bullet compound collision shape.
     /// Return Bullet compound collision shape.
-    btCompoundShape* GetCompoundShape() const { return compoundShape_.Get(); }
+    btCompoundShape* GetCompoundShape() const { return compoundShape_.get(); }
 
 
     /// Return mass.
     /// Return mass.
     /// @property
     /// @property
@@ -321,11 +323,14 @@ private:
     void MarkBodyDirty() { readdBody_ = true; }
     void MarkBodyDirty() { readdBody_ = true; }
 
 
     /// Bullet rigid body.
     /// Bullet rigid body.
-    UniquePtr<btRigidBody> body_;
+    std::unique_ptr<btRigidBody> body_;
+    
     /// Bullet compound collision shape.
     /// Bullet compound collision shape.
-    UniquePtr<btCompoundShape> compoundShape_;
+    std::unique_ptr<btCompoundShape> compoundShape_;
+    
     /// Compound collision shape with center of mass offset applied.
     /// Compound collision shape with center of mass offset applied.
-    UniquePtr<btCompoundShape> shiftedCompoundShape_;
+    std::unique_ptr<btCompoundShape> shiftedCompoundShape_;
+    
     /// Physics world.
     /// Physics world.
     WeakPtr<PhysicsWorld> physicsWorld_;
     WeakPtr<PhysicsWorld> physicsWorld_;
     /// Smoothed transform, if has one.
     /// Smoothed transform, if has one.

+ 3 - 1
Source/Urho3D/Physics2D/PhysicsWorld2D.cpp

@@ -38,6 +38,8 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -56,7 +58,7 @@ PhysicsWorld2D::PhysicsWorld2D(Context* context) :
     m_drawFlags = e_shapeBit;
     m_drawFlags = e_shapeBit;
 
 
     // Create Box2D world
     // Create Box2D world
-    world_ = new b2World(ToB2Vec2(gravity_));
+    world_ = make_unique<b2World>(ToB2Vec2(gravity_));
     // Set contact listener
     // Set contact listener
     world_->SetContactListener(this);
     world_->SetContactListener(this);
     // Set debug draw
     // Set debug draw

+ 5 - 2
Source/Urho3D/Physics2D/PhysicsWorld2D.h

@@ -27,6 +27,8 @@
 
 
 #include <Box2D/Box2D.h>
 #include <Box2D/Box2D.h>
 
 
+#include <memory>
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -226,7 +228,7 @@ public:
     int GetPositionIterations() const { return positionIterations_; }
     int GetPositionIterations() const { return positionIterations_; }
 
 
     /// Return the Box2D physics world.
     /// Return the Box2D physics world.
-    b2World* GetWorld() { return world_.Get(); }
+    b2World* GetWorld() { return world_.get(); }
 
 
     /// Set node dirtying to be disregarded.
     /// Set node dirtying to be disregarded.
     void SetApplyingTransforms(bool enable) { applyingTransforms_ = enable; }
     void SetApplyingTransforms(bool enable) { applyingTransforms_ = enable; }
@@ -246,7 +248,8 @@ protected:
     void SendEndContactEvents();
     void SendEndContactEvents();
 
 
     /// Box2D physics world.
     /// Box2D physics world.
-    UniquePtr<b2World> world_;
+    std::unique_ptr<b2World> world_;
+    
     /// Gravity.
     /// Gravity.
     Vector2 gravity_;
     Vector2 gravity_;
     /// Velocity iterations.
     /// Velocity iterations.

+ 13 - 8
Source/Urho3D/Resource/XMLElement.cpp

@@ -30,6 +30,8 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -1070,20 +1072,22 @@ XPathQuery::~XPathQuery() = default;
 void XPathQuery::Bind()
 void XPathQuery::Bind()
 {
 {
     // Delete previous query object and create a new one binding it with variable set
     // Delete previous query object and create a new one binding it with variable set
-    query_ = new pugi::xpath_query(queryString_.CString(), variables_.Get());
+    query_ = make_unique<pugi::xpath_query>(queryString_.CString(), variables_.get());
 }
 }
 
 
 bool XPathQuery::SetVariable(const String& name, bool value)
 bool XPathQuery::SetVariable(const String& name, bool value)
 {
 {
     if (!variables_)
     if (!variables_)
-        variables_ = new pugi::xpath_variable_set();
+        variables_ = make_unique<pugi::xpath_variable_set>();
+
     return variables_->set(name.CString(), value);
     return variables_->set(name.CString(), value);
 }
 }
 
 
 bool XPathQuery::SetVariable(const String& name, float value)
 bool XPathQuery::SetVariable(const String& name, float value)
 {
 {
     if (!variables_)
     if (!variables_)
-        variables_ = new pugi::xpath_variable_set();
+        variables_ = make_unique<pugi::xpath_variable_set>();
+
     return variables_->set(name.CString(), value);
     return variables_->set(name.CString(), value);
 }
 }
 
 
@@ -1095,14 +1099,15 @@ bool XPathQuery::SetVariable(const String& name, const String& value)
 bool XPathQuery::SetVariable(const char* name, const char* value)
 bool XPathQuery::SetVariable(const char* name, const char* value)
 {
 {
     if (!variables_)
     if (!variables_)
-        variables_ = new pugi::xpath_variable_set();
+        variables_ = make_unique<pugi::xpath_variable_set>();
+
     return variables_->set(name, value);
     return variables_->set(name, value);
 }
 }
 
 
 bool XPathQuery::SetVariable(const String& name, const XPathResultSet& value)
 bool XPathQuery::SetVariable(const String& name, const XPathResultSet& value)
 {
 {
     if (!variables_)
     if (!variables_)
-        variables_ = new pugi::xpath_variable_set();
+        variables_ = make_unique<pugi::xpath_variable_set>();
 
 
     pugi::xpath_node_set* nodeSet = value.GetXPathNodeSet();
     pugi::xpath_node_set* nodeSet = value.GetXPathNodeSet();
     if (!nodeSet)
     if (!nodeSet)
@@ -1116,7 +1121,7 @@ bool XPathQuery::SetQuery(const String& queryString, const String& variableStrin
     if (!variableString.Empty())
     if (!variableString.Empty())
     {
     {
         Clear();
         Clear();
-        variables_ = new pugi::xpath_variable_set();
+        variables_ = make_unique<pugi::xpath_variable_set>();
 
 
         // Parse the variable string having format "name1:type1,name2:type2,..." where type is one of "Bool", "Float", "String", "ResultSet"
         // Parse the variable string having format "name1:type1,name2:type2,..." where type is one of "Bool", "Float", "String", "ResultSet"
         Vector<String> vars = variableString.Split(',');
         Vector<String> vars = variableString.Split(',');
@@ -1155,8 +1160,8 @@ void XPathQuery::Clear()
 {
 {
     queryString_.Clear();
     queryString_.Clear();
 
 
-    variables_.Reset();
-    query_.Reset();
+    variables_.reset();
+    query_.reset();
 }
 }
 
 
 bool XPathQuery::EvaluateToBool(const XMLElement& element) const
 bool XPathQuery::EvaluateToBool(const XMLElement& element) const

+ 8 - 4
Source/Urho3D/Resource/XMLElement.h

@@ -27,6 +27,8 @@
 #include "../Math/BoundingBox.h"
 #include "../Math/BoundingBox.h"
 #include "../Math/Rect.h"
 #include "../Math/Rect.h"
 
 
+#include <memory>
+
 namespace pugi
 namespace pugi
 {
 {
 
 
@@ -403,18 +405,20 @@ public:
     String GetQuery() const { return queryString_; }
     String GetQuery() const { return queryString_; }
 
 
     /// Return pugixml xpath_query.
     /// Return pugixml xpath_query.
-    pugi::xpath_query* GetXPathQuery() const { return query_.Get(); }
+    pugi::xpath_query* GetXPathQuery() const { return query_.get(); }
 
 
     /// Return pugixml xpath_variable_set.
     /// Return pugixml xpath_variable_set.
-    pugi::xpath_variable_set* GetXPathVariableSet() const { return variables_.Get(); }
+    pugi::xpath_variable_set* GetXPathVariableSet() const { return variables_.get(); }
 
 
 private:
 private:
     /// XPath query string.
     /// XPath query string.
     String queryString_;
     String queryString_;
+    
     /// Pugixml xpath_query.
     /// Pugixml xpath_query.
-    UniquePtr<pugi::xpath_query> query_;
+    std::unique_ptr<pugi::xpath_query> query_;
+    
     /// Pugixml xpath_variable_set.
     /// Pugixml xpath_variable_set.
-    UniquePtr<pugi::xpath_variable_set> variables_;
+    std::unique_ptr<pugi::xpath_variable_set> variables_;
 };
 };
 
 
 }
 }

+ 6 - 2
Source/Urho3D/Resource/XMLFile.cpp

@@ -36,6 +36,10 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+#include <memory>
+
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -112,8 +116,8 @@ bool XMLFile::BeginLoad(Deserializer& source)
         }
         }
 
 
         // Patch this XMLFile and leave the original inherited XMLFile as it is
         // Patch this XMLFile and leave the original inherited XMLFile as it is
-        UniquePtr<pugi::xml_document> patchDocument(document_.Detach());
-        document_ = new pugi::xml_document();
+        std::unique_ptr<pugi::xml_document> patchDocument = move(document_);
+        document_ = make_unique<pugi::xml_document>();
         document_->reset(*inheritedXMLFile->document_);
         document_->reset(*inheritedXMLFile->document_);
         Patch(rootElem);
         Patch(rootElem);
 
 

+ 4 - 2
Source/Urho3D/Resource/XMLFile.h

@@ -25,6 +25,8 @@
 #include "../Resource/Resource.h"
 #include "../Resource/Resource.h"
 #include "../Resource/XMLElement.h"
 #include "../Resource/XMLElement.h"
 
 
+#include <memory>
+
 namespace pugi
 namespace pugi
 {
 {
 
 
@@ -69,7 +71,7 @@ public:
     XMLElement GetRoot(const String& name = String::EMPTY);
     XMLElement GetRoot(const String& name = String::EMPTY);
 
 
     /// Return the pugixml document.
     /// Return the pugixml document.
-    pugi::xml_document* GetDocument() const { return document_.Get(); }
+    pugi::xml_document* GetDocument() const { return document_.get(); }
 
 
     /// Serialize the XML content to a string.
     /// Serialize the XML content to a string.
     String ToString(const String& indentation = "\t") const;
     String ToString(const String& indentation = "\t") const;
@@ -95,7 +97,7 @@ private:
     bool CombineText(const pugi::xml_node& patch, const pugi::xml_node& original, bool prepend) const;
     bool CombineText(const pugi::xml_node& patch, const pugi::xml_node& original, bool prepend) const;
 
 
     /// Pugixml document.
     /// Pugixml document.
-    UniquePtr<pugi::xml_document> document_;
+    std::unique_ptr<pugi::xml_document> document_;
 };
 };
 
 
 }
 }

+ 3 - 1
Source/Urho3D/Scene/Node.cpp

@@ -38,6 +38,8 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 #ifdef _MSC_VER
 #ifdef _MSC_VER
 #pragma warning(disable:6293)
 #pragma warning(disable:6293)
 #endif
 #endif
@@ -60,7 +62,7 @@ Node::Node(Context* context) :
     scale_(Vector3::ONE),
     scale_(Vector3::ONE),
     worldRotation_(Quaternion::IDENTITY)
     worldRotation_(Quaternion::IDENTITY)
 {
 {
-    impl_ = new NodeImpl();
+    impl_ = make_unique<NodeImpl>();
     impl_->owner_ = nullptr;
     impl_->owner_ = nullptr;
 }
 }
 
 

+ 4 - 1
Source/Urho3D/Scene/Node.h

@@ -28,6 +28,8 @@
 #include "../Math/Matrix3x4.h"
 #include "../Math/Matrix3x4.h"
 #include "../Scene/Animatable.h"
 #include "../Scene/Animatable.h"
 
 
+#include <memory>
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -751,8 +753,9 @@ private:
     Vector<SharedPtr<Node> > children_;
     Vector<SharedPtr<Node> > children_;
     /// Node listeners.
     /// Node listeners.
     Vector<WeakPtr<Component> > listeners_;
     Vector<WeakPtr<Component> > listeners_;
+    
     /// Pointer to implementation.
     /// Pointer to implementation.
-    UniquePtr<NodeImpl> impl_;
+    std::unique_ptr<NodeImpl> impl_;
 
 
 protected:
 protected:
     /// User variables.
     /// User variables.

+ 5 - 3
Source/Urho3D/Scene/Serializable.cpp

@@ -34,6 +34,8 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -669,7 +671,7 @@ void Serializable::ResetToDefault()
 
 
 void Serializable::RemoveInstanceDefault()
 void Serializable::RemoveInstanceDefault()
 {
 {
-    instanceDefaultValues_.Reset();
+    instanceDefaultValues_.reset();
 }
 }
 
 
 void Serializable::SetTemporary(bool enable)
 void Serializable::SetTemporary(bool enable)
@@ -715,7 +717,7 @@ void Serializable::AllocateNetworkState()
         return;
         return;
 
 
     const Vector<AttributeInfo>* networkAttributes = GetNetworkAttributes();
     const Vector<AttributeInfo>* networkAttributes = GetNetworkAttributes();
-    networkState_ = new NetworkState();
+    networkState_ = make_unique<NetworkState>();
     networkState_->attributes_ = networkAttributes;
     networkState_->attributes_ = networkAttributes;
 
 
     if (!networkAttributes)
     if (!networkAttributes)
@@ -1020,7 +1022,7 @@ void Serializable::SetInstanceDefault(const String& name, const Variant& default
 {
 {
     // Allocate the instance level default value
     // Allocate the instance level default value
     if (!instanceDefaultValues_)
     if (!instanceDefaultValues_)
-        instanceDefaultValues_ = new VariantMap();
+        instanceDefaultValues_ = make_unique<VariantMap>();
     instanceDefaultValues_->operator [](name) = defaultValue;
     instanceDefaultValues_->operator [](name) = defaultValue;
 }
 }
 
 

+ 6 - 3
Source/Urho3D/Scene/Serializable.h

@@ -26,6 +26,7 @@
 #include "../Core/Object.h"
 #include "../Core/Object.h"
 
 
 #include <cstddef>
 #include <cstddef>
+#include <memory>
 
 
 namespace Urho3D
 namespace Urho3D
 {
 {
@@ -134,11 +135,11 @@ public:
     bool GetInterceptNetworkUpdate(const String& attributeName) const;
     bool GetInterceptNetworkUpdate(const String& attributeName) const;
 
 
     /// Return the network attribute state, if allocated.
     /// Return the network attribute state, if allocated.
-    NetworkState* GetNetworkState() const { return networkState_.Get(); }
+    NetworkState* GetNetworkState() const { return networkState_.get(); }
 
 
 protected:
 protected:
     /// Network attribute state.
     /// Network attribute state.
-    UniquePtr<NetworkState> networkState_;
+    std::unique_ptr<NetworkState> networkState_;
 
 
 private:
 private:
     /// Set instance-level default value. Allocate the internal data structure as necessary.
     /// Set instance-level default value. Allocate the internal data structure as necessary.
@@ -147,9 +148,11 @@ private:
     Variant GetInstanceDefault(const String& name) const;
     Variant GetInstanceDefault(const String& name) const;
 
 
     /// Attribute default value at each instance level.
     /// Attribute default value at each instance level.
-    UniquePtr<VariantMap> instanceDefaultValues_;
+    std::unique_ptr<VariantMap> instanceDefaultValues_;
+    
     /// When true, store the attribute value as instance's default value (internal use only).
     /// When true, store the attribute value as instance's default value (internal use only).
     bool setInstanceDefault_;
     bool setInstanceDefault_;
+    
     /// Temporary flag.
     /// Temporary flag.
     bool temporary_;
     bool temporary_;
 };
 };

+ 5 - 3
Source/Urho3D/Urho2D/AnimatedSprite2D.cpp

@@ -38,6 +38,8 @@
 #include <spine/spine.h>
 #include <spine/spine.h>
 #endif
 #endif
 
 
+using namespace std;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -135,7 +137,7 @@ void AnimatedSprite2D::SetAnimationSet(AnimationSet2D* animationSet)
 #endif
 #endif
     if (animationSet_->GetSpriterData())
     if (animationSet_->GetSpriterData())
     {
     {
-        spriterInstance_ = new Spriter::SpriterInstance(this, animationSet_->GetSpriterData());
+        spriterInstance_ = make_unique<Spriter::SpriterInstance>(this, animationSet_->GetSpriterData());
 
 
         if (!animationSet_->GetSpriterData()->entities_.Empty())
         if (!animationSet_->GetSpriterData()->entities_.Empty())
         {
         {
@@ -389,7 +391,7 @@ void AnimatedSprite2D::UpdateSourceBatchesSpine()
 void AnimatedSprite2D::SetSpriterAnimation()
 void AnimatedSprite2D::SetSpriterAnimation()
 {
 {
     if (!spriterInstance_)
     if (!spriterInstance_)
-        spriterInstance_ = new Spriter::SpriterInstance(this, animationSet_->GetSpriterData());
+        spriterInstance_ = make_unique<Spriter::SpriterInstance>(this, animationSet_->GetSpriterData());
 
 
     // Use entity is empty first entity
     // Use entity is empty first entity
     if (entity_.Empty())
     if (entity_.Empty())
@@ -514,7 +516,7 @@ void AnimatedSprite2D::Dispose()
         skeleton_ = 0;
         skeleton_ = 0;
     }
     }
 #endif
 #endif
-    spriterInstance_.Reset();
+    spriterInstance_.reset();
 }
 }
 
 
 }
 }

+ 3 - 1
Source/Urho3D/Urho2D/AnimatedSprite2D.h

@@ -26,6 +26,8 @@
 
 
 #include "../Urho2D/StaticSprite2D.h"
 #include "../Urho2D/StaticSprite2D.h"
 
 
+#include <memory>
+
 #ifdef URHO3D_SPINE
 #ifdef URHO3D_SPINE
 struct spAnimationState;
 struct spAnimationState;
 struct spAnimationStateData;
 struct spAnimationStateData;
@@ -156,7 +158,7 @@ protected:
 #endif
 #endif
 
 
     /// Spriter instance.
     /// Spriter instance.
-    UniquePtr<Spriter::SpriterInstance> spriterInstance_;
+    std::unique_ptr<Spriter::SpriterInstance> spriterInstance_;
 };
 };
 
 
 }
 }

+ 4 - 2
Source/Urho3D/Urho2D/AnimationSet2D.cpp

@@ -38,6 +38,8 @@
 
 
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
+using namespace std;
+
 #ifdef URHO3D_SPINE
 #ifdef URHO3D_SPINE
 #include <spine/spine.h>
 #include <spine/spine.h>
 #include <spine/extension.h>
 #include <spine/extension.h>
@@ -293,7 +295,7 @@ bool AnimationSet2D::BeginLoadSpriter(Deserializer& source)
     if (source.Read(buffer.Get(), dataSize) != dataSize)
     if (source.Read(buffer.Get(), dataSize) != dataSize)
         return false;
         return false;
 
 
-    spriterData_ = new Spriter::SpriterData();
+    spriterData_ = make_unique<Spriter::SpriterData>();
     if (!spriterData_->Load(buffer.Get(), dataSize))
     if (!spriterData_->Load(buffer.Get(), dataSize))
     {
     {
         URHO3D_LOGERROR("Could not spriter data from " + source.GetName());
         URHO3D_LOGERROR("Could not spriter data from " + source.GetName());
@@ -521,7 +523,7 @@ void AnimationSet2D::Dispose()
     }
     }
 #endif
 #endif
 
 
-    spriterData_.Reset();
+    spriterData_.reset();
 
 
     sprite_.Reset();
     sprite_.Reset();
     spriteSheet_.Reset();
     spriteSheet_.Reset();

+ 9 - 2
Source/Urho3D/Urho2D/AnimationSet2D.h

@@ -25,6 +25,8 @@
 #include "../Container/ArrayPtr.h"
 #include "../Container/ArrayPtr.h"
 #include "../Resource/Resource.h"
 #include "../Resource/Resource.h"
 
 
+#include <memory>
+
 #ifdef URHO3D_SPINE
 #ifdef URHO3D_SPINE
 struct spAtlas;
 struct spAtlas;
 struct spSkeletonData;
 struct spSkeletonData;
@@ -78,7 +80,8 @@ public:
 #endif
 #endif
 
 
     /// Return spriter data.
     /// Return spriter data.
-    Spriter::SpriterData* GetSpriterData() const { return spriterData_.Get(); }
+    Spriter::SpriterData* GetSpriterData() const { return spriterData_.get(); }
+    
     /// Return spriter file sprite.
     /// Return spriter file sprite.
     Sprite2D* GetSpriterFileSprite(int folderId, int fileId) const;
     Sprite2D* GetSpriterFileSprite(int folderId, int fileId) const;
 
 
@@ -111,13 +114,17 @@ private:
 #endif
 #endif
 
 
     /// Spriter data.
     /// Spriter data.
-    UniquePtr<Spriter::SpriterData> spriterData_;
+    std::unique_ptr<Spriter::SpriterData> spriterData_;
+    
     /// Has sprite sheet.
     /// Has sprite sheet.
     bool hasSpriteSheet_;
     bool hasSpriteSheet_;
+    
     /// Sprite sheet file path.
     /// Sprite sheet file path.
     String spriteSheetFilePath_;
     String spriteSheetFilePath_;
+    
     /// Sprite sheet.
     /// Sprite sheet.
     SharedPtr<SpriteSheet2D> spriteSheet_;
     SharedPtr<SpriteSheet2D> spriteSheet_;
+    
     /// Spriter sprites.
     /// Spriter sprites.
     HashMap<unsigned, SharedPtr<Sprite2D> > spriterFileSprites_;
     HashMap<unsigned, SharedPtr<Sprite2D> > spriterFileSprites_;
 };
 };