Store ObjectID instead of raw pointer for Shape Owners

This commit is contained in:
Haoyu Qiu 2022-01-25 17:16:02 +08:00
parent cb9854df52
commit fa96505418
4 changed files with 8 additions and 8 deletions

View File

@ -170,7 +170,7 @@ uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) {
id = shapes.back()->key() + 1; id = shapes.back()->key() + 1;
} }
sd.owner = p_owner; sd.owner_id = p_owner ? p_owner->get_instance_id() : 0;
shapes[id] = sd; shapes[id] = sd;
@ -283,7 +283,7 @@ Transform2D CollisionObject2D::shape_owner_get_transform(uint32_t p_owner) const
Object *CollisionObject2D::shape_owner_get_owner(uint32_t p_owner) const { Object *CollisionObject2D::shape_owner_get_owner(uint32_t p_owner) const {
ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr); ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr);
return shapes[p_owner].owner; return ObjectDB::get_instance(shapes[p_owner].owner_id);
} }
void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape) { void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape) {

View File

@ -45,7 +45,7 @@ class CollisionObject2D : public Node2D {
bool pickable; bool pickable;
struct ShapeData { struct ShapeData {
Object *owner; ObjectID owner_id;
Transform2D xform; Transform2D xform;
struct Shape { struct Shape {
Ref<Shape2D> shape; Ref<Shape2D> shape;
@ -61,7 +61,7 @@ class CollisionObject2D : public Node2D {
disabled = false; disabled = false;
one_way_collision = false; one_way_collision = false;
one_way_collision_margin = 0; one_way_collision_margin = 0;
owner = nullptr; owner_id = 0;
} }
}; };

View File

@ -363,7 +363,7 @@ uint32_t CollisionObject::create_shape_owner(Object *p_owner) {
id = shapes.back()->key() + 1; id = shapes.back()->key() + 1;
} }
sd.owner = p_owner; sd.owner_id = p_owner ? p_owner->get_instance_id() : 0;
shapes[id] = sd; shapes[id] = sd;
@ -442,7 +442,7 @@ Transform CollisionObject::shape_owner_get_transform(uint32_t p_owner) const {
Object *CollisionObject::shape_owner_get_owner(uint32_t p_owner) const { Object *CollisionObject::shape_owner_get_owner(uint32_t p_owner) const {
ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr); ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr);
return shapes[p_owner].owner; return ObjectDB::get_instance(shapes[p_owner].owner_id);
} }
void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape) { void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape) {

View File

@ -45,7 +45,7 @@ class CollisionObject : public Spatial {
RID rid; RID rid;
struct ShapeData { struct ShapeData {
Object *owner; ObjectID owner_id;
Transform xform; Transform xform;
struct ShapeBase { struct ShapeBase {
RID debug_shape; RID debug_shape;
@ -58,7 +58,7 @@ class CollisionObject : public Spatial {
ShapeData() { ShapeData() {
disabled = false; disabled = false;
owner = nullptr; owner_id = 0;
} }
}; };