Rename collision layer as suggested in #5696

This commit is contained in:
Juan Linietsky 2017-01-13 11:01:19 -03:00
parent 04c749a1f0
commit 0ad9939603
5 changed files with 44 additions and 42 deletions

View file

@ -112,7 +112,7 @@ motion/mirroring = motion_mirroring
[PhysicsBody2D]
collision/layers = collision_layers
collision/layers = collision_layer
collision/mask = collision_mask
[Polygon2D]
@ -227,7 +227,7 @@ mesh/skeleton = skeleton
[PhysicsBody]
collision/layers = collision_layers
collision/layers = collision_layer
collision/mask = collision_mask
[Quad]

View file

@ -70,19 +70,19 @@ float PhysicsBody2D::get_one_way_collision_max_depth() const{
void PhysicsBody2D::_set_layers(uint32_t p_mask) {
set_layer_mask(p_mask);
set_collision_layer(p_mask);
set_collision_mask(p_mask);
}
uint32_t PhysicsBody2D::_get_layers() const{
return get_layer_mask();
return get_collision_layer();
}
void PhysicsBody2D::_bind_methods() {
ClassDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody2D::set_layer_mask);
ClassDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask);
ClassDB::bind_method(_MD("set_collision_layer","mask"),&PhysicsBody2D::set_collision_layer);
ClassDB::bind_method(_MD("get_collision_layer"),&PhysicsBody2D::get_collision_layer);
ClassDB::bind_method(_MD("set_collision_mask","mask"),&PhysicsBody2D::set_collision_mask);
ClassDB::bind_method(_MD("get_collision_mask"),&PhysicsBody2D::get_collision_mask);
@ -90,8 +90,8 @@ void PhysicsBody2D::_bind_methods() {
ClassDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&PhysicsBody2D::set_collision_mask_bit);
ClassDB::bind_method(_MD("get_collision_mask_bit","bit"),&PhysicsBody2D::get_collision_mask_bit);
ClassDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&PhysicsBody2D::set_layer_mask_bit);
ClassDB::bind_method(_MD("get_layer_mask_bit","bit"),&PhysicsBody2D::get_layer_mask_bit);
ClassDB::bind_method(_MD("set_collision_layer_bit","bit","value"),&PhysicsBody2D::set_collision_layer_bit);
ClassDB::bind_method(_MD("get_collision_layer_bit","bit"),&PhysicsBody2D::get_collision_layer_bit);
ClassDB::bind_method(_MD("_set_layers","mask"),&PhysicsBody2D::_set_layers);
ClassDB::bind_method(_MD("_get_layers"),&PhysicsBody2D::_get_layers);
@ -102,21 +102,22 @@ void PhysicsBody2D::_bind_methods() {
ClassDB::bind_method(_MD("add_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::add_collision_exception_with);
ClassDB::bind_method(_MD("remove_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::remove_collision_exception_with);
ADD_PROPERTY(PropertyInfo(Variant::INT,"layers",PROPERTY_HINT_LAYERS_2D_PHYSICS,"",0),_SCS("_set_layers"),_SCS("_get_layers")); //for backwards compat
ADD_GROUP("Collision","collision_");
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_layers",PROPERTY_HINT_LAYERS_2D_PHYSICS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_layer",PROPERTY_HINT_LAYERS_2D_PHYSICS),_SCS("set_collision_layer"),_SCS("get_collision_layer"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_2D_PHYSICS),_SCS("set_collision_mask"),_SCS("get_collision_mask"));
ADD_GROUP("","");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"one_way_collision/direction"),_SCS("set_one_way_collision_direction"),_SCS("get_one_way_collision_direction"));
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"one_way_collision/max_depth"),_SCS("set_one_way_collision_max_depth"),_SCS("get_one_way_collision_max_depth"));
}
void PhysicsBody2D::set_layer_mask(uint32_t p_mask) {
void PhysicsBody2D::set_collision_layer(uint32_t p_mask) {
mask=p_mask;
Physics2DServer::get_singleton()->body_set_layer_mask(get_rid(),p_mask);
}
uint32_t PhysicsBody2D::get_layer_mask() const {
uint32_t PhysicsBody2D::get_collision_layer() const {
return mask;
}
@ -148,20 +149,20 @@ bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const{
}
void PhysicsBody2D::set_layer_mask_bit(int p_bit, bool p_value) {
void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_layer_mask();
uint32_t mask = get_collision_layer();
if (p_value)
mask|=1<<p_bit;
else
mask&=~(1<<p_bit);
set_layer_mask(mask);
set_collision_layer(mask);
}
bool PhysicsBody2D::get_layer_mask_bit(int p_bit) const{
bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const{
return get_layer_mask()&(1<<p_bit);
return get_collision_layer()&(1<<p_bit);
}
PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) {

View file

@ -55,8 +55,8 @@ protected:
static void _bind_methods();
public:
void set_layer_mask(uint32_t p_mask);
uint32_t get_layer_mask() const;
void set_collision_layer(uint32_t p_mask);
uint32_t get_collision_layer() const;
void set_collision_mask(uint32_t p_mask);
uint32_t get_collision_mask() const;
@ -65,8 +65,8 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
void set_layer_mask_bit(int p_bit, bool p_value);
bool get_layer_mask_bit(int p_bit) const;
void set_collision_layer_bit(int p_bit, bool p_value);
bool get_collision_layer_bit(int p_bit) const;
void add_collision_exception_with(Node* p_node); //must be physicsbody
void remove_collision_exception_with(Node* p_node);

View file

@ -58,13 +58,13 @@ float PhysicsBody::get_inverse_mass() const {
}
void PhysicsBody::set_layer_mask(uint32_t p_mask) {
void PhysicsBody::set_collision_layer(uint32_t p_mask) {
layer_mask=p_mask;
PhysicsServer::get_singleton()->body_set_layer_mask(get_rid(),p_mask);
}
uint32_t PhysicsBody::get_layer_mask() const {
uint32_t PhysicsBody::get_collision_layer() const {
return layer_mask;
}
@ -97,20 +97,20 @@ bool PhysicsBody::get_collision_mask_bit(int p_bit) const{
}
void PhysicsBody::set_layer_mask_bit(int p_bit, bool p_value) {
void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_layer_mask();
uint32_t mask = get_collision_layer();
if (p_value)
mask|=1<<p_bit;
else
mask&=~(1<<p_bit);
set_layer_mask(mask);
set_collision_layer(mask);
}
bool PhysicsBody::get_layer_mask_bit(int p_bit) const{
bool PhysicsBody::get_collision_layer_bit(int p_bit) const{
return get_layer_mask()&(1<<p_bit);
return get_collision_layer()&(1<<p_bit);
}
void PhysicsBody::add_collision_exception_with(Node* p_node) {
@ -137,18 +137,18 @@ void PhysicsBody::remove_collision_exception_with(Node* p_node) {
}
void PhysicsBody::_set_layers(uint32_t p_mask) {
set_layer_mask(p_mask);
set_collision_layer(p_mask);
set_collision_mask(p_mask);
}
uint32_t PhysicsBody::_get_layers() const{
return get_layer_mask();
return get_collision_layer();
}
void PhysicsBody::_bind_methods() {
ClassDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody::set_layer_mask);
ClassDB::bind_method(_MD("get_layer_mask"),&PhysicsBody::get_layer_mask);
ClassDB::bind_method(_MD("set_collision_layer","layer"),&PhysicsBody::set_collision_layer);
ClassDB::bind_method(_MD("get_collision_layer"),&PhysicsBody::get_collision_layer);
ClassDB::bind_method(_MD("set_collision_mask","mask"),&PhysicsBody::set_collision_mask);
ClassDB::bind_method(_MD("get_collision_mask"),&PhysicsBody::get_collision_mask);
@ -156,13 +156,14 @@ void PhysicsBody::_bind_methods() {
ClassDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&PhysicsBody::set_collision_mask_bit);
ClassDB::bind_method(_MD("get_collision_mask_bit","bit"),&PhysicsBody::get_collision_mask_bit);
ClassDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&PhysicsBody::set_layer_mask_bit);
ClassDB::bind_method(_MD("get_layer_mask_bit","bit"),&PhysicsBody::get_layer_mask_bit);
ClassDB::bind_method(_MD("set_collision_layer_bit","bit","value"),&PhysicsBody::set_collision_layer_bit);
ClassDB::bind_method(_MD("get_collision_layer_bit","bit"),&PhysicsBody::get_collision_layer_bit);
ClassDB::bind_method(_MD("_set_layers","mask"),&PhysicsBody::_set_layers);
ClassDB::bind_method(_MD("_get_layers"),&PhysicsBody::_get_layers);
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_layers",PROPERTY_HINT_LAYERS_3D_PHYSICS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
ADD_GROUP("Collision","collision_");
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_layer",PROPERTY_HINT_LAYERS_3D_PHYSICS),_SCS("set_collision_layer"),_SCS("get_collision_layer"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_3D_PHYSICS),_SCS("set_collision_mask"),_SCS("get_collision_mask"));
}
@ -1014,7 +1015,7 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
if (is_shape_set_as_trigger(i))
continue;
if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i),m,sr,max_shapes,res_shapes,exclude,get_layer_mask(),mask)) {
if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i),m,sr,max_shapes,res_shapes,exclude,get_collision_layer(),mask)) {
collided=true;
}
@ -1096,7 +1097,7 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
float lsafe,lunsafe;
PhysicsDirectSpaceState::ShapeRestInfo lrest;
bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion,0, lsafe,lunsafe,exclude,get_layer_mask(),mask,&lrest);
bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion,0, lsafe,lunsafe,exclude,get_collision_layer(),mask,&lrest);
//print_line("shape: "+itos(i)+" travel:"+rtos(ltravel));
if (!valid) {
safe=0;
@ -1137,7 +1138,7 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
ugt.origin+=p_motion*unsafe;
PhysicsDirectSpaceState::ShapeRestInfo rest_info;
bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), m,&rest,exclude,get_layer_mask(),mask);
bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), m,&rest,exclude,get_collision_layer(),mask);
if (!c2) {
//should not happen, but floating point precision is so weird..
colliding=false;
@ -1200,7 +1201,7 @@ bool KinematicBody::can_teleport_to(const Vector3& p_position) {
if (is_shape_set_as_trigger(i))
continue;
bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,1,exclude,get_layer_mask(),mask);
bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,1,exclude,get_collision_layer(),mask);
if (col)
return false;
}

View file

@ -55,14 +55,14 @@ public:
virtual Vector3 get_angular_velocity() const;
virtual float get_inverse_mass() const;
void set_layer_mask(uint32_t p_mask);
uint32_t get_layer_mask() const;
void set_collision_layer(uint32_t p_mask);
uint32_t get_collision_layer() const;
void set_collision_mask(uint32_t p_mask);
uint32_t get_collision_mask() const;
void set_layer_mask_bit(int p_bit, bool p_value);
bool get_layer_mask_bit(int p_bit) const;
void set_collision_layer_bit(int p_bit, bool p_value);
bool get_collision_layer_bit(int p_bit) const;
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;