mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Change JoltShapeInstance3D
to use move semantics
This commit is contained in:
parent
aef0065e09
commit
92da11f69c
2 changed files with 12 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue