diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-04-16 08:36:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-16 08:36:29 +0200 |
commit | dddbde82caf2aa42290055348bdf2cfd1b268e22 (patch) | |
tree | 0f0dced6a424a46aa6493423d7c0d671cd7c8154 /servers/physics_2d/broad_phase_2d_hash_grid.h | |
parent | 0c8ec7237071df787fc598c9014b4a9746a1ce18 (diff) | |
parent | 9b65b00296a070d653290ba3dfcf19b516a752f1 (diff) |
Merge pull request #45989 from HenryWConklin/optimize-2dphys-different-layers
Optimize BroadPhase2dHashGrid to not pair elements on different layers
Diffstat (limited to 'servers/physics_2d/broad_phase_2d_hash_grid.h')
-rw-r--r-- | servers/physics_2d/broad_phase_2d_hash_grid.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.h b/servers/physics_2d/broad_phase_2d_hash_grid.h index eb7c8879ac..bb7c03b989 100644 --- a/servers/physics_2d/broad_phase_2d_hash_grid.h +++ b/servers/physics_2d/broad_phase_2d_hash_grid.h @@ -51,6 +51,9 @@ class BroadPhase2DHashGrid : public BroadPhase2DSW { CollisionObject2DSW *owner; bool _static; Rect2 aabb; + // Owner's collision_mask/layer, used to detect changes in layers. + uint32_t collision_mask; + uint32_t collision_layer; int subindex; uint64_t pass; Map<Element *, PairData *> paired; @@ -115,8 +118,12 @@ class BroadPhase2DHashGrid : public BroadPhase2DSW { UnpairCallback unpair_callback; void *unpair_userdata; - void _enter_grid(Element *p_elem, const Rect2 &p_rect, bool p_static); - void _exit_grid(Element *p_elem, const Rect2 &p_rect, bool p_static); + static _FORCE_INLINE_ bool _test_collision_mask(uint32_t p_mask1, uint32_t p_layer1, uint32_t p_mask2, uint32_t p_layer2) { + return p_mask1 & p_layer2 || p_mask2 & p_layer1; + } + + void _enter_grid(Element *p_elem, const Rect2 &p_rect, bool p_static, bool p_force_enter); + void _exit_grid(Element *p_elem, const Rect2 &p_rect, bool p_static, bool p_force_exit); template <bool use_aabb, bool use_segment> _FORCE_INLINE_ void _cull(const Point2i p_cell, const Rect2 &p_aabb, const Point2 &p_from, const Point2 &p_to, CollisionObject2DSW **p_results, int p_max_results, int *p_result_indices, int &index); |