Allow adding disabled shapes
Adds the ability to directly add disabled shapes to a collision object. Before this commit a shape has always been assumed to be enabled and had to be disabled in an extra step.
This commit is contained in:
parent
6098a7f191
commit
a9d4cde0f5
|
@ -279,14 +279,14 @@ PhysicsServer::AreaSpaceOverrideMode BulletPhysicsServer::area_get_space_overrid
|
|||
return area->get_spOv_mode();
|
||||
}
|
||||
|
||||
void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform) {
|
||||
void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) {
|
||||
AreaBullet *area = area_owner.get(p_area);
|
||||
ERR_FAIL_COND(!area);
|
||||
|
||||
ShapeBullet *shape = shape_owner.get(p_shape);
|
||||
ERR_FAIL_COND(!shape);
|
||||
|
||||
area->add_shape(shape, p_transform);
|
||||
area->add_shape(shape, p_transform, p_disabled);
|
||||
}
|
||||
|
||||
void BulletPhysicsServer::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
|
||||
|
@ -498,7 +498,7 @@ PhysicsServer::BodyMode BulletPhysicsServer::body_get_mode(RID p_body) const {
|
|||
return body->get_mode();
|
||||
}
|
||||
|
||||
void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform) {
|
||||
void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) {
|
||||
|
||||
RigidBodyBullet *body = rigid_body_owner.get(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
@ -506,7 +506,7 @@ void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transfor
|
|||
ShapeBullet *shape = shape_owner.get(p_shape);
|
||||
ERR_FAIL_COND(!shape);
|
||||
|
||||
body->add_shape(shape, p_transform);
|
||||
body->add_shape(shape, p_transform, p_disabled);
|
||||
}
|
||||
|
||||
void BulletPhysicsServer::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
|
||||
|
|
|
@ -133,7 +133,7 @@ public:
|
|||
virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode);
|
||||
virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const;
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform());
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false);
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape);
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform);
|
||||
virtual int area_get_shape_count(RID p_area) const;
|
||||
|
@ -174,7 +174,7 @@ public:
|
|||
virtual void body_set_mode(RID p_body, BodyMode p_mode);
|
||||
virtual BodyMode body_get_mode(RID p_body) const;
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform());
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false);
|
||||
// Not supported, Please remove and add new shape
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape);
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform);
|
||||
|
|
|
@ -216,8 +216,8 @@ RigidCollisionObjectBullet::~RigidCollisionObjectBullet() {
|
|||
}
|
||||
}
|
||||
|
||||
void RigidCollisionObjectBullet::add_shape(ShapeBullet *p_shape, const Transform &p_transform) {
|
||||
shapes.push_back(ShapeWrapper(p_shape, p_transform, true));
|
||||
void RigidCollisionObjectBullet::add_shape(ShapeBullet *p_shape, const Transform &p_transform, bool p_disabled) {
|
||||
shapes.push_back(ShapeWrapper(p_shape, p_transform, !p_disabled));
|
||||
p_shape->add_owner(this);
|
||||
reload_shapes();
|
||||
}
|
||||
|
@ -299,6 +299,8 @@ Transform RigidCollisionObjectBullet::get_shape_transform(int p_index) const {
|
|||
}
|
||||
|
||||
void RigidCollisionObjectBullet::set_shape_disabled(int p_index, bool p_disabled) {
|
||||
if (shapes[p_index].active != p_disabled)
|
||||
return;
|
||||
shapes.write[p_index].active = !p_disabled;
|
||||
shape_changed(p_index);
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ public:
|
|||
|
||||
_FORCE_INLINE_ btCollisionShape *get_main_shape() const { return mainShape; }
|
||||
|
||||
void add_shape(ShapeBullet *p_shape, const Transform &p_transform = Transform());
|
||||
void add_shape(ShapeBullet *p_shape, const Transform &p_transform = Transform(), bool p_disabled = false);
|
||||
void set_shape(int p_index, ShapeBullet *p_shape);
|
||||
|
||||
int get_shape_count() const;
|
||||
|
|
|
@ -251,9 +251,9 @@ void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2
|
|||
s.index = total_subshapes;
|
||||
s.shape = p_shape;
|
||||
if (area) {
|
||||
Physics2DServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform);
|
||||
Physics2DServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled);
|
||||
} else {
|
||||
Physics2DServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform);
|
||||
Physics2DServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled);
|
||||
}
|
||||
sd.shapes.push_back(s);
|
||||
|
||||
|
|
|
@ -259,9 +259,9 @@ void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &
|
|||
s.index = total_subshapes;
|
||||
s.shape = p_shape;
|
||||
if (area) {
|
||||
PhysicsServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform);
|
||||
PhysicsServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled);
|
||||
} else {
|
||||
PhysicsServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform);
|
||||
PhysicsServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled);
|
||||
}
|
||||
sd.shapes.push_back(s);
|
||||
|
||||
|
|
|
@ -32,13 +32,14 @@
|
|||
#include "servers/physics/physics_server_sw.h"
|
||||
#include "space_sw.h"
|
||||
|
||||
void CollisionObjectSW::add_shape(ShapeSW *p_shape, const Transform &p_transform) {
|
||||
void CollisionObjectSW::add_shape(ShapeSW *p_shape, const Transform &p_transform, bool p_disabled) {
|
||||
|
||||
Shape s;
|
||||
s.shape = p_shape;
|
||||
s.xform = p_transform;
|
||||
s.xform_inv = s.xform.affine_inverse();
|
||||
s.bpid = 0; //needs update
|
||||
s.disabled = p_disabled;
|
||||
shapes.push_back(s);
|
||||
p_shape->add_owner(this);
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
void _shape_changed();
|
||||
|
||||
_FORCE_INLINE_ Type get_type() const { return type; }
|
||||
void add_shape(ShapeSW *p_shape, const Transform &p_transform = Transform());
|
||||
void add_shape(ShapeSW *p_shape, const Transform &p_transform = Transform(), bool p_disabled = false);
|
||||
void set_shape(int p_index, ShapeSW *p_shape);
|
||||
void set_shape_transform(int p_index, const Transform &p_transform);
|
||||
_FORCE_INLINE_ int get_shape_count() const { return shapes.size(); }
|
||||
|
|
|
@ -283,7 +283,7 @@ PhysicsServer::AreaSpaceOverrideMode PhysicsServerSW::area_get_space_override_mo
|
|||
return area->get_space_override_mode();
|
||||
}
|
||||
|
||||
void PhysicsServerSW::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform) {
|
||||
void PhysicsServerSW::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) {
|
||||
|
||||
AreaSW *area = area_owner.get(p_area);
|
||||
ERR_FAIL_COND(!area);
|
||||
|
@ -291,7 +291,7 @@ void PhysicsServerSW::area_add_shape(RID p_area, RID p_shape, const Transform &p
|
|||
ShapeSW *shape = shape_owner.get(p_shape);
|
||||
ERR_FAIL_COND(!shape);
|
||||
|
||||
area->add_shape(shape, p_transform);
|
||||
area->add_shape(shape, p_transform, p_disabled);
|
||||
}
|
||||
|
||||
void PhysicsServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
|
||||
|
@ -540,7 +540,7 @@ PhysicsServer::BodyMode PhysicsServerSW::body_get_mode(RID p_body) const {
|
|||
return body->get_mode();
|
||||
};
|
||||
|
||||
void PhysicsServerSW::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform) {
|
||||
void PhysicsServerSW::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) {
|
||||
|
||||
BodySW *body = body_owner.get(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
@ -548,7 +548,7 @@ void PhysicsServerSW::body_add_shape(RID p_body, RID p_shape, const Transform &p
|
|||
ShapeSW *shape = shape_owner.get(p_shape);
|
||||
ERR_FAIL_COND(!shape);
|
||||
|
||||
body->add_shape(shape, p_transform);
|
||||
body->add_shape(shape, p_transform, p_disabled);
|
||||
}
|
||||
|
||||
void PhysicsServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
|
||||
|
|
|
@ -119,7 +119,7 @@ public:
|
|||
virtual void area_set_space(RID p_area, RID p_space);
|
||||
virtual RID area_get_space(RID p_area) const;
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform());
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false);
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape);
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform);
|
||||
|
||||
|
@ -163,7 +163,7 @@ public:
|
|||
virtual void body_set_mode(RID p_body, BodyMode p_mode);
|
||||
virtual BodyMode body_get_mode(RID p_body) const;
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform());
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false);
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape);
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform);
|
||||
|
||||
|
|
|
@ -31,14 +31,14 @@
|
|||
#include "collision_object_2d_sw.h"
|
||||
#include "space_2d_sw.h"
|
||||
|
||||
void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Transform2D &p_transform) {
|
||||
void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Transform2D &p_transform, bool p_disabled) {
|
||||
|
||||
Shape s;
|
||||
s.shape = p_shape;
|
||||
s.xform = p_transform;
|
||||
s.xform_inv = s.xform.affine_inverse();
|
||||
s.bpid = 0; //needs update
|
||||
s.disabled = false;
|
||||
s.disabled = p_disabled;
|
||||
s.one_way_collision = false;
|
||||
s.one_way_collision_margin = 0;
|
||||
shapes.push_back(s);
|
||||
|
|
|
@ -111,7 +111,7 @@ public:
|
|||
void _shape_changed();
|
||||
|
||||
_FORCE_INLINE_ Type get_type() const { return type; }
|
||||
void add_shape(Shape2DSW *p_shape, const Transform2D &p_transform = Transform2D());
|
||||
void add_shape(Shape2DSW *p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false);
|
||||
void set_shape(int p_index, Shape2DSW *p_shape);
|
||||
void set_shape_transform(int p_index, const Transform2D &p_transform);
|
||||
void set_shape_metadata(int p_index, const Variant &p_metadata);
|
||||
|
|
|
@ -378,7 +378,7 @@ Physics2DServer::AreaSpaceOverrideMode Physics2DServerSW::area_get_space_overrid
|
|||
return area->get_space_override_mode();
|
||||
}
|
||||
|
||||
void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform) {
|
||||
void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform, bool p_disabled) {
|
||||
|
||||
Area2DSW *area = area_owner.get(p_area);
|
||||
ERR_FAIL_COND(!area);
|
||||
|
@ -386,7 +386,7 @@ void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2
|
|||
Shape2DSW *shape = shape_owner.get(p_shape);
|
||||
ERR_FAIL_COND(!shape);
|
||||
|
||||
area->add_shape(shape, p_transform);
|
||||
area->add_shape(shape, p_transform, p_disabled);
|
||||
}
|
||||
|
||||
void Physics2DServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
|
||||
|
@ -643,7 +643,7 @@ Physics2DServer::BodyMode Physics2DServerSW::body_get_mode(RID p_body) const {
|
|||
return body->get_mode();
|
||||
};
|
||||
|
||||
void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform) {
|
||||
void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform, bool p_disabled) {
|
||||
|
||||
Body2DSW *body = body_owner.get(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
@ -651,7 +651,7 @@ void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2
|
|||
Shape2DSW *shape = shape_owner.get(p_shape);
|
||||
ERR_FAIL_COND(!shape);
|
||||
|
||||
body->add_shape(shape, p_transform);
|
||||
body->add_shape(shape, p_transform, p_disabled);
|
||||
}
|
||||
|
||||
void Physics2DServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
|
||||
|
|
|
@ -131,7 +131,7 @@ public:
|
|||
virtual void area_set_space(RID p_area, RID p_space);
|
||||
virtual RID area_get_space(RID p_area) const;
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D());
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false);
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape);
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform);
|
||||
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
virtual void body_set_mode(RID p_body, BodyMode p_mode);
|
||||
virtual BodyMode body_get_mode(RID p_body) const;
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D());
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false);
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape);
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform);
|
||||
virtual void body_set_shape_metadata(RID p_body, int p_shape_idx, const Variant &p_metadata);
|
||||
|
|
|
@ -140,7 +140,7 @@ public:
|
|||
FUNC2(area_set_space_override_mode, RID, AreaSpaceOverrideMode);
|
||||
FUNC1RC(AreaSpaceOverrideMode, area_get_space_override_mode, RID);
|
||||
|
||||
FUNC3(area_add_shape, RID, RID, const Transform2D &);
|
||||
FUNC4(area_add_shape, RID, RID, const Transform2D &, bool);
|
||||
FUNC3(area_set_shape, RID, int, RID);
|
||||
FUNC3(area_set_shape_transform, RID, int, const Transform2D &);
|
||||
FUNC3(area_set_shape_disabled, RID, int, bool);
|
||||
|
@ -183,7 +183,7 @@ public:
|
|||
FUNC2(body_set_mode, RID, BodyMode);
|
||||
FUNC1RC(BodyMode, body_get_mode, RID);
|
||||
|
||||
FUNC3(body_add_shape, RID, RID, const Transform2D &);
|
||||
FUNC4(body_add_shape, RID, RID, const Transform2D &, bool);
|
||||
FUNC3(body_set_shape, RID, int, RID);
|
||||
FUNC3(body_set_shape_transform, RID, int, const Transform2D &);
|
||||
FUNC3(body_set_shape_metadata, RID, int, const Variant &);
|
||||
|
|
|
@ -335,7 +335,7 @@ public:
|
|||
virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0;
|
||||
virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0;
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D()) = 0;
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) = 0;
|
||||
|
||||
|
@ -388,7 +388,7 @@ public:
|
|||
virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
|
||||
virtual BodyMode body_get_mode(RID p_body) const = 0;
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D()) = 0;
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) = 0;
|
||||
virtual void body_set_shape_metadata(RID p_body, int p_shape_idx, const Variant &p_metadata) = 0;
|
||||
|
|
|
@ -320,7 +320,7 @@ public:
|
|||
virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0;
|
||||
virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0;
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform()) = 0;
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false) = 0;
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) = 0;
|
||||
|
||||
|
@ -372,7 +372,7 @@ public:
|
|||
virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
|
||||
virtual BodyMode body_get_mode(RID p_body) const = 0;
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform()) = 0;
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false) = 0;
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue