summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/camera_2d.cpp18
-rw-r--r--scene/2d/collision_polygon_2d.cpp2
-rw-r--r--scene/2d/cpu_particles_2d.cpp5
-rw-r--r--scene/2d/path_2d.cpp2
-rw-r--r--scene/2d/polygon_2d.cpp2
-rw-r--r--scene/2d/tile_map.cpp16
-rw-r--r--scene/2d/tile_map.h7
7 files changed, 24 insertions, 28 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index a0d74dd283..6011941142 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -140,9 +140,6 @@ Transform2D Camera2D::get_camera_transform() {
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom);
- if (offset != Vector2())
- screen_rect.position += offset;
-
if (limit_smoothing_enabled) {
if (screen_rect.position.x < limit[MARGIN_LEFT])
camera_pos.x -= screen_rect.position.x - limit[MARGIN_LEFT];
@@ -193,21 +190,8 @@ Transform2D Camera2D::get_camera_transform() {
if (screen_rect.position.y < limit[MARGIN_TOP])
screen_rect.position.y = limit[MARGIN_TOP];
- if (offset != Vector2()) {
-
+ if (offset != Vector2())
screen_rect.position += offset;
- if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT])
- screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
-
- if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
- screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;
-
- if (screen_rect.position.x < limit[MARGIN_LEFT])
- screen_rect.position.x = limit[MARGIN_LEFT];
-
- if (screen_rect.position.y < limit[MARGIN_TOP])
- screen_rect.position.y = limit[MARGIN_TOP];
- }
camera_screen_center = screen_rect.position + screen_rect.size * 0.5;
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index ef7644fcab..bb144dda96 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -70,7 +70,7 @@ void CollisionPolygon2D::_build_polygon() {
w[(i << 1) + 1] = polygon[(i + 1) % polygon.size()];
}
- w = PoolVector<Vector2>::Write();
+ w.release();
concave->set_segments(segments);
parent->shape_owner_add_shape(owner_id, concave);
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 2091085420..591933d972 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -661,8 +661,9 @@ void CPUParticles2D::_particles_process(float p_delta) {
//do none
} break;
case EMISSION_SHAPE_SPHERE: {
- Vector3 sphere_shape = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0).normalized() * emission_sphere_radius;
- p.transform[2] = Vector2(sphere_shape.x, sphere_shape.y);
+ float s = Math::randf(), t = 2.0 * Math_PI * Math::randf();
+ float radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
+ p.transform[2] = Vector2(Math::cos(t), Math::sin(t)) * radius;
} break;
case EMISSION_SHAPE_RECTANGLE: {
p.transform[2] = Vector2(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_rect_extents;
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index e062067248..f2f53d4354 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -58,7 +58,7 @@ Rect2 Path2D::_edit_get_rect() const {
}
bool Path2D::_edit_use_rect() const {
- return true;
+ return curve.is_valid() && curve->get_point_count() != 0;
}
bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index f6f1bad581..32a0b732c0 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -76,7 +76,7 @@ Rect2 Polygon2D::_edit_get_rect() const {
}
bool Polygon2D::_edit_use_rect() const {
- return true;
+ return polygon.size() > 0;
}
bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 22bc0e44e6..cf544a5473 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -861,7 +861,7 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
if (!E && p_tile == INVALID_CELL)
return; //nothing to do
- PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
+ PosKey qk = pk.to_quadrant(_get_quadrant_size());
if (p_tile == INVALID_CELL) {
//erase existing
tile_map.erase(pk);
@@ -1020,7 +1020,7 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) {
E->get().autotile_coord_x = (int)coord.x;
E->get().autotile_coord_y = (int)coord.y;
- PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
+ PosKey qk = p.to_quadrant(_get_quadrant_size());
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
_make_quadrant_dirty(Q);
@@ -1117,7 +1117,7 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord)
c.autotile_coord_y = p_coord.y;
tile_map[pk] = c;
- PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
+ PosKey qk = pk.to_quadrant(_get_quadrant_size());
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
if (!Q)
@@ -1144,7 +1144,7 @@ void TileMap::_recreate_quadrants() {
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
- PosKey qk(E->key().x / _get_quadrant_size(), E->key().y / _get_quadrant_size());
+ PosKey qk = PosKey(E->key().x, E->key().y).to_quadrant(_get_quadrant_size());
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
if (!Q) {
@@ -1275,13 +1275,17 @@ PoolVector<int> TileMap::_get_tile_data() const {
idx += 3;
}
- w = PoolVector<int>::Write();
+ w.release();
return data;
}
Rect2 TileMap::_edit_get_rect() const {
- const_cast<TileMap *>(this)->update_dirty_quadrants();
+ if (pending_update) {
+ const_cast<TileMap *>(this)->update_dirty_quadrants();
+ } else {
+ const_cast<TileMap *>(this)->_recompute_rect_cache();
+ }
return rect_cache;
}
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 6c9648ff32..e30b7eff83 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -94,6 +94,13 @@ private:
bool operator==(const PosKey &p_k) const { return (y == p_k.y && x == p_k.x); }
+ PosKey to_quadrant(const int &p_quadrant_size) const {
+ // rounding down, instead of simply rounding towards zero (truncating)
+ return PosKey(
+ x > 0 ? x / p_quadrant_size : (x - (p_quadrant_size - 1)) / p_quadrant_size,
+ y > 0 ? y / p_quadrant_size : (y - (p_quadrant_size - 1)) / p_quadrant_size);
+ }
+
PosKey(int16_t p_x, int16_t p_y) {
x = p_x;
y = p_y;