diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/physics_3d/godot_shape_3d.cpp | 33 | ||||
-rw-r--r-- | servers/physics_3d/godot_soft_body_3d.cpp | 93 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/environment/gi.cpp | 14 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp | 19 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp | 11 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/shader_rd.cpp | 3 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp | 18 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/particles_storage.cpp | 6 | ||||
-rw-r--r-- | servers/rendering/renderer_scene_cull.cpp | 16 | ||||
-rw-r--r-- | servers/rendering/shader_preprocessor.cpp | 4 | ||||
-rw-r--r-- | servers/rendering_server.cpp | 4 |
11 files changed, 81 insertions, 140 deletions
diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp index 8aacfa929f..300dca4e08 100644 --- a/servers/physics_3d/godot_shape_3d.cpp +++ b/servers/physics_3d/godot_shape_3d.cpp @@ -852,17 +852,12 @@ Vector3 GodotConvexPolygonShape3D::get_support(const Vector3 &p_normal) const { // Get the array of vertices const Vector3 *const vertices_array = mesh.vertices.ptr(); - // Get the array of extreme vertices - const int *const extreme_array = extreme_vertices.ptr(); - const uint32_t extreme_size = extreme_vertices.size(); - - // Start with an initial assumption of the first extreme vertex - int best_vertex = extreme_array[0]; + // Start with an initial assumption of the first extreme vertex. + int best_vertex = extreme_vertices[0]; real_t max_support = p_normal.dot(vertices_array[best_vertex]); - // Check the remaining extreme vertices for a better vertex - for (uint32_t i = 0; i < extreme_size; ++i) { - int vert = extreme_array[i]; + // Check the remaining extreme vertices for a better vertex. + for (const int &vert : extreme_vertices) { real_t s = p_normal.dot(vertices_array[vert]); if (s > max_support) { best_vertex = vert; @@ -870,27 +865,18 @@ Vector3 GodotConvexPolygonShape3D::get_support(const Vector3 &p_normal) const { } } - // If we checked all vertices in the mesh then we're done - if (extreme_size == mesh.vertices.size()) { + // If we checked all vertices in the mesh then we're done. + if (extreme_vertices.size() == mesh.vertices.size()) { return vertices_array[best_vertex]; } - // Get the array of neighbor arrays for each vertex - const LocalVector<int> *const vertex_neighbors_array = vertex_neighbors.ptr(); - // Move along the surface until we reach the true support vertex. int last_vertex = -1; while (true) { int next_vertex = -1; - // Get the array of neighbors around the best vertex - const LocalVector<int> &neighbors = vertex_neighbors_array[best_vertex]; - const int *const neighbors_array = neighbors.ptr(); - const uint32_t neighbors_size = neighbors.size(); - - // Iterate over all the neighbors checking for a better vertex - for (uint32_t i = 0; i < neighbors_size; ++i) { - int vert = neighbors_array[i]; + // Iterate over all the neighbors checking for a better vertex. + for (const int &vert : vertex_neighbors[best_vertex]) { if (vert != last_vertex) { real_t s = p_normal.dot(vertices_array[vert]); if (s > max_support) { @@ -1149,8 +1135,7 @@ void GodotConvexPolygonShape3D::_setup(const Vector<Vector3> &p_vertices) { if (extreme_vertices.size() < mesh.vertices.size()) { vertex_neighbors.resize(mesh.vertices.size()); - for (uint32_t i = 0; i < mesh.edges.size(); i++) { - Geometry3D::MeshData::Edge &edge = mesh.edges[i]; + for (Geometry3D::MeshData::Edge &edge : mesh.edges) { vertex_neighbors[edge.vertex_a].push_back(edge.vertex_b); vertex_neighbors[edge.vertex_b].push_back(edge.vertex_a); } diff --git a/servers/physics_3d/godot_soft_body_3d.cpp b/servers/physics_3d/godot_soft_body_3d.cpp index 871017a5e7..1820a29553 100644 --- a/servers/physics_3d/godot_soft_body_3d.cpp +++ b/servers/physics_3d/godot_soft_body_3d.cpp @@ -167,14 +167,11 @@ void GodotSoftBody3D::update_rendering_server(PhysicsServer3DRenderingServerHand } void GodotSoftBody3D::update_normals_and_centroids() { - uint32_t i, ni; - - for (i = 0, ni = nodes.size(); i < ni; ++i) { - nodes[i].n = Vector3(); + for (Node &node : nodes) { + node.n = Vector3(); } - for (i = 0, ni = faces.size(); i < ni; ++i) { - Face &face = faces[i]; + for (Face &face : faces) { const Vector3 n = vec3_cross(face.n[0]->x - face.n[2]->x, face.n[0]->x - face.n[1]->x); face.n[0]->n += n; face.n[1]->n += n; @@ -184,8 +181,7 @@ void GodotSoftBody3D::update_normals_and_centroids() { face.centroid = 0.33333333333 * (face.n[0]->x + face.n[1]->x + face.n[2]->x); } - for (i = 0, ni = nodes.size(); i < ni; ++i) { - Node &node = nodes[i]; + for (Node &node : nodes) { real_t len = node.n.length(); if (len > CMP_EPSILON) { node.n /= len; @@ -235,9 +231,7 @@ void GodotSoftBody3D::update_area() { int i, ni; // Face area. - for (i = 0, ni = faces.size(); i < ni; ++i) { - Face &face = faces[i]; - + for (Face &face : faces) { const Vector3 &x0 = face.n[0]->x; const Vector3 &x1 = face.n[1]->x; const Vector3 &x2 = face.n[2]->x; @@ -255,12 +249,11 @@ void GodotSoftBody3D::update_area() { memset(counts.ptr(), 0, counts.size() * sizeof(int)); } - for (i = 0, ni = nodes.size(); i < ni; ++i) { - nodes[i].area = 0.0; + for (Node &node : nodes) { + node.area = 0.0; } - for (i = 0, ni = faces.size(); i < ni; ++i) { - const Face &face = faces[i]; + for (const Face &face : faces) { for (int j = 0; j < 3; ++j) { const int index = (int)(face.n[j] - &nodes[0]); counts[index]++; @@ -278,8 +271,7 @@ void GodotSoftBody3D::update_area() { } void GodotSoftBody3D::reset_link_rest_lengths() { - for (uint32_t i = 0, ni = links.size(); i < ni; ++i) { - Link &link = links[i]; + for (Link &link : links) { link.rl = (link.n[0]->x - link.n[1]->x).length(); link.c1 = link.rl * link.rl; } @@ -287,8 +279,7 @@ void GodotSoftBody3D::reset_link_rest_lengths() { void GodotSoftBody3D::update_link_constants() { real_t inv_linear_stiffness = 1.0 / linear_stiffness; - for (uint32_t i = 0, ni = links.size(); i < ni; ++i) { - Link &link = links[i]; + for (Link &link : links) { link.c0 = (link.n[0]->im + link.n[1]->im) * inv_linear_stiffness; } } @@ -619,9 +610,9 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) { } } } - for (i = 0; i < links.size(); ++i) { - const int ia = (int)(links[i].n[0] - &nodes[0]); - const int ib = (int)(links[i].n[1] - &nodes[0]); + for (Link &link : links) { + const int ia = (int)(link.n[0] - &nodes[0]); + const int ib = (int)(link.n[1] - &nodes[0]); int idx = ib * n + ia; int idx_inv = ia * n + ib; adj[idx] = 1; @@ -635,9 +626,9 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) { // Build node links. node_links.resize(nodes.size()); - for (i = 0; i < links.size(); ++i) { - const int ia = (int)(links[i].n[0] - &nodes[0]); - const int ib = (int)(links[i].n[1] - &nodes[0]); + for (Link &link : links) { + const int ia = (int)(link.n[0] - &nodes[0]); + const int ib = (int)(link.n[1] - &nodes[0]); if (node_links[ia].find(ib) == -1) { node_links[ia].push_back(ib); } @@ -649,8 +640,7 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) { for (uint32_t ii = 0; ii < node_links.size(); ii++) { for (uint32_t jj = 0; jj < node_links[ii].size(); jj++) { int k = node_links[ii][jj]; - for (uint32_t kk = 0; kk < node_links[k].size(); kk++) { - int l = node_links[k][kk]; + for (const int &l : node_links[k]) { if ((int)ii != l) { int idx_ik = k * n + ii; int idx_kj = l * n + k; @@ -916,8 +906,7 @@ void GodotSoftBody3D::set_drag_coefficient(real_t p_val) { } void GodotSoftBody3D::add_velocity(const Vector3 &p_velocity) { - for (uint32_t i = 0, ni = nodes.size(); i < ni; ++i) { - Node &node = nodes[i]; + for (Node &node : nodes) { if (node.im > 0) { node.v += p_velocity; } @@ -929,26 +918,22 @@ void GodotSoftBody3D::apply_forces(const LocalVector<GodotArea3D *> &p_wind_area return; } - uint32_t i, ni; int32_t j; real_t volume = 0.0; const Vector3 &org = nodes[0].x; // Iterate over faces (try not to iterate elsewhere if possible). - for (i = 0, ni = faces.size(); i < ni; ++i) { - const Face &face = faces[i]; - + for (const Face &face : faces) { Vector3 wind_force(0, 0, 0); // Compute volume. volume += vec3_dot(face.n[0]->x - org, vec3_cross(face.n[1]->x - org, face.n[2]->x - org)); // Compute nodal forces from area winds. - int wind_area_count = p_wind_areas.size(); - if (wind_area_count > 0) { - for (j = 0; j < wind_area_count; j++) { - wind_force += _compute_area_windforce(p_wind_areas[j], &face); + if (!p_wind_areas.is_empty()) { + for (const GodotArea3D *area : p_wind_areas) { + wind_force += _compute_area_windforce(area, &face); } for (j = 0; j < 3; j++) { @@ -962,8 +947,7 @@ void GodotSoftBody3D::apply_forces(const LocalVector<GodotArea3D *> &p_wind_area // Apply nodal pressure forces. if (pressure_coefficient > CMP_EPSILON) { real_t ivolumetp = 1.0 / Math::abs(volume) * pressure_coefficient; - for (i = 0, ni = nodes.size(); i < ni; ++i) { - Node &node = nodes[i]; + for (Node &node : nodes) { if (node.im > 0) { node.f += node.n * (node.area * ivolumetp); } @@ -1048,9 +1032,7 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) { real_t clamp_delta_v = max_displacement * inv_delta; // Integrate. - uint32_t i, ni; - for (i = 0, ni = nodes.size(); i < ni; ++i) { - Node &node = nodes[i]; + for (Node &node : nodes) { node.q = node.x; Vector3 delta_v = node.f * node.im * p_delta; for (int c = 0; c < 3; c++) { @@ -1065,9 +1047,7 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) { update_bounds(); // Node tree update. - for (i = 0, ni = nodes.size(); i < ni; ++i) { - const Node &node = nodes[i]; - + for (const Node &node : nodes) { AABB node_aabb(node.x, Vector3()); node_aabb.expand_to(node.x + node.v * p_delta); node_aabb.grow_by(collision_margin); @@ -1088,17 +1068,13 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) { void GodotSoftBody3D::solve_constraints(real_t p_delta) { const real_t inv_delta = 1.0 / p_delta; - uint32_t i, ni; - - for (i = 0, ni = links.size(); i < ni; ++i) { - Link &link = links[i]; + for (Link &link : links) { link.c3 = link.n[1]->q - link.n[0]->q; link.c2 = 1 / (link.c3.length_squared() * link.c0); } // Solve velocities. - for (i = 0, ni = nodes.size(); i < ni; ++i) { - Node &node = nodes[i]; + for (Node &node : nodes) { node.x = node.q + node.v * p_delta; } @@ -1108,9 +1084,7 @@ void GodotSoftBody3D::solve_constraints(real_t p_delta) { solve_links(1.0, ti); } const real_t vc = (1.0 - damping_coefficient) * inv_delta; - for (i = 0, ni = nodes.size(); i < ni; ++i) { - Node &node = nodes[i]; - + for (Node &node : nodes) { node.x += node.bv * p_delta; node.bv = Vector3(); @@ -1123,8 +1097,7 @@ void GodotSoftBody3D::solve_constraints(real_t p_delta) { } void GodotSoftBody3D::solve_links(real_t kst, real_t ti) { - for (uint32_t i = 0, ni = links.size(); i < ni; ++i) { - Link &link = links[i]; + for (Link &link : links) { if (link.c0 > 0) { Node &node_a = *link.n[0]; Node &node_b = *link.n[1]; @@ -1183,9 +1156,7 @@ void GodotSoftBody3D::query_ray(const Vector3 &p_from, const Vector3 &p_to, Godo void GodotSoftBody3D::initialize_face_tree() { face_tree.clear(); - for (uint32_t i = 0; i < faces.size(); ++i) { - Face &face = faces[i]; - + for (Face &face : faces) { AABB face_aabb; face_aabb.position = face.n[0]->x; @@ -1199,9 +1170,7 @@ void GodotSoftBody3D::initialize_face_tree() { } void GodotSoftBody3D::update_face_tree(real_t p_delta) { - for (uint32_t i = 0; i < faces.size(); ++i) { - const Face &face = faces[i]; - + for (const Face &face : faces) { AABB face_aabb; const Node *node0 = face.n[0]; diff --git a/servers/rendering/renderer_rd/environment/gi.cpp b/servers/rendering/renderer_rd/environment/gi.cpp index a52716cd78..08133bf8d6 100644 --- a/servers/rendering/renderer_rd/environment/gi.cpp +++ b/servers/rendering/renderer_rd/environment/gi.cpp @@ -540,9 +540,7 @@ void GI::SDFGI::create(RID p_env, const Vector3 &p_world_position, uint32_t p_re occlusion_texture = RD::get_singleton()->texture_create_shared(tv, occlusion_data); } - for (uint32_t i = 0; i < cascades.size(); i++) { - SDFGI::Cascade &cascade = cascades[i]; - + for (SDFGI::Cascade &cascade : cascades) { /* 3D Textures */ cascade.sdf_tex = RD::get_singleton()->texture_create(tf_sdf, RD::TextureView()); @@ -743,9 +741,7 @@ void GI::SDFGI::create(RID p_env, const Vector3 &p_world_position, uint32_t p_re } //direct light - for (uint32_t i = 0; i < cascades.size(); i++) { - SDFGI::Cascade &cascade = cascades[i]; - + for (SDFGI::Cascade &cascade : cascades) { Vector<RD::Uniform> uniforms; { RD::Uniform u; @@ -1134,8 +1130,7 @@ void GI::SDFGI::free_data() { } GI::SDFGI::~SDFGI() { - for (uint32_t i = 0; i < cascades.size(); i++) { - const SDFGI::Cascade &c = cascades[i]; + for (const SDFGI::Cascade &c : cascades) { RD::get_singleton()->free(c.light_data); RD::get_singleton()->free(c.light_aniso_0_tex); RD::get_singleton()->free(c.light_aniso_1_tex); @@ -1198,8 +1193,7 @@ void GI::SDFGI::update(RID p_env, const Vector3 &p_world_position) { int32_t drag_margin = (cascade_size / SDFGI::PROBE_DIVISOR) / 2; - for (uint32_t i = 0; i < cascades.size(); i++) { - SDFGI::Cascade &cascade = cascades[i]; + for (SDFGI::Cascade &cascade : cascades) { cascade.dirty_regions = Vector3i(); Vector3 probe_half_size = Vector3(1, 1, 1) * cascade.cell_size * float(cascade_size / SDFGI::PROBE_DIVISOR) * 0.5; diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 3fd8d55a71..ad63d3fd4b 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -1365,8 +1365,8 @@ void RenderForwardClustered::_pre_opaque_render(RenderDataRD *p_render_data, boo } //cube shadows are rendered in their own way - for (uint32_t i = 0; i < p_render_data->cube_shadows.size(); i++) { - _render_shadow_pass(p_render_data->render_shadows[p_render_data->cube_shadows[i]].light, p_render_data->shadow_atlas, p_render_data->render_shadows[p_render_data->cube_shadows[i]].pass, p_render_data->render_shadows[p_render_data->cube_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info); + for (const int &index : p_render_data->cube_shadows) { + _render_shadow_pass(p_render_data->render_shadows[index].light, p_render_data->shadow_atlas, p_render_data->render_shadows[index].pass, p_render_data->render_shadows[index].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info); } if (p_render_data->directional_shadows.size()) { @@ -2415,8 +2415,7 @@ void RenderForwardClustered::_render_shadow_process() { void RenderForwardClustered::_render_shadow_end(uint32_t p_barrier) { RD::get_singleton()->draw_command_begin_label("Shadow Render"); - for (uint32_t i = 0; i < scene_state.shadow_passes.size(); i++) { - SceneState::ShadowPass &shadow_pass = scene_state.shadow_passes[i]; + for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) { RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, 0, true, false, shadow_pass.rp_uniform_set, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from, RD::BARRIER_MASK_NO_BARRIER); _render_list_with_threads(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, shadow_pass.final_depth_action, Vector<Color>(), 1.0, 0, shadow_pass.rect); } @@ -3376,9 +3375,7 @@ int RenderForwardClustered::sdfgi_get_pending_region_count(const Ref<RenderScene Ref<RendererRD::GI::SDFGI> sdfgi = rb->get_custom_data(RB_SCOPE_SDFGI); int dirty_count = 0; - for (uint32_t i = 0; i < sdfgi->cascades.size(); i++) { - const RendererRD::GI::SDFGI::Cascade &c = sdfgi->cascades[i]; - + for (const RendererRD::GI::SDFGI::Cascade &c : sdfgi->cascades) { if (c.dirty_regions == RendererRD::GI::SDFGI::Cascade::DIRTY_ALL) { dirty_count++; } else { @@ -4007,11 +4004,11 @@ RenderForwardClustered::~RenderForwardClustered() { RSG::light_storage->directional_shadow_atlas_set_size(0); { - for (uint32_t i = 0; i < scene_state.uniform_buffers.size(); i++) { - RD::get_singleton()->free(scene_state.uniform_buffers[i]); + for (const RID &rid : scene_state.uniform_buffers) { + RD::get_singleton()->free(rid); } - for (uint32_t i = 0; i < scene_state.implementation_uniform_buffers.size(); i++) { - RD::get_singleton()->free(scene_state.implementation_uniform_buffers[i]); + for (const RID &rid : scene_state.implementation_uniform_buffers) { + RD::get_singleton()->free(rid); } RD::get_singleton()->free(scene_state.lightmap_buffer); RD::get_singleton()->free(scene_state.lightmap_capture_buffer); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 5d4e3c1ac1..25204f1abf 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -579,8 +579,8 @@ void RenderForwardMobile::_pre_opaque_render(RenderDataRD *p_render_data) { } //cube shadows are rendered in their own way - for (uint32_t i = 0; i < p_render_data->cube_shadows.size(); i++) { - _render_shadow_pass(p_render_data->render_shadows[p_render_data->cube_shadows[i]].light, p_render_data->shadow_atlas, p_render_data->render_shadows[p_render_data->cube_shadows[i]].pass, p_render_data->render_shadows[p_render_data->cube_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info); + for (const int &index : p_render_data->cube_shadows) { + _render_shadow_pass(p_render_data->render_shadows[index].light, p_render_data->shadow_atlas, p_render_data->render_shadows[index].pass, p_render_data->render_shadows[index].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info); } if (p_render_data->directional_shadows.size()) { @@ -1340,8 +1340,7 @@ void RenderForwardMobile::_render_shadow_process() { void RenderForwardMobile::_render_shadow_end(uint32_t p_barrier) { RD::get_singleton()->draw_command_begin_label("Shadow Render"); - for (uint32_t i = 0; i < scene_state.shadow_passes.size(); i++) { - SceneState::ShadowPass &shadow_pass = scene_state.shadow_passes[i]; + for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) { RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, shadow_pass.rp_uniform_set, 0, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from, RD::BARRIER_MASK_NO_BARRIER); _render_list_with_threads(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, shadow_pass.final_depth_action, Vector<Color>(), 1.0, 0, shadow_pass.rect); } @@ -2810,8 +2809,8 @@ RenderForwardMobile::~RenderForwardMobile() { } { - for (uint32_t i = 0; i < scene_state.uniform_buffers.size(); i++) { - RD::get_singleton()->free(scene_state.uniform_buffers[i]); + for (const RID &rid : scene_state.uniform_buffers) { + RD::get_singleton()->free(rid); } RD::get_singleton()->free(scene_state.lightmap_buffer); RD::get_singleton()->free(scene_state.lightmap_capture_buffer); diff --git a/servers/rendering/renderer_rd/shader_rd.cpp b/servers/rendering/renderer_rd/shader_rd.cpp index 2d5263a3e2..533a912a34 100644 --- a/servers/rendering/renderer_rd/shader_rd.cpp +++ b/servers/rendering/renderer_rd/shader_rd.cpp @@ -165,8 +165,7 @@ void ShaderRD::_clear_version(Version *p_version) { } void ShaderRD::_build_variant_code(StringBuilder &builder, uint32_t p_variant, const Version *p_version, const StageTemplate &p_template) { - for (uint32_t i = 0; i < p_template.chunks.size(); i++) { - const StageTemplate::Chunk &chunk = p_template.chunks[i]; + for (const StageTemplate::Chunk &chunk : p_template.chunks) { switch (chunk.type) { case StageTemplate::Chunk::TYPE_VERSION_DEFINES: { builder.append("\n"); //make sure defines begin at newline diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp index 62da62403f..46a0d85ba8 100644 --- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp @@ -842,15 +842,15 @@ void MeshStorage::mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int } void MeshStorage::_mesh_instance_clear(MeshInstance *mi) { - for (uint32_t i = 0; i < mi->surfaces.size(); i++) { - if (mi->surfaces[i].versions) { - for (uint32_t j = 0; j < mi->surfaces[i].version_count; j++) { - RD::get_singleton()->free(mi->surfaces[i].versions[j].vertex_array); + for (const RendererRD::MeshStorage::MeshInstance::Surface surface : mi->surfaces) { + if (surface.versions) { + for (uint32_t j = 0; j < surface.version_count; j++) { + RD::get_singleton()->free(surface.versions[j].vertex_array); } - memfree(mi->surfaces[i].versions); + memfree(surface.versions); } - if (mi->surfaces[i].vertex_buffer.is_valid()) { - RD::get_singleton()->free(mi->surfaces[i].vertex_buffer); + if (surface.vertex_buffer.is_valid()) { + RD::get_singleton()->free(surface.vertex_buffer); } } mi->surfaces.clear(); @@ -866,8 +866,8 @@ void MeshStorage::_mesh_instance_clear(MeshInstance *mi) { void MeshStorage::_mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface) { if (mesh->blend_shape_count > 0 && mi->blend_weights_buffer.is_null()) { mi->blend_weights.resize(mesh->blend_shape_count); - for (uint32_t i = 0; i < mi->blend_weights.size(); i++) { - mi->blend_weights[i] = 0; + for (float &weight : mi->blend_weights) { + weight = 0; } mi->blend_weights_buffer = RD::get_singleton()->storage_buffer_create(sizeof(float) * mi->blend_weights.size(), mi->blend_weights.to_byte_array()); mi->weights_dirty = true; diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index e4149f6bbd..f4c3e769a8 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -851,9 +851,9 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta collision_heightmap_texture = p_particles->sdf_collision_texture; //replace in all other history frames where used because parameters are no longer valid if screen moves - for (uint32_t i = 1; i < p_particles->frame_history.size(); i++) { - if (p_particles->frame_history[i].collider_count > 0 && p_particles->frame_history[i].colliders[0].type == ParticlesFrameParams::COLLISION_TYPE_2D_SDF) { - p_particles->frame_history[i].colliders[0] = frame_params.colliders[0]; + for (ParticlesFrameParams ¶ms : p_particles->frame_history) { + if (params.collider_count > 0 && params.colliders[0].type == ParticlesFrameParams::COLLISION_TYPE_2D_SDF) { + params.colliders[0] = frame_params.colliders[0]; } } } diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index de417082f5..9011cdd98a 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -3096,15 +3096,15 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c #endif if (cull_to > thread_cull_threshold) { //multiple threads - for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) { - scene_cull_result_threads[i].clear(); + for (InstanceCullResult &thread : scene_cull_result_threads) { + thread.clear(); } WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &RendererSceneCull::_scene_cull_threaded, &cull_data, scene_cull_result_threads.size(), -1, true, SNAME("RenderCullInstances")); WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group_task); - for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) { - scene_cull_result.append_from(scene_cull_result_threads[i]); + for (InstanceCullResult &thread : scene_cull_result_threads) { + scene_cull_result.append_from(thread); } } else { @@ -4134,8 +4134,8 @@ RendererSceneCull::RendererSceneCull() { scene_cull_result.init(&rid_cull_page_pool, &geometry_instance_cull_page_pool, &instance_cull_page_pool); scene_cull_result_threads.resize(WorkerThreadPool::get_singleton()->get_thread_count()); - for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) { - scene_cull_result_threads[i].init(&rid_cull_page_pool, &geometry_instance_cull_page_pool, &instance_cull_page_pool); + for (InstanceCullResult &thread : scene_cull_result_threads) { + thread.init(&rid_cull_page_pool, &geometry_instance_cull_page_pool, &instance_cull_page_pool); } indexer_update_iterations = GLOBAL_GET("rendering/limits/spatial_indexer/update_iterations_per_frame"); @@ -4163,8 +4163,8 @@ RendererSceneCull::~RendererSceneCull() { } scene_cull_result.reset(); - for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) { - scene_cull_result_threads[i].reset(); + for (InstanceCullResult &thread : scene_cull_result_threads) { + thread.reset(); } scene_cull_result_threads.clear(); diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index ccbf5defa2..97efd2df94 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -330,8 +330,8 @@ String ShaderPreprocessor::vector_to_string(const LocalVector<char32_t> &p_v, in String ShaderPreprocessor::tokens_to_string(const LocalVector<Token> &p_tokens) { LocalVector<char32_t> result; - for (uint32_t i = 0; i < p_tokens.size(); i++) { - result.push_back(p_tokens[i].text); + for (const Token &token : p_tokens) { + result.push_back(token.text); } return vector_to_string(result); } diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 675db63b9a..4ef562adcb 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2802,9 +2802,7 @@ void RenderingServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry Vector<Vector3> vertices; Vector<Vector3> normals; - for (uint32_t i = 0; i < p_mesh_data.faces.size(); i++) { - const Geometry3D::MeshData::Face &f = p_mesh_data.faces[i]; - + for (const Geometry3D::MeshData::Face &f : p_mesh_data.faces) { for (uint32_t j = 2; j < f.indices.size(); j++) { vertices.push_back(p_mesh_data.vertices[f.indices[0]]); normals.push_back(f.plane.normal); |