diff options
author | Andrew Thomas <andrewjamest1993@protonmail.com> | 2017-12-05 18:14:33 -0600 |
---|---|---|
committer | Andrew Thomas <andrewjamest1993@protonmail.com> | 2017-12-16 08:18:54 -0600 |
commit | d8c4324cfbe88841055170e04a16dbac9aa4ac75 (patch) | |
tree | d60288adf2c7c4045f4e408732cc5dc33c6a722c /scene/2d | |
parent | 5938466c848becb269f002191901487135e39ce3 (diff) |
TileMap: Add update_bitmask_region(2), expose update_bitmask_area(1) and update_bitmask_region(2) to GDscript
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/tile_map.cpp | 23 | ||||
-rw-r--r-- | scene/2d/tile_map.h | 1 |
2 files changed, 24 insertions, 0 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index c0d0a6e011..69104ea4b2 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -759,6 +759,26 @@ void TileMap::update_bitmask_area(const Vector2 &p_pos) { } } +void TileMap::update_bitmask_region(const Vector2 &p_start, const Vector2 &p_end) { + + if ((p_end.x < p_start.x || p_end.y < p_start.y) || (p_end.x == p_start.x && p_end.y == p_start.y)) { + int i; + Array a = get_used_cells(); + for (i = 0; i < a.size(); i++) { + // update_bitmask_area() in order to update cells adjacent to the + // current cell, since ordering in array may not be reliable + Vector2 vector = (Vector2)a[i]; + update_bitmask_area(Vector2(vector.x, vector.y)); + } + return; + } + for (int x = p_start.x - 1; x <= p_end.x + 1; x++) { + for (int y = p_start.y - 1; y <= p_end.y + 1; y++) { + update_cell_bitmask(x, y); + } + } +} + void TileMap::update_cell_bitmask(int p_x, int p_y) { PosKey p(p_x, p_y); @@ -1531,6 +1551,9 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("_recreate_quadrants"), &TileMap::_recreate_quadrants); ClassDB::bind_method(D_METHOD("_update_dirty_quadrants"), &TileMap::_update_dirty_quadrants); + ClassDB::bind_method(D_METHOD("update_bitmask_area"), &TileMap::update_bitmask_area); + ClassDB::bind_method(D_METHOD("update_bitmask_region", "start", "end"), &TileMap::update_bitmask_region, DEFVAL(Vector2()), DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("_set_tile_data"), &TileMap::_set_tile_data); ClassDB::bind_method(D_METHOD("_get_tile_data"), &TileMap::_get_tile_data); diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 8eecf48df2..b7f1a57023 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -251,6 +251,7 @@ public: void make_bitmask_area_dirty(const Vector2 &p_pos); void update_bitmask_area(const Vector2 &p_pos); + void update_bitmask_region(const Vector2 &p_start = Vector2(), const Vector2 &p_end = Vector2()); void update_cell_bitmask(int p_x, int p_y); void update_dirty_bitmask(); |