mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Remove raw ptrs from ProjectileObject
This commit is contained in:
parent
70304dd276
commit
fae8f0c1a9
@ -95,17 +95,14 @@ void ProjectileObject::explode() {
|
|||||||
|
|
||||||
void ProjectileObject::cleanup() {
|
void ProjectileObject::cleanup() {
|
||||||
if (_body) {
|
if (_body) {
|
||||||
engine->dynamicsWorld->removeRigidBody(_body);
|
engine->dynamicsWorld->removeRigidBody(_body.get());
|
||||||
delete _body;
|
|
||||||
_body = nullptr;
|
_body = nullptr;
|
||||||
}
|
}
|
||||||
if (_ghostBody) {
|
if (_ghostBody) {
|
||||||
engine->dynamicsWorld->removeCollisionObject(_ghostBody);
|
engine->dynamicsWorld->removeCollisionObject(_ghostBody.get());
|
||||||
delete _ghostBody;
|
|
||||||
_ghostBody = nullptr;
|
_ghostBody = nullptr;
|
||||||
}
|
}
|
||||||
if (_shape) {
|
if(_shape) {
|
||||||
delete _shape;
|
|
||||||
_shape = nullptr;
|
_shape = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,10 +111,10 @@ ProjectileObject::ProjectileObject(GameWorld* world, const glm::vec3& position,
|
|||||||
const ProjectileObject::ProjectileInfo& info)
|
const ProjectileObject::ProjectileInfo& info)
|
||||||
: GameObject(world, position, glm::quat{1.0f,0.0f,0.0f,0.0f}, nullptr)
|
: GameObject(world, position, glm::quat{1.0f,0.0f,0.0f,0.0f}, nullptr)
|
||||||
, _info(info) {
|
, _info(info) {
|
||||||
_shape = new btSphereShape(0.45f);
|
_shape = std::make_unique<btSphereShape>(0.45f);
|
||||||
btVector3 inertia(0.f, 0.f, 0.f);
|
btVector3 inertia(0.f, 0.f, 0.f);
|
||||||
_shape->calculateLocalInertia(1.f, inertia);
|
_shape->calculateLocalInertia(1.f, inertia);
|
||||||
btRigidBody::btRigidBodyConstructionInfo riginfo(1.f, nullptr, _shape,
|
btRigidBody::btRigidBodyConstructionInfo riginfo(1.f, nullptr, _shape.get(),
|
||||||
inertia);
|
inertia);
|
||||||
|
|
||||||
btTransform ws;
|
btTransform ws;
|
||||||
@ -126,13 +123,13 @@ ProjectileObject::ProjectileObject(GameWorld* world, const glm::vec3& position,
|
|||||||
riginfo.m_startWorldTransform = ws;
|
riginfo.m_startWorldTransform = ws;
|
||||||
riginfo.m_mass = 1.f;
|
riginfo.m_mass = 1.f;
|
||||||
|
|
||||||
_body = new btRigidBody(riginfo);
|
_body = std::make_unique<btRigidBody>(riginfo);
|
||||||
_body->setUserPointer(this);
|
_body->setUserPointer(this);
|
||||||
_body->setLinearVelocity(
|
_body->setLinearVelocity(
|
||||||
btVector3(_info.direction.x, _info.direction.y, _info.direction.z) *
|
btVector3(_info.direction.x, _info.direction.y, _info.direction.z) *
|
||||||
_info.velocity);
|
_info.velocity);
|
||||||
engine->dynamicsWorld->addRigidBody(
|
engine->dynamicsWorld->addRigidBody(
|
||||||
_body, btBroadphaseProxy::DefaultFilter,
|
_body.get(), btBroadphaseProxy::DefaultFilter,
|
||||||
btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
|
btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
|
||||||
|
|
||||||
if (_info.type == RPG) {
|
if (_info.type == RPG) {
|
||||||
@ -142,15 +139,15 @@ ProjectileObject::ProjectileObject(GameWorld* world, const glm::vec3& position,
|
|||||||
|
|
||||||
if (_info.type != Grenade) {
|
if (_info.type != Grenade) {
|
||||||
// Projectiles that aren't grenades explode on contact.
|
// Projectiles that aren't grenades explode on contact.
|
||||||
_ghostBody = new btPairCachingGhostObject();
|
_ghostBody = std::make_unique<btPairCachingGhostObject>();
|
||||||
_ghostBody->setWorldTransform(_body->getWorldTransform());
|
_ghostBody->setWorldTransform(_body->getWorldTransform());
|
||||||
_ghostBody->setCollisionShape(_shape);
|
_ghostBody->setCollisionShape(_shape.get());
|
||||||
_ghostBody->setUserPointer(this);
|
_ghostBody->setUserPointer(this);
|
||||||
_ghostBody->setCollisionFlags(
|
_ghostBody->setCollisionFlags(
|
||||||
btCollisionObject::CF_KINEMATIC_OBJECT |
|
btCollisionObject::CF_KINEMATIC_OBJECT |
|
||||||
btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||||
engine->dynamicsWorld->addCollisionObject(
|
engine->dynamicsWorld->addCollisionObject(
|
||||||
_ghostBody, btBroadphaseProxy::SensorTrigger,
|
_ghostBody.get(), btBroadphaseProxy::SensorTrigger,
|
||||||
btBroadphaseProxy::AllFilter);
|
btBroadphaseProxy::AllFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
ProjectileInfo _info;
|
ProjectileInfo _info;
|
||||||
|
|
||||||
btSphereShape* _shape;
|
std::unique_ptr<btSphereShape> _shape;
|
||||||
|
|
||||||
btRigidBody* _body = nullptr;
|
std::unique_ptr<btRigidBody> _body;
|
||||||
|
|
||||||
/** Used for RPGs and Molotov collision detection */
|
/** Used for RPGs and Molotov collision detection */
|
||||||
btPairCachingGhostObject* _ghostBody = nullptr;
|
std::unique_ptr<btPairCachingGhostObject> _ghostBody;
|
||||||
|
|
||||||
bool _exploded = false;
|
bool _exploded = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user