Skip to content

Commit 0e8efa6

Browse files
bojidar-bgmyhalibobo
authored andcommitted
Fix some issue with TileMap's and other nodes' boundaries
Fixes godotengine#30348 Addresses a small part of godotengine#30012
1 parent 955f542 commit 0e8efa6

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

scene/2d/path_2d.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Rect2 Path2D::_edit_get_rect() const {
5858
}
5959

6060
bool Path2D::_edit_use_rect() const {
61-
return true;
61+
return curve.is_valid() && curve->get_point_count() != 0;
6262
}
6363

6464
bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {

scene/2d/polygon_2d.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Rect2 Polygon2D::_edit_get_rect() const {
7676
}
7777

7878
bool Polygon2D::_edit_use_rect() const {
79-
return true;
79+
return polygon.size() > 0;
8080
}
8181

8282
bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {

scene/2d/tile_map.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
861861
if (!E && p_tile == INVALID_CELL)
862862
return; //nothing to do
863863

864-
PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
864+
PosKey qk = pk.to_quadrant(_get_quadrant_size());
865865
if (p_tile == INVALID_CELL) {
866866
//erase existing
867867
tile_map.erase(pk);
@@ -1020,7 +1020,7 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
10201020
E->get().autotile_coord_x = (int)coord.x;
10211021
E->get().autotile_coord_y = (int)coord.y;
10221022

1023-
PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
1023+
PosKey qk = p.to_quadrant(_get_quadrant_size());
10241024
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
10251025
_make_quadrant_dirty(Q);
10261026

@@ -1117,7 +1117,7 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord)
11171117
c.autotile_coord_y = p_coord.y;
11181118
tile_map[pk] = c;
11191119

1120-
PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
1120+
PosKey qk = pk.to_quadrant(_get_quadrant_size());
11211121
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
11221122

11231123
if (!Q)
@@ -1144,7 +1144,7 @@ void TileMap::_recreate_quadrants() {
11441144

11451145
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
11461146

1147-
PosKey qk(E->key().x / _get_quadrant_size(), E->key().y / _get_quadrant_size());
1147+
PosKey qk = PosKey(E->key().x, E->key().y).to_quadrant(_get_quadrant_size());
11481148

11491149
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
11501150
if (!Q) {
@@ -1281,7 +1281,11 @@ PoolVector<int> TileMap::_get_tile_data() const {
12811281
}
12821282

12831283
Rect2 TileMap::_edit_get_rect() const {
1284-
const_cast<TileMap *>(this)->update_dirty_quadrants();
1284+
if (pending_update) {
1285+
const_cast<TileMap *>(this)->update_dirty_quadrants();
1286+
} else {
1287+
const_cast<TileMap *>(this)->_recompute_rect_cache();
1288+
}
12851289
return rect_cache;
12861290
}
12871291

scene/2d/tile_map.h

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ class TileMap : public Node2D {
9494

9595
bool operator==(const PosKey &p_k) const { return (y == p_k.y && x == p_k.x); }
9696

97+
PosKey to_quadrant(const int &p_quadrant_size) const {
98+
// rounding down, instead of simply rounding towards zero (truncating)
99+
return PosKey(
100+
x > 0 ? x / p_quadrant_size : (x - (p_quadrant_size - 1)) / p_quadrant_size,
101+
y > 0 ? y / p_quadrant_size : (y - (p_quadrant_size - 1)) / p_quadrant_size);
102+
}
103+
97104
PosKey(int16_t p_x, int16_t p_y) {
98105
x = p_x;
99106
y = p_y;

0 commit comments

Comments
 (0)