summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/tile_map.cpp61
-rw-r--r--scene/3d/lightmap_gi.cpp19
-rw-r--r--scene/animation/animation_player.cpp64
-rw-r--r--scene/gui/popup.cpp6
-rw-r--r--scene/resources/animation.cpp44
-rw-r--r--scene/resources/immediate_mesh.cpp20
-rw-r--r--scene/resources/importer_mesh.cpp19
-rw-r--r--scene/resources/packed_scene.cpp3
-rw-r--r--scene/resources/surface_tool.cpp34
-rw-r--r--scene/resources/text_paragraph.cpp38
-rw-r--r--scene/resources/tile_set.cpp16
11 files changed, 158 insertions, 166 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index a30b3c900d..05d28e8a0e 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -803,10 +803,10 @@ void TileMap::_make_quadrant_dirty(HashMap<Vector2i, TileMapQuadrant>::Iterator
void TileMap::_make_all_quadrants_dirty() {
// Make all quandrants dirty, then trigger an update later.
- for (unsigned int layer = 0; layer < layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
if (!E.value.dirty_list_element.in_list()) {
- layers[layer].dirty_quadrant_list.add(&E.value.dirty_list_element);
+ layer.dirty_quadrant_list.add(&E.value.dirty_list_element);
}
}
}
@@ -1014,8 +1014,8 @@ void TileMap::_rendering_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_CANVAS: {
bool node_visible = is_visible_in_tree();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
for (const KeyValue<Vector2i, RID> &kv : q.occluders) {
Transform2D xform;
@@ -1030,8 +1030,8 @@ void TileMap::_rendering_notification(int p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
bool node_visible = is_visible_in_tree();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
// Update occluders transform.
@@ -1050,8 +1050,8 @@ void TileMap::_rendering_notification(int p_what) {
if (!is_inside_tree()) {
return;
}
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
// Update occluders transform.
@@ -1071,8 +1071,8 @@ void TileMap::_rendering_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_CANVAS: {
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
for (const KeyValue<Vector2i, RID> &kv : q.occluders) {
RS::get_singleton()->canvas_light_occluder_attach_to_canvas(kv.value, RID());
@@ -1257,16 +1257,16 @@ void TileMap::_rendering_update_dirty_quadrants(SelfList<TileMapQuadrant>::List
if (_rendering_quadrant_order_dirty) {
int index = -(int64_t)0x80000000; //always must be drawn below children.
- for (int layer = 0; layer < (int)layers.size(); layer++) {
+ for (TileMapLayer &layer : layers) {
// Sort the quadrants coords per local coordinates.
RBMap<Vector2i, Vector2i, TileMapQuadrant::CoordsWorldComparator> local_to_map;
- for (const KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (const KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
local_to_map[map_to_local(E.key)] = E.key;
}
// Sort the quadrants.
for (const KeyValue<Vector2i, Vector2i> &E : local_to_map) {
- TileMapQuadrant &q = layers[layer].quadrant_map[E.value];
+ TileMapQuadrant &q = layer.quadrant_map[E.value];
for (const RID &ci : q.canvas_items) {
RS::get_singleton()->canvas_item_set_draw_index(ci, index++);
}
@@ -1453,8 +1453,8 @@ void TileMap::_physics_notification(int p_what) {
if (is_inside_tree() && (!collision_animatable || in_editor)) {
// Update the new transform directly if we are not in animatable mode.
Transform2D gl_transform = get_global_transform();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
TileMapQuadrant &q = E.value;
for (RID body : q.bodies) {
@@ -1476,8 +1476,8 @@ void TileMap::_physics_notification(int p_what) {
if (is_inside_tree() && !in_editor && collision_animatable) {
// Only active when animatable. Send the new transform to the physics...
new_transform = get_global_transform();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
TileMapQuadrant &q = E.value;
for (RID body : q.bodies) {
@@ -1667,13 +1667,12 @@ void TileMap::_navigation_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
if (is_inside_tree()) {
- for (int layer = 0; layer < (int)layers.size(); layer++) {
+ for (TileMapLayer &layer : layers) {
Transform2D tilemap_xform = get_global_transform();
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
for (const KeyValue<Vector2i, Vector<RID>> &E_region : q.navigation_regions) {
- for (int layer_index = 0; layer_index < E_region.value.size(); layer_index++) {
- RID region = E_region.value[layer_index];
+ for (const RID &region : E_region.value) {
if (!region.is_valid()) {
continue;
}
@@ -2815,8 +2814,8 @@ void TileMap::clear_layer(int p_layer) {
void TileMap::clear() {
// Remove all tiles.
_clear_internals();
- for (unsigned int i = 0; i < layers.size(); i++) {
- layers[i].tile_map.clear();
+ for (TileMapLayer &layer : layers) {
+ layer.tile_map.clear();
}
_recreate_internals();
used_rect_cache_dirty = true;
@@ -3956,15 +3955,15 @@ PackedStringArray TileMap::get_configuration_warnings() const {
// Retrieve the set of Z index values with a Y-sorted layer.
RBSet<int> y_sorted_z_index;
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- if (layers[layer].y_sort_enabled) {
- y_sorted_z_index.insert(layers[layer].z_index);
+ for (const TileMapLayer &layer : layers) {
+ if (layer.y_sort_enabled) {
+ y_sorted_z_index.insert(layer.z_index);
}
}
// Check if we have a non-sorted layer in a Z-index with a Y-sorted layer.
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- if (!layers[layer].y_sort_enabled && y_sorted_z_index.has(layers[layer].z_index)) {
+ for (const TileMapLayer &layer : layers) {
+ if (!layer.y_sort_enabled && y_sorted_z_index.has(layer.z_index)) {
warnings.push_back(RTR("A Y-sorted layer has the same Z-index value as a not Y-sorted layer.\nThis may lead to unwanted behaviors, as a layer that is not Y-sorted will be Y-sorted as a whole with tiles from Y-sorted layers."));
break;
}
@@ -3973,8 +3972,8 @@ PackedStringArray TileMap::get_configuration_warnings() const {
if (tile_set.is_valid() && tile_set->get_tile_shape() == TileSet::TILE_SHAPE_ISOMETRIC) {
bool warn = !is_y_sort_enabled();
if (!warn) {
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- if (!layers[layer].y_sort_enabled) {
+ for (const TileMapLayer &layer : layers) {
+ if (!layer.y_sort_enabled) {
warn = true;
break;
}
diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp
index 6940bad4a6..f308ad0999 100644
--- a/scene/3d/lightmap_gi.cpp
+++ b/scene/3d/lightmap_gi.cpp
@@ -455,8 +455,8 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
Plane best_plane;
float best_plane_score = -1.0;
- for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
- const BSPSimplex &s = p_simplices[p_simplex_indices[i]];
+ for (const int idx : p_simplex_indices) {
+ const BSPSimplex &s = p_simplices[idx];
for (int j = 0; j < 4; j++) {
uint32_t plane_index = s.planes[j];
if (planes_tested[plane_index] == node_index) {
@@ -484,8 +484,8 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
int over_count = 0;
int under_count = 0;
- for (uint32_t k = 0; k < p_simplex_indices.size(); k++) {
- int side = _bsp_get_simplex_side(p_points, p_simplices, plane, p_simplex_indices[k]);
+ for (const int &index : p_simplex_indices) {
+ int side = _bsp_get_simplex_side(p_points, p_simplices, plane, index);
if (side == -2) {
continue; //this simplex is invalid, skip for now
} else if (side < 0) {
@@ -523,8 +523,7 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
LocalVector<int32_t> indices_under;
//split again, but add to list
- for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
- uint32_t index = p_simplex_indices[i];
+ for (const uint32_t index : p_simplex_indices) {
int side = _bsp_get_simplex_side(p_points, p_simplices, best_plane, index);
if (side == -2) {
@@ -977,8 +976,8 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
}
}
- for (uint32_t i = 0; i < new_probe_positions.size(); i++) {
- probes_found.push_back(new_probe_positions[i]);
+ for (const Vector3 &position : new_probe_positions) {
+ probes_found.push_back(position);
}
}
@@ -1219,8 +1218,8 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
LocalVector<BSPNode> bsp_nodes;
LocalVector<int32_t> planes_tested;
planes_tested.resize(bsp_planes.size());
- for (uint32_t i = 0; i < planes_tested.size(); i++) {
- planes_tested[i] = 0x7FFFFFFF;
+ for (int &index : planes_tested) {
+ index = 0x7FFFFFFF;
}
if (p_bake_step) {
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 0febe580db..047997ca09 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -143,8 +143,8 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
} else if (name.begins_with("libraries")) {
Dictionary d;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- d[animation_libraries[i].name] = animation_libraries[i].library;
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ d[lib.name] = lib.library;
}
r_ret = d;
@@ -1269,13 +1269,13 @@ void AnimationPlayer::_animation_set_cache_update() {
bool clear_cache_needed = false;
// Update changed and add otherwise
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- for (const KeyValue<StringName, Ref<Animation>> &K : animation_libraries[i].library->animations) {
- StringName key = animation_libraries[i].name == StringName() ? K.key : StringName(String(animation_libraries[i].name) + "/" + String(K.key));
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ for (const KeyValue<StringName, Ref<Animation>> &K : lib.library->animations) {
+ StringName key = lib.name == StringName() ? K.key : StringName(String(lib.name) + "/" + String(K.key));
if (!animation_set.has(key)) {
AnimationData ad;
ad.animation = K.value;
- ad.animation_library = animation_libraries[i].name;
+ ad.animation_library = lib.name;
ad.name = key;
ad.last_update = animation_set_update_pass;
animation_set.insert(ad.name, ad);
@@ -1283,11 +1283,11 @@ void AnimationPlayer::_animation_set_cache_update() {
AnimationData &ad = animation_set[key];
if (ad.last_update != animation_set_update_pass) {
// Was not updated, update. If the animation is duplicated, the second one will be ignored.
- if (ad.animation != K.value || ad.animation_library != animation_libraries[i].name) {
+ if (ad.animation != K.value || ad.animation_library != lib.name) {
// Animation changed, update and clear caches.
clear_cache_needed = true;
ad.animation = K.value;
- ad.animation_library = animation_libraries[i].name;
+ ad.animation_library = lib.name;
}
ad.last_update = animation_set_update_pass;
@@ -1405,11 +1405,11 @@ Error AnimationPlayer::add_animation_library(const StringName &p_name, const Ref
int insert_pos = 0;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- ERR_FAIL_COND_V_MSG(animation_libraries[i].name == p_name, ERR_ALREADY_EXISTS, "Can't add animation library twice with name: " + String(p_name));
- ERR_FAIL_COND_V_MSG(animation_libraries[i].library == p_animation_library, ERR_ALREADY_EXISTS, "Can't add animation library twice (adding as '" + p_name.operator String() + "', exists as '" + animation_libraries[i].name.operator String() + "'.");
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ ERR_FAIL_COND_V_MSG(lib.name == p_name, ERR_ALREADY_EXISTS, "Can't add animation library twice with name: " + String(p_name));
+ ERR_FAIL_COND_V_MSG(lib.library == p_animation_library, ERR_ALREADY_EXISTS, "Can't add animation library twice (adding as '" + p_name.operator String() + "', exists as '" + lib.name.operator String() + "'.");
- if (animation_libraries[i].name.operator String() >= p_name.operator String()) {
+ if (lib.name.operator String() >= p_name.operator String()) {
break;
}
@@ -1468,21 +1468,21 @@ void AnimationPlayer::rename_animation_library(const StringName &p_name, const S
#endif
bool found = false;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- ERR_FAIL_COND_MSG(animation_libraries[i].name == p_new_name, "Can't rename animation library to another existing name: " + String(p_new_name));
- if (animation_libraries[i].name == p_name) {
+ for (AnimationLibraryData &lib : animation_libraries) {
+ ERR_FAIL_COND_MSG(lib.name == p_new_name, "Can't rename animation library to another existing name: " + String(p_new_name));
+ if (lib.name == p_name) {
found = true;
- animation_libraries[i].name = p_new_name;
+ lib.name = p_new_name;
// rename connections
- animation_libraries[i].library->disconnect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added));
- animation_libraries[i].library->disconnect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed));
- animation_libraries[i].library->disconnect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed));
+ lib.library->disconnect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added));
+ lib.library->disconnect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed));
+ lib.library->disconnect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed));
- animation_libraries[i].library->connect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added).bind(p_new_name));
- animation_libraries[i].library->connect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed).bind(p_new_name));
- animation_libraries[i].library->connect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed).bind(p_new_name));
+ lib.library->connect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added).bind(p_new_name));
+ lib.library->connect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed).bind(p_new_name));
+ lib.library->connect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed).bind(p_new_name));
- for (const KeyValue<StringName, Ref<Animation>> &K : animation_libraries[i].library->animations) {
+ for (const KeyValue<StringName, Ref<Animation>> &K : lib.library->animations) {
StringName old_name = p_name == StringName() ? K.key : StringName(String(p_name) + "/" + String(K.key));
StringName new_name = p_new_name == StringName() ? K.key : StringName(String(p_new_name) + "/" + String(K.key));
_rename_animation(old_name, new_name);
@@ -1502,8 +1502,8 @@ void AnimationPlayer::rename_animation_library(const StringName &p_name, const S
}
bool AnimationPlayer::has_animation_library(const StringName &p_name) const {
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- if (animation_libraries[i].name == p_name) {
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ if (lib.name == p_name) {
return true;
}
}
@@ -1512,9 +1512,9 @@ bool AnimationPlayer::has_animation_library(const StringName &p_name) const {
}
Ref<AnimationLibrary> AnimationPlayer::get_animation_library(const StringName &p_name) const {
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- if (animation_libraries[i].name == p_name) {
- return animation_libraries[i].library;
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ if (lib.name == p_name) {
+ return lib.library;
}
}
ERR_FAIL_V(Ref<AnimationLibrary>());
@@ -1522,15 +1522,15 @@ Ref<AnimationLibrary> AnimationPlayer::get_animation_library(const StringName &p
TypedArray<StringName> AnimationPlayer::_get_animation_library_list() const {
TypedArray<StringName> ret;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- ret.push_back(animation_libraries[i].name);
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ ret.push_back(lib.name);
}
return ret;
}
void AnimationPlayer::get_animation_library_list(List<StringName> *p_libraries) const {
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- p_libraries->push_back(animation_libraries[i].name);
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ p_libraries->push_back(lib.name);
}
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index c939e7a48a..2ea1b93810 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -59,9 +59,9 @@ void Popup::_initialize_visible_parents() {
void Popup::_deinitialize_visible_parents() {
if (is_embedded()) {
- for (uint32_t i = 0; i < visible_parents.size(); ++i) {
- visible_parents[i]->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused));
- visible_parents[i]->disconnect("tree_exited", callable_mp(this, &Popup::_deinitialize_visible_parents));
+ for (Window *parent_window : visible_parents) {
+ parent_window->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused));
+ parent_window->disconnect("tree_exited", callable_mp(this, &Popup::_deinitialize_visible_parents));
}
visible_parents.clear();
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index b371266c83..50f3015814 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -4754,17 +4754,17 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
// The frame has advanced, time to validate the previous frame
uint32_t current_page_size = base_page_size;
- for (uint32_t i = 0; i < data_tracks.size(); i++) {
- uint32_t track_size = data_tracks[i].data.size(); // track size
- track_size += data_tracks[i].get_temp_packet_size(); // Add the temporary data
+ for (const AnimationCompressionDataState &state : data_tracks) {
+ uint32_t track_size = state.data.size(); // track size
+ track_size += state.get_temp_packet_size(); // Add the temporary data
if (track_size > Compression::MAX_DATA_TRACK_SIZE) {
rollback = true; //track to large, time track can't point to keys any longer, because key offset is 12 bits
break;
}
current_page_size += track_size;
}
- for (uint32_t i = 0; i < time_tracks.size(); i++) {
- current_page_size += time_tracks[i].packets.size() * 4; // time packet is 32 bits
+ for (const AnimationCompressionTimeState &state : time_tracks) {
+ current_page_size += state.packets.size() * 4; // time packet is 32 bits
}
if (!rollback && current_page_size > p_page_size) {
@@ -4776,22 +4776,22 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
if (rollback) {
// Not valid any longer, so rollback and commit page
- for (uint32_t i = 0; i < data_tracks.size(); i++) {
- data_tracks[i].temp_packets.resize(data_tracks[i].validated_packet_count);
+ for (AnimationCompressionDataState &state : data_tracks) {
+ state.temp_packets.resize(state.validated_packet_count);
}
- for (uint32_t i = 0; i < time_tracks.size(); i++) {
- time_tracks[i].key_index = time_tracks[i].validated_key_index; //rollback key
- time_tracks[i].packets.resize(time_tracks[i].validated_packet_count);
+ for (AnimationCompressionTimeState &state : time_tracks) {
+ state.key_index = state.validated_key_index; //rollback key
+ state.packets.resize(state.validated_packet_count);
}
} else {
// All valid, so save rollback information
- for (uint32_t i = 0; i < data_tracks.size(); i++) {
- data_tracks[i].validated_packet_count = data_tracks[i].temp_packets.size();
+ for (AnimationCompressionDataState &state : data_tracks) {
+ state.validated_packet_count = state.temp_packets.size();
}
- for (uint32_t i = 0; i < time_tracks.size(); i++) {
- time_tracks[i].validated_key_index = time_tracks[i].key_index;
- time_tracks[i].validated_packet_count = time_tracks[i].packets.size();
+ for (AnimationCompressionTimeState &state : time_tracks) {
+ state.validated_key_index = state.key_index;
+ state.validated_packet_count = state.packets.size();
}
// Accept this frame as the frame being processed (as long as it exists)
@@ -4976,8 +4976,8 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
}
uint32_t new_size = 0;
- for (uint32_t i = 0; i < compression.pages.size(); i++) {
- new_size += compression.pages[i].data.size();
+ for (const Compression::Page &page : compression.pages) {
+ new_size += page.data.size();
}
print_line("Original size: " + itos(orig_size) + " - Compressed size: " + itos(new_size) + " " + String::num(float(new_size) / float(orig_size) * 100, 2) + "% pages: " + itos(compression.pages.size()));
@@ -5289,8 +5289,8 @@ int Animation::_get_compressed_key_count(uint32_t p_compressed_track) const {
int key_count = 0;
- for (uint32_t i = 0; i < compression.pages.size(); i++) {
- const uint8_t *page_data = compression.pages[i].data.ptr();
+ for (const Compression::Page &page : compression.pages) {
+ const uint8_t *page_data = page.data.ptr();
// Little endian assumed. No major big endian hardware exists any longer, but in case it does it will need to be supported.
const uint32_t *indices = (const uint32_t *)page_data;
const uint16_t *time_keys = (const uint16_t *)&page_data[indices[p_compressed_track * 3 + 0]];
@@ -5323,8 +5323,8 @@ bool Animation::_fetch_compressed_by_index(uint32_t p_compressed_track, int p_in
ERR_FAIL_COND_V(!compression.enabled, false);
ERR_FAIL_UNSIGNED_INDEX_V(p_compressed_track, compression.bounds.size(), false);
- for (uint32_t i = 0; i < compression.pages.size(); i++) {
- const uint8_t *page_data = compression.pages[i].data.ptr();
+ for (const Compression::Page &page : compression.pages) {
+ const uint8_t *page_data = page.data.ptr();
// Little endian assumed. No major big endian hardware exists any longer, but in case it does it will need to be supported.
const uint32_t *indices = (const uint32_t *)page_data;
const uint16_t *time_keys = (const uint16_t *)&page_data[indices[p_compressed_track * 3 + 0]];
@@ -5374,7 +5374,7 @@ bool Animation::_fetch_compressed_by_index(uint32_t p_compressed_track, int p_in
}
}
- r_time = compression.pages[i].time_offset + double(frame) / double(compression.fps);
+ r_time = page.time_offset + double(frame) / double(compression.fps);
for (uint32_t l = 0; l < COMPONENTS; l++) {
r_value[l] = decode[l];
}
diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp
index f4a0db3930..48d609da97 100644
--- a/scene/resources/immediate_mesh.cpp
+++ b/scene/resources/immediate_mesh.cpp
@@ -41,8 +41,8 @@ void ImmediateMesh::surface_set_color(const Color &p_color) {
if (!uses_colors) {
colors.resize(vertices.size());
- for (uint32_t i = 0; i < colors.size(); i++) {
- colors[i] = p_color;
+ for (Color &color : colors) {
+ color = p_color;
}
uses_colors = true;
}
@@ -54,8 +54,8 @@ void ImmediateMesh::surface_set_normal(const Vector3 &p_normal) {
if (!uses_normals) {
normals.resize(vertices.size());
- for (uint32_t i = 0; i < normals.size(); i++) {
- normals[i] = p_normal;
+ for (Vector3 &normal : normals) {
+ normal = p_normal;
}
uses_normals = true;
}
@@ -66,8 +66,8 @@ void ImmediateMesh::surface_set_tangent(const Plane &p_tangent) {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
if (!uses_tangents) {
tangents.resize(vertices.size());
- for (uint32_t i = 0; i < tangents.size(); i++) {
- tangents[i] = p_tangent;
+ for (Plane &tangent : tangents) {
+ tangent = p_tangent;
}
uses_tangents = true;
}
@@ -78,8 +78,8 @@ void ImmediateMesh::surface_set_uv(const Vector2 &p_uv) {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
if (!uses_uvs) {
uvs.resize(vertices.size());
- for (uint32_t i = 0; i < uvs.size(); i++) {
- uvs[i] = p_uv;
+ for (Vector2 &uv : uvs) {
+ uv = p_uv;
}
uses_uvs = true;
}
@@ -90,8 +90,8 @@ void ImmediateMesh::surface_set_uv2(const Vector2 &p_uv2) {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
if (!uses_uv2s) {
uv2s.resize(vertices.size());
- for (uint32_t i = 0; i < uv2s.size(); i++) {
- uv2s[i] = p_uv2;
+ for (Vector2 &uv : uv2s) {
+ uv = p_uv2;
}
uses_uv2s = true;
}
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp
index eefa5aa14a..55b633a40c 100644
--- a/scene/resources/importer_mesh.cpp
+++ b/scene/resources/importer_mesh.cpp
@@ -364,9 +364,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const LocalVector<Pair<int, int>> &close_verts = E->value;
bool found = false;
- for (unsigned int k = 0; k < close_verts.size(); k++) {
- const Pair<int, int> &idx = close_verts[k];
-
+ for (const Pair<int, int> &idx : close_verts) {
bool is_uvs_close = (!uvs_ptr || uvs_ptr[j].distance_squared_to(uvs_ptr[idx.second]) < CMP_EPSILON2);
bool is_uv2s_close = (!uv2s_ptr || uv2s_ptr[j].distance_squared_to(uv2s_ptr[idx.second]) < CMP_EPSILON2);
ERR_FAIL_INDEX(idx.second, normals.size());
@@ -599,8 +597,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const LocalVector<int> &corners = vertex_corners[j];
const Vector3 &vertex_normal = normals_ptr[j];
- for (unsigned int k = 0; k < corners.size(); k++) {
- const int &corner_idx = corners[k];
+ for (const int &corner_idx : corners) {
const Vector3 &ray_normal = ray_normals[corner_idx];
if (ray_normal.length_squared() < CMP_EPSILON2) {
@@ -635,8 +632,8 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
split_vertex_indices.push_back(j);
split_vertex_normals.push_back(n);
int new_idx = split_vertex_count++;
- for (unsigned int l = 0; l < group_indices.size(); l++) {
- new_indices_ptr[group_indices[l]] = new_idx;
+ for (const int &index : group_indices) {
+ new_indices_ptr[index] = new_idx;
}
}
}
@@ -1241,10 +1238,10 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
}
//generate surfaces
- for (unsigned int i = 0; i < surfaces_tools.size(); i++) {
- surfaces_tools[i]->index();
- Array arrays = surfaces_tools[i]->commit_to_arrays();
- add_surface(surfaces_tools[i]->get_primitive_type(), arrays, Array(), Dictionary(), surfaces_tools[i]->get_material(), surfaces_tools[i]->get_meta("name"));
+ for (Ref<SurfaceTool> &tool : surfaces_tools) {
+ tool->index();
+ Array arrays = tool->commit_to_arrays();
+ add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"));
}
set_lightmap_size_hint(Size2(size_x, size_y));
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 514e7eb260..c24186a109 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -402,8 +402,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
}
}
- for (uint32_t i = 0; i < deferred_node_paths.size(); i++) {
- const DeferredNodePathProperties &dnp = deferred_node_paths[i];
+ for (const DeferredNodePathProperties &dnp : deferred_node_paths) {
Node *other = dnp.base->get_node_or_null(dnp.path);
dnp.base->set(dnp.property, other);
}
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index e802e1c2d9..17e92ddfca 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -732,13 +732,13 @@ void SurfaceTool::index() {
LocalVector<Vertex> old_vertex_array = vertex_array;
vertex_array.clear();
- for (uint32_t i = 0; i < old_vertex_array.size(); i++) {
- int *idxptr = indices.getptr(old_vertex_array[i]);
+ for (const Vertex &vertex : old_vertex_array) {
+ int *idxptr = indices.getptr(vertex);
int idx;
if (!idxptr) {
idx = indices.size();
- vertex_array.push_back(old_vertex_array[i]);
- indices[old_vertex_array[i]] = idx;
+ vertex_array.push_back(vertex);
+ indices[vertex] = idx;
} else {
idx = *idxptr;
}
@@ -756,9 +756,8 @@ void SurfaceTool::deindex() {
LocalVector<Vertex> old_vertex_array = vertex_array;
vertex_array.clear();
- for (uint32_t i = 0; i < index_array.size(); i++) {
- uint32_t index = index_array[i];
- ERR_FAIL_COND(index >= old_vertex_array.size());
+ for (const int &index : index_array) {
+ ERR_FAIL_COND(uint32_t(index) >= old_vertex_array.size());
vertex_array.push_back(old_vertex_array[index]);
}
format &= ~Mesh::ARRAY_FORMAT_INDEX;
@@ -1000,8 +999,7 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
}
int vfrom = vertex_array.size();
- for (uint32_t vi = 0; vi < nvertices.size(); vi++) {
- Vertex v = nvertices[vi];
+ for (Vertex &v : nvertices) {
v.vertex = p_xform.xform(v.vertex);
if (nformat & RS::ARRAY_FORMAT_NORMAL) {
v.normal = p_xform.basis.xform(v.normal);
@@ -1014,8 +1012,8 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
vertex_array.push_back(v);
}
- for (uint32_t i = 0; i < nindices.size(); i++) {
- int dst_index = nindices[i] + vfrom;
+ for (const int &index : nindices) {
+ int dst_index = index + vfrom;
index_array.push_back(dst_index);
}
if (index_array.size() % 3) {
@@ -1132,9 +1130,9 @@ void SurfaceTool::generate_tangents() {
TangentGenerationContextUserData triangle_data;
triangle_data.vertices = &vertex_array;
- for (uint32_t i = 0; i < vertex_array.size(); i++) {
- vertex_array[i].binormal = Vector3();
- vertex_array[i].tangent = Vector3();
+ for (Vertex &vertex : vertex_array) {
+ vertex.binormal = Vector3();
+ vertex.tangent = Vector3();
}
triangle_data.indices = &index_array;
msc.m_pUserData = &triangle_data;
@@ -1176,12 +1174,12 @@ void SurfaceTool::generate_normals(bool p_flip) {
}
}
- for (uint32_t vi = 0; vi < vertex_array.size(); vi++) {
- Vector3 *lv = vertex_hash.getptr(vertex_array[vi]);
+ for (Vertex &vertex : vertex_array) {
+ Vector3 *lv = vertex_hash.getptr(vertex);
if (!lv) {
- vertex_array[vi].normal = Vector3();
+ vertex.normal = Vector3();
} else {
- vertex_array[vi].normal = lv->normalized();
+ vertex.normal = lv->normalized();
}
}
diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp
index 6d66c48b78..dfafc7d2bc 100644
--- a/scene/resources/text_paragraph.cpp
+++ b/scene/resources/text_paragraph.cpp
@@ -135,8 +135,8 @@ void TextParagraph::_bind_methods() {
void TextParagraph::_shape_lines() {
if (lines_dirty) {
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- TS->free_rid(lines_rid[i]);
+ for (const RID &line_rid : lines_rid) {
+ TS->free_rid(line_rid);
}
lines_rid.clear();
@@ -234,14 +234,14 @@ void TextParagraph::_shape_lines() {
} else {
// Autowrap disabled.
- for (int i = 0; i < (int)lines_rid.size(); i++) {
+ for (const RID &line_rid : lines_rid) {
if (alignment == HORIZONTAL_ALIGNMENT_FILL) {
- TS->shaped_text_fit_to_width(lines_rid[i], width, jst_flags);
+ TS->shaped_text_fit_to_width(line_rid, width, jst_flags);
overrun_flags.set_flag(TextServer::OVERRUN_JUSTIFICATION_AWARE);
- TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
- TS->shaped_text_fit_to_width(lines_rid[i], width, jst_flags | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS);
+ TS->shaped_text_overrun_trim_to_width(line_rid, width, overrun_flags);
+ TS->shaped_text_fit_to_width(line_rid, width, jst_flags | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS);
} else {
- TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
+ TS->shaped_text_overrun_trim_to_width(line_rid, width, overrun_flags);
}
}
}
@@ -268,8 +268,8 @@ RID TextParagraph::get_dropcap_rid() const {
void TextParagraph::clear() {
_THREAD_SAFE_METHOD_
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- TS->free_rid(lines_rid[i]);
+ for (const RID &line_rid : lines_rid) {
+ TS->free_rid(line_rid);
}
lines_rid.clear();
TS->shaped_text_clear(rid);
@@ -915,17 +915,17 @@ int TextParagraph::hit_test(const Point2 &p_coords) const {
return 0;
}
}
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
- if ((p_coords.y >= ofs.y) && (p_coords.y <= ofs.y + TS->shaped_text_get_size(lines_rid[i]).y)) {
- return TS->shaped_text_hit_test_position(lines_rid[i], p_coords.x);
+ for (const RID &line_rid : lines_rid) {
+ if (TS->shaped_text_get_orientation(line_rid) == TextServer::ORIENTATION_HORIZONTAL) {
+ if ((p_coords.y >= ofs.y) && (p_coords.y <= ofs.y + TS->shaped_text_get_size(line_rid).y)) {
+ return TS->shaped_text_hit_test_position(line_rid, p_coords.x);
}
- ofs.y += TS->shaped_text_get_size(lines_rid[i]).y;
+ ofs.y += TS->shaped_text_get_size(line_rid).y;
} else {
- if ((p_coords.x >= ofs.x) && (p_coords.x <= ofs.x + TS->shaped_text_get_size(lines_rid[i]).x)) {
- return TS->shaped_text_hit_test_position(lines_rid[i], p_coords.y);
+ if ((p_coords.x >= ofs.x) && (p_coords.x <= ofs.x + TS->shaped_text_get_size(line_rid).x)) {
+ return TS->shaped_text_hit_test_position(line_rid, p_coords.y);
}
- ofs.y += TS->shaped_text_get_size(lines_rid[i]).x;
+ ofs.y += TS->shaped_text_get_size(line_rid).x;
}
}
return TS->shaped_text_get_range(rid).y;
@@ -1027,8 +1027,8 @@ TextParagraph::TextParagraph() {
}
TextParagraph::~TextParagraph() {
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- TS->free_rid(lines_rid[i]);
+ for (const RID &line_rid : lines_rid) {
+ TS->free_rid(line_rid);
}
lines_rid.clear();
TS->free_rid(rid);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 94e78fc3aa..b5a68ef14b 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -404,8 +404,8 @@ void TileSet::_update_terrains_cache() {
if (terrains_cache_dirty) {
// Organizes tiles into structures.
per_terrain_pattern_tiles.resize(terrain_sets.size());
- for (int i = 0; i < (int)per_terrain_pattern_tiles.size(); i++) {
- per_terrain_pattern_tiles[i].clear();
+ for (RBMap<TileSet::TerrainsPattern, RBSet<TileMapCell>> &tiles : per_terrain_pattern_tiles) {
+ tiles.clear();
}
for (const KeyValue<int, Ref<TileSetSource>> &kv : sources) {
@@ -1342,8 +1342,8 @@ void TileSet::clear_tile_proxies() {
int TileSet::add_pattern(Ref<TileMapPattern> p_pattern, int p_index) {
ERR_FAIL_COND_V(!p_pattern.is_valid(), -1);
ERR_FAIL_COND_V_MSG(p_pattern->is_empty(), -1, "Cannot add an empty pattern to the TileSet.");
- for (unsigned int i = 0; i < patterns.size(); i++) {
- ERR_FAIL_COND_V_MSG(patterns[i] == p_pattern, -1, "TileSet has already this pattern.");
+ for (const Ref<TileMapPattern> &pattern : patterns) {
+ ERR_FAIL_COND_V_MSG(pattern == p_pattern, -1, "TileSet has already this pattern.");
}
ERR_FAIL_COND_V(p_index > (int)patterns.size(), -1);
if (p_index < 0) {
@@ -4190,8 +4190,8 @@ real_t TileSetAtlasSource::get_tile_animation_total_duration(const Vector2i p_at
ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), 1, vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
real_t sum = 0.0;
- for (int frame = 0; frame < (int)tiles[p_atlas_coords].animation_frames_durations.size(); frame++) {
- sum += tiles[p_atlas_coords].animation_frames_durations[frame];
+ for (const real_t &duration : tiles[p_atlas_coords].animation_frames_durations) {
+ sum += duration;
}
return sum;
}
@@ -4573,8 +4573,8 @@ void TileSetAtlasSource::_clear_tiles_outside_texture() {
}
}
- for (unsigned int i = 0; i < to_remove.size(); i++) {
- remove_tile(to_remove[i]);
+ for (const Vector2i &v : to_remove) {
+ remove_tile(v);
}
}