Optimize _recreate_quadrants

This commit is contained in:
Marcelo Fernandez 2018-06-25 22:24:12 -03:00
parent 8c7da84e1e
commit 67a78e020a
2 changed files with 8 additions and 4 deletions

View file

@ -708,7 +708,7 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
rect_cache_dirty = true; rect_cache_dirty = true;
} }
void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q) { void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update) {
Quadrant &q = Q->get(); Quadrant &q = Q->get();
if (!q.dirty_list.in_list()) if (!q.dirty_list.in_list())
@ -719,7 +719,10 @@ void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q) {
pending_update = true; pending_update = true;
if (!is_inside_tree()) if (!is_inside_tree())
return; return;
_update_dirty_quadrants();
if (update) {
_update_dirty_quadrants();
}
} }
void TileMap::set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) { void TileMap::set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) {
@ -1016,8 +1019,9 @@ void TileMap::_recreate_quadrants() {
} }
Q->get().cells.insert(E->key()); Q->get().cells.insert(E->key());
_make_quadrant_dirty(Q); _make_quadrant_dirty(Q, false);
} }
_update_dirty_quadrants();
} }
void TileMap::_clear_quadrants() { void TileMap::_clear_quadrants() {

View file

@ -188,7 +188,7 @@ private:
Map<PosKey, Quadrant>::Element *_create_quadrant(const PosKey &p_qk); Map<PosKey, Quadrant>::Element *_create_quadrant(const PosKey &p_qk);
void _erase_quadrant(Map<PosKey, Quadrant>::Element *Q); void _erase_quadrant(Map<PosKey, Quadrant>::Element *Q);
void _make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q); void _make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update = true);
void _recreate_quadrants(); void _recreate_quadrants();
void _clear_quadrants(); void _clear_quadrants();
void _update_dirty_quadrants(); void _update_dirty_quadrants();