Skip to content

Commit e17a57d

Browse files
bojidar-bgakien-mga
authored andcommitted
Fix some issue with TileMap's and other nodes' boundaries
Fixes godotengine#30348 Addresses a small part of godotengine#30012 (cherry picked from commit ebf2a4d)
1 parent 0f0016b commit e17a57d

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
@@ -760,7 +760,7 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
760760
if (!E && p_tile == INVALID_CELL)
761761
return; //nothing to do
762762

763-
PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
763+
PosKey qk = pk.to_quadrant(_get_quadrant_size());
764764
if (p_tile == INVALID_CELL) {
765765
//erase existing
766766
tile_map.erase(pk);
@@ -919,7 +919,7 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
919919
E->get().autotile_coord_x = (int)coord.x;
920920
E->get().autotile_coord_y = (int)coord.y;
921921

922-
PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
922+
PosKey qk = p.to_quadrant(_get_quadrant_size());
923923
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
924924
_make_quadrant_dirty(Q);
925925

@@ -1007,7 +1007,7 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord)
10071007
c.autotile_coord_y = p_coord.y;
10081008
tile_map[pk] = c;
10091009

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

10131013
if (!Q)
@@ -1034,7 +1034,7 @@ void TileMap::_recreate_quadrants() {
10341034

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

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

10391039
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
10401040
if (!Q) {
@@ -1174,7 +1174,11 @@ PoolVector<int> TileMap::_get_tile_data() const {
11741174
}
11751175

11761176
Rect2 TileMap::_edit_get_rect() const {
1177-
const_cast<TileMap *>(this)->update_dirty_quadrants();
1177+
if (pending_update) {
1178+
const_cast<TileMap *>(this)->update_dirty_quadrants();
1179+
} else {
1180+
const_cast<TileMap *>(this)->_recompute_rect_cache();
1181+
}
11781182
return rect_cache;
11791183
}
11801184

scene/2d/tile_map.h

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

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

93+
PosKey to_quadrant(const int &p_quadrant_size) const {
94+
// rounding down, instead of simply rounding towards zero (truncating)
95+
return PosKey(
96+
x > 0 ? x / p_quadrant_size : (x - (p_quadrant_size - 1)) / p_quadrant_size,
97+
y > 0 ? y / p_quadrant_size : (y - (p_quadrant_size - 1)) / p_quadrant_size);
98+
}
99+
93100
PosKey(int16_t p_x, int16_t p_y) {
94101
x = p_x;
95102
y = p_y;

0 commit comments

Comments
 (0)