diff options
author | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2017-02-20 23:02:03 +0200 |
---|---|---|
committer | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2017-02-20 23:02:03 +0200 |
commit | 136e1e18bac67f0df8e698e5500dc3379966da6c (patch) | |
tree | 38545382cf3141590e65fec0254f89ced5ab3983 /scene/2d/tile_map.cpp | |
parent | 5e3fc7d06956dcda8b50cd4f028c83cf967f7223 (diff) | |
download | redot-engine-136e1e18bac67f0df8e698e5500dc3379966da6c.tar.gz |
Add Rect2 TileMap::get_used_rect(), closes #4390
Diffstat (limited to 'scene/2d/tile_map.cpp')
-rw-r--r-- | scene/2d/tile_map.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 5de0b93ed9..15fbec4441 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -730,6 +730,7 @@ void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bo c.transpose=p_transpose; _make_quadrant_dirty(Q); + used_size_cache_dirty=true; } @@ -818,6 +819,7 @@ void TileMap::clear() { _clear_quadrants(); tile_map.clear(); + used_size_cache_dirty=true; } void TileMap::_set_tile_data(const PoolVector<int>& p_data) { @@ -1159,6 +1161,28 @@ Array TileMap::get_used_cells() const { return a; } +Rect2 TileMap::get_used_rect() { // Not const because of cache + + if (used_size_cache_dirty) { + if(tile_map.size() > 0) { + used_size_cache = Rect2(tile_map.front()->key().x, tile_map.front()->key().y, 0, 0); + + for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) { + used_size_cache.expand_to(Vector2(E->key().x, E->key().y)); + } + + used_size_cache.size += Vector2(1,1); + } else { + used_size_cache = Rect2(); + } + + used_size_cache_dirty = false; + } + + return used_size_cache; +} + + void TileMap::set_occluder_light_mask(int p_mask) { occluder_light_mask=p_mask; @@ -1251,6 +1275,7 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("clear"),&TileMap::clear); ClassDB::bind_method(D_METHOD("get_used_cells"),&TileMap::get_used_cells); + ClassDB::bind_method(D_METHOD("get_used_rect"),&TileMap::get_used_rect); ClassDB::bind_method(D_METHOD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false)); ClassDB::bind_method(D_METHOD("world_to_map","worldpos"),&TileMap::world_to_map); @@ -1305,6 +1330,7 @@ TileMap::TileMap() { rect_cache_dirty=true; + used_size_cache_dirty=true; pending_update=false; quadrant_order_dirty=false; quadrant_size=16; |