summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/import/editor_importer_bake_reset.cpp4
-rw-r--r--editor/import/resource_importer_scene.cpp25
-rw-r--r--scene/2d/tile_map.cpp24
-rw-r--r--scene/2d/tile_map.h4
4 files changed, 25 insertions, 32 deletions
diff --git a/editor/import/editor_importer_bake_reset.cpp b/editor/import/editor_importer_bake_reset.cpp
index 939c47faa4..541eab4f40 100644
--- a/editor/import/editor_importer_bake_reset.cpp
+++ b/editor/import/editor_importer_bake_reset.cpp
@@ -151,7 +151,9 @@ void BakeReset::_align_animations(AnimationPlayer *p_ap, const Map<StringName, B
}
void BakeReset::_fetch_reset_animation(AnimationPlayer *p_ap, Map<StringName, BakeResetRestBone> &r_rest_bones, const String &p_bake_anim) {
- ERR_FAIL_NULL(p_ap);
+ if (!p_ap) {
+ return;
+ }
List<StringName> anim_names;
p_ap->get_animation_list(&anim_names);
Node *root = p_ap->get_owner();
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 1e642462dc..50aae6c434 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -234,21 +234,6 @@ static String _fixstr(const String &p_what, const String &p_str) {
return what;
}
-static void _gen_shape_list(const Ref<Mesh> &mesh, List<Ref<Shape3D>> &r_shape_list, bool p_convex) {
- ERR_FAIL_NULL_MSG(mesh, "Cannot generate shape list with null mesh value");
- if (!p_convex) {
- Ref<Shape3D> shape = mesh->create_trimesh_shape();
- r_shape_list.push_back(shape);
- } else {
- Vector<Ref<Shape3D>> cd = mesh->convex_decompose();
- if (cd.size()) {
- for (int i = 0; i < cd.size(); i++) {
- r_shape_list.push_back(cd[i]);
- }
- }
- }
-}
-
static void _pre_gen_shape_list(const Ref<EditorSceneImporterMesh> &mesh, List<Ref<Shape3D>> &r_shape_list, bool p_convex) {
ERR_FAIL_NULL_MSG(mesh, "Cannot generate shape list with null mesh value");
if (!p_convex) {
@@ -426,7 +411,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
if (collision_map.has(mesh)) {
shapes = collision_map[mesh];
} else {
- _gen_shape_list(mesh, shapes, true);
+ _pre_gen_shape_list(mesh, shapes, true);
}
RigidBody3D *rigid_body = memnew(RigidBody3D);
@@ -452,10 +437,10 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
if (collision_map.has(mesh)) {
shapes = collision_map[mesh];
} else if (_teststr(name, "col")) {
- _gen_shape_list(mesh, shapes, false);
+ _pre_gen_shape_list(mesh, shapes, false);
collision_map[mesh] = shapes;
} else if (_teststr(name, "convcol")) {
- _gen_shape_list(mesh, shapes, true);
+ _pre_gen_shape_list(mesh, shapes, true);
collision_map[mesh] = shapes;
}
@@ -510,11 +495,11 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
if (collision_map.has(mesh)) {
shapes = collision_map[mesh];
} else if (_teststr(mesh->get_name(), "col")) {
- _gen_shape_list(mesh, shapes, false);
+ _pre_gen_shape_list(mesh, shapes, false);
collision_map[mesh] = shapes;
mesh->set_name(_fixstr(mesh->get_name(), "col"));
} else if (_teststr(mesh->get_name(), "convcol")) {
- _gen_shape_list(mesh, shapes, true);
+ _pre_gen_shape_list(mesh, shapes, true);
collision_map[mesh] = shapes;
mesh->set_name(_fixstr(mesh->get_name(), "convcol"));
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 6afa0c0779..e2a415e5aa 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1576,7 +1576,7 @@ void TileMap::set_cell(int p_layer, const Vector2i &p_coords, int p_source_id, c
_make_quadrant_dirty(Q);
}
- used_size_cache_dirty = true;
+ used_rect_cache_dirty = true;
} else {
if (!E) {
// Insert a new cell in the tile map.
@@ -1604,7 +1604,7 @@ void TileMap::set_cell(int p_layer, const Vector2i &p_coords, int p_source_id, c
c.alternative_tile = alternative_tile;
_make_quadrant_dirty(Q);
- used_size_cache_dirty = true;
+ used_rect_cache_dirty = true;
}
}
@@ -1800,7 +1800,7 @@ void TileMap::clear_layer(int p_layer) {
_clear_layer_internals(p_layer);
layers[p_layer].tile_map.clear();
- used_size_cache_dirty = true;
+ used_rect_cache_dirty = true;
}
void TileMap::clear() {
@@ -1809,7 +1809,7 @@ void TileMap::clear() {
for (unsigned int i = 0; i < layers.size(); i++) {
layers[i].tile_map.clear();
}
- used_size_cache_dirty = true;
+ used_rect_cache_dirty = true;
}
void TileMap::_set_tile_data(int p_layer, const Vector<int> &p_data) {
@@ -2666,25 +2666,31 @@ TypedArray<Vector2i> TileMap::get_used_cells(int p_layer) const {
Rect2 TileMap::get_used_rect() { // Not const because of cache
// Return the rect of the currently used area
- if (used_size_cache_dirty) {
+ if (used_rect_cache_dirty) {
bool first = true;
+ used_rect_cache = Rect2i();
+
for (unsigned int i = 0; i < layers.size(); i++) {
const Map<Vector2i, TileMapCell> &tile_map = layers[i].tile_map;
if (tile_map.size() > 0) {
if (first) {
- used_size_cache = Rect2(tile_map.front()->key().x, tile_map.front()->key().y, 1, 1);
+ used_rect_cache = Rect2i(tile_map.front()->key().x, tile_map.front()->key().y, 0, 0);
first = false;
}
for (Map<Vector2i, TileMapCell>::Element *E = tile_map.front(); E; E = E->next()) {
- used_size_cache.expand_to(Vector2(E->key().x + 1, E->key().y + 1));
+ used_rect_cache.expand_to(Vector2i(E->key().x, E->key().y));
}
}
}
- used_size_cache_dirty = false;
+
+ if (!first) { // first is true if every layer is empty.
+ used_rect_cache.size += Vector2i(1, 1); // The cache expands to top-left coordinate, so we add one full tile.
+ }
+ used_rect_cache_dirty = false;
}
- return used_size_cache;
+ return used_rect_cache;
}
// --- Override some methods of the CanvasItem class to pass the changes to the quadrants CanvasItems ---
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 4800780f94..dce18f7682 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -213,8 +213,8 @@ private:
// Rect.
Rect2 rect_cache;
bool rect_cache_dirty = true;
- Rect2 used_size_cache;
- bool used_size_cache_dirty = true;
+ Rect2i used_rect_cache;
+ bool used_rect_cache_dirty = true;
// TileMap layers.
struct TileMapLayer {