1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-17 14:11:06 +00:00

Prevent setting too big or too small Collision Mask and Layer

This commit is contained in:
Rafał Mikrut
2021-04-30 17:58:06 +02:00
committed by Hugo Locurcio
parent 3a8bea3ae3
commit cb5faca39a
14 changed files with 50 additions and 16 deletions

View File

@@ -87,6 +87,7 @@ uint32_t CSGShape::get_collision_mask() const {
}
void CSGShape::set_collision_mask_bit(int p_bit, bool p_value) {
ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision mask bit must be between 0 and 31 inclusive.");
uint32_t mask = get_collision_mask();
if (p_value) {
mask |= 1 << p_bit;
@@ -97,20 +98,23 @@ void CSGShape::set_collision_mask_bit(int p_bit, bool p_value) {
}
bool CSGShape::get_collision_mask_bit(int p_bit) const {
ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive.");
return get_collision_mask() & (1 << p_bit);
}
void CSGShape::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_layer();
ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision layer bit must be between 0 and 31 inclusive.");
uint32_t layer = get_collision_layer();
if (p_value) {
mask |= 1 << p_bit;
layer |= 1 << p_bit;
} else {
mask &= ~(1 << p_bit);
layer &= ~(1 << p_bit);
}
set_collision_layer(mask);
set_collision_layer(layer);
}
bool CSGShape::get_collision_layer_bit(int p_bit) const {
ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision layer bit must be between 0 and 31 inclusive.");
return get_collision_layer() & (1 << p_bit);
}