1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Remove raw ptrs from PickupObject

This commit is contained in:
Filip Gawin 2018-08-28 20:01:55 +02:00
parent 071481f617
commit 70304dd276
2 changed files with 8 additions and 10 deletions

View File

@ -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<btPairCachingGhostObject>();
m_ghost->setUserPointer(this);
m_ghost->setWorldTransform(tf);
m_shape = new btSphereShape(0.5f);
m_ghost->setCollisionShape(m_shape);
m_shape = std::make_unique<btSphereShape>(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<const btCollisionObject*>(
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);
}

View File

@ -116,8 +116,8 @@ public:
}
private:
btPairCachingGhostObject* m_ghost = nullptr;
btSphereShape* m_shape = nullptr;
std::unique_ptr<btPairCachingGhostObject> m_ghost;
std::unique_ptr<btSphereShape> m_shape;
bool m_enabled = false;
float m_enableTimer = 0.f;
bool m_collected = false;