diff --git a/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp b/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp index 95b763680bd..6320002b869 100644 --- a/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp +++ b/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp @@ -42,12 +42,11 @@ JoltShapeInstance3D::ShapeReference::ShapeReference(JoltShapedObject3D *p_parent } } -JoltShapeInstance3D::ShapeReference::ShapeReference(const ShapeReference &p_other) : +JoltShapeInstance3D::ShapeReference::ShapeReference(ShapeReference &&p_other) : parent(p_other.parent), shape(p_other.shape) { - if (shape != nullptr) { - shape->add_owner(parent); - } + p_other.parent = nullptr; + p_other.shape = nullptr; } JoltShapeInstance3D::ShapeReference::~ShapeReference() { @@ -56,16 +55,10 @@ JoltShapeInstance3D::ShapeReference::~ShapeReference() { } } -JoltShapeInstance3D::ShapeReference &JoltShapeInstance3D::ShapeReference::operator=(const ShapeReference &p_other) { - if (shape != nullptr) { - shape->remove_owner(parent); - } - - parent = p_other.parent; - shape = p_other.shape; - - if (shape != nullptr) { - shape->add_owner(parent); +JoltShapeInstance3D::ShapeReference &JoltShapeInstance3D::ShapeReference::operator=(ShapeReference &&p_other) { + if (this != &p_other) { + SWAP(parent, p_other.parent); + SWAP(shape, p_other.shape); } return *this; diff --git a/modules/jolt_physics/shapes/jolt_shape_instance_3d.h b/modules/jolt_physics/shapes/jolt_shape_instance_3d.h index ebb08c74a74..e601ccd6493 100644 --- a/modules/jolt_physics/shapes/jolt_shape_instance_3d.h +++ b/modules/jolt_physics/shapes/jolt_shape_instance_3d.h @@ -40,20 +40,19 @@ class JoltShapedObject3D; class JoltShape3D; class JoltShapeInstance3D { - // This RAII helper exists solely to avoid needing to maintain copy construction/assignment in the shape instance. - // Ideally this would be move-only instead, but Godot's containers don't support that at the moment. + // This RAII helper exists solely to avoid needing to maintain move construction/assignment in `JoltShapeInstance3D`. struct ShapeReference { JoltShapedObject3D *parent = nullptr; JoltShape3D *shape = nullptr; ShapeReference() = default; ShapeReference(JoltShapedObject3D *p_parent, JoltShape3D *p_shape); - ShapeReference(const ShapeReference &p_other); - ShapeReference(ShapeReference &&p_other) = delete; + ShapeReference(const ShapeReference &p_other) = delete; + ShapeReference(ShapeReference &&p_other); ~ShapeReference(); - ShapeReference &operator=(const ShapeReference &p_other); - ShapeReference &operator=(ShapeReference &&p_other) = delete; + ShapeReference &operator=(const ShapeReference &p_other) = delete; + ShapeReference &operator=(ShapeReference &&p_other); JoltShape3D *operator*() const { return shape; } JoltShape3D *operator->() const { return shape; }