From 70304dd276314335f9b15120dee3c4412eab3b55 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 28 Aug 2018 20:01:55 +0200 Subject: [PATCH] Remove raw ptrs from PickupObject --- rwengine/src/objects/PickupObject.cpp | 14 ++++++-------- rwengine/src/objects/PickupObject.hpp | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/rwengine/src/objects/PickupObject.cpp b/rwengine/src/objects/PickupObject.cpp index 3a919cf1..6b3229bc 100644 --- a/rwengine/src/objects/PickupObject.cpp +++ b/rwengine/src/objects/PickupObject.cpp @@ -98,11 +98,11 @@ PickupObject::PickupObject(GameWorld* world, const glm::vec3& position, tf.setIdentity(); tf.setOrigin(btVector3(position.x, position.y, position.z)); - m_ghost = new btPairCachingGhostObject; + m_ghost = std::make_unique(); m_ghost->setUserPointer(this); m_ghost->setWorldTransform(tf); - m_shape = new btSphereShape(0.5f); - m_ghost->setCollisionShape(m_shape); + m_shape = std::make_unique(0.5f); + m_ghost->setCollisionShape(m_shape.get()); m_ghost->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_NO_CONTACT_RESPONSE); @@ -162,8 +162,6 @@ PickupObject::~PickupObject() { if (m_ghost) { setEnabled(false); engine->destroyEffect(m_corona); - delete m_ghost; - delete m_shape; } } @@ -212,7 +210,7 @@ void PickupObject::tick(float dt) { const btBroadphasePair& pair = pairArray[i]; auto otherObject = static_cast( - pair.m_pProxy0->m_clientObject == m_ghost + pair.m_pProxy0->m_clientObject == m_ghost.get() ? pair.m_pProxy1->m_clientObject : pair.m_pProxy0->m_clientObject); if (otherObject->getUserPointer()) { @@ -256,10 +254,10 @@ void PickupObject::tick(float dt) { void PickupObject::setEnabled(bool enabled) { if (!m_enabled && enabled) { engine->dynamicsWorld->addCollisionObject( - m_ghost, btBroadphaseProxy::SensorTrigger); + m_ghost.get(), btBroadphaseProxy::SensorTrigger); m_corona.size = glm::vec2(1.5f, 1.5f); } else if (m_enabled && !enabled) { - engine->dynamicsWorld->removeCollisionObject(m_ghost); + engine->dynamicsWorld->removeCollisionObject(m_ghost.get()); m_corona.size = glm::vec2(0.f, 0.f); } diff --git a/rwengine/src/objects/PickupObject.hpp b/rwengine/src/objects/PickupObject.hpp index 98ed3eb4..38a7bbaf 100644 --- a/rwengine/src/objects/PickupObject.hpp +++ b/rwengine/src/objects/PickupObject.hpp @@ -116,8 +116,8 @@ public: } private: - btPairCachingGhostObject* m_ghost = nullptr; - btSphereShape* m_shape = nullptr; + std::unique_ptr m_ghost; + std::unique_ptr m_shape; bool m_enabled = false; float m_enableTimer = 0.f; bool m_collected = false;