summaryrefslogtreecommitdiff
path: root/modules/bullet/collision_object_bullet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/bullet/collision_object_bullet.cpp')
-rw-r--r--modules/bullet/collision_object_bullet.cpp58
1 files changed, 17 insertions, 41 deletions
diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp
index dd208965bd..a3158a15e5 100644
--- a/modules/bullet/collision_object_bullet.cpp
+++ b/modules/bullet/collision_object_bullet.cpp
@@ -79,7 +79,7 @@ btTransform CollisionObjectBullet::ShapeWrapper::get_adjusted_transform() const
}
void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_scale) {
- if (bt_shape == nullptr) {
+ if (!bt_shape) {
if (active) {
bt_shape = shape->create_bt_shape(scale * body_scale);
} else {
@@ -88,13 +88,6 @@ void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_s
}
}
-void CollisionObjectBullet::ShapeWrapper::release_bt_shape() {
- if (bt_shape != nullptr) {
- shape->destroy_bt_shape(bt_shape);
- bt_shape = nullptr;
- }
-}
-
CollisionObjectBullet::CollisionObjectBullet(Type p_type) :
RIDBullet(),
type(p_type) {}
@@ -165,13 +158,6 @@ bool CollisionObjectBullet::has_collision_exception(const CollisionObjectBullet
return !bt_collision_object->checkCollideWith(p_otherCollisionObject->bt_collision_object);
}
-void CollisionObjectBullet::prepare_object_for_dispatch() {
- if (need_body_reload) {
- do_reload_body();
- need_body_reload = false;
- }
-}
-
void CollisionObjectBullet::set_collision_enabled(bool p_enabled) {
collisionsEnabled = p_enabled;
if (collisionsEnabled) {
@@ -333,28 +319,16 @@ bool RigidCollisionObjectBullet::is_shape_disabled(int p_index) {
return !shapes[p_index].active;
}
-void RigidCollisionObjectBullet::prepare_object_for_dispatch() {
- if (need_shape_reload) {
- do_reload_shapes();
- need_shape_reload = false;
- }
- CollisionObjectBullet::prepare_object_for_dispatch();
-}
-
void RigidCollisionObjectBullet::shape_changed(int p_shape_index) {
ShapeWrapper &shp = shapes.write[p_shape_index];
if (shp.bt_shape == mainShape) {
mainShape = nullptr;
}
- shp.release_bt_shape();
+ bulletdelete(shp.bt_shape);
reload_shapes();
}
void RigidCollisionObjectBullet::reload_shapes() {
- need_shape_reload = true;
-}
-
-void RigidCollisionObjectBullet::do_reload_shapes() {
if (mainShape && mainShape->isCompound()) {
// Destroy compound
bulletdelete(mainShape);
@@ -362,39 +336,41 @@ void RigidCollisionObjectBullet::do_reload_shapes() {
mainShape = nullptr;
+ ShapeWrapper *shpWrapper;
const int shape_count = shapes.size();
- ShapeWrapper *shapes_ptr = shapes.ptrw();
- // Reset all shapes if required
+ // Reset shape if required
if (force_shape_reset) {
for (int i(0); i < shape_count; ++i) {
- shapes_ptr[i].release_bt_shape();
+ shpWrapper = &shapes.write[i];
+ bulletdelete(shpWrapper->bt_shape);
}
force_shape_reset = false;
}
const btVector3 body_scale(get_bt_body_scale());
+ // Try to optimize by not using compound
if (1 == shape_count) {
- // Is it possible to optimize by not using compound?
- btTransform transform = shapes_ptr[0].get_adjusted_transform();
+ shpWrapper = &shapes.write[0];
+ btTransform transform = shpWrapper->get_adjusted_transform();
if (transform.getOrigin().isZero() && transform.getBasis() == transform.getBasis().getIdentity()) {
- shapes_ptr[0].claim_bt_shape(body_scale);
- mainShape = shapes_ptr[0].bt_shape;
+ shpWrapper->claim_bt_shape(body_scale);
+ mainShape = shpWrapper->bt_shape;
main_shape_changed();
- // Nothing more to do
return;
}
}
- // Optimization not possible use a compound shape.
+ // Optimization not possible use a compound shape
btCompoundShape *compoundShape = bulletnew(btCompoundShape(enableDynamicAabbTree, shape_count));
for (int i(0); i < shape_count; ++i) {
- shapes_ptr[i].claim_bt_shape(body_scale);
- btTransform scaled_shape_transform(shapes_ptr[i].get_adjusted_transform());
+ shpWrapper = &shapes.write[i];
+ shpWrapper->claim_bt_shape(body_scale);
+ btTransform scaled_shape_transform(shpWrapper->get_adjusted_transform());
scaled_shape_transform.getOrigin() *= body_scale;
- compoundShape->addChildShape(scaled_shape_transform, shapes_ptr[i].bt_shape);
+ compoundShape->addChildShape(scaled_shape_transform, shpWrapper->bt_shape);
}
compoundShape->recalculateLocalAabb();
@@ -413,5 +389,5 @@ void RigidCollisionObjectBullet::internal_shape_destroy(int p_index, bool p_perm
if (shp.bt_shape == mainShape) {
mainShape = nullptr;
}
- shp.release_bt_shape();
+ bulletdelete(shp.bt_shape);
}