Replace internal uses of insert_or_spawn_batch (#18035)

## Objective
`insert_or_spawn_batch` is due to be deprecated eventually (#15704), and
removing uses internally will make that easier.

## Solution

Replaced internal uses of `insert_or_spawn_batch` with
`try_insert_batch` (non-panicking variant because
`insert_or_spawn_batch` didn't panic).

All of the internal uses are in rendering code. Since retained rendering
was meant to get rid non-opaque entity IDs, I assume the code was just
using `insert_or_spawn_batch` because `insert_batch` didn't exist and
not because it actually wanted to spawn something. However, I am *not*
confident in my ability to judge rendering code.
This commit is contained in:
JaySpruce 2025-03-06 10:16:36 -06:00 committed by GitHub
parent 06cb5c5fd9
commit d6db78b5dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 15 additions and 15 deletions

View File

@ -347,7 +347,7 @@ pub fn extract_lights(
));
}
*previous_point_lights_len = point_lights_values.len();
commands.insert_or_spawn_batch(point_lights_values);
commands.try_insert_batch(point_lights_values);
let mut spot_lights_values = Vec::with_capacity(*previous_spot_lights_len);
for entity in global_point_lights.iter().copied() {
@ -410,7 +410,7 @@ pub fn extract_lights(
}
}
*previous_spot_lights_len = spot_lights_values.len();
commands.insert_or_spawn_batch(spot_lights_values);
commands.try_insert_batch(spot_lights_values);
for (
main_entity,

View File

@ -167,7 +167,7 @@ fn apply_wireframe_material(
let material = get_wireframe_material(maybe_color, &mut materials, &global_material);
material_to_spawn.push((e, MeshMaterial3d(material)));
}
commands.insert_or_spawn_batch(material_to_spawn);
commands.try_insert_batch(material_to_spawn);
}
type WireframeFilter = (With<Mesh3d>, Without<Wireframe>, Without<NoWireframe>);
@ -195,7 +195,7 @@ fn apply_global_wireframe_material(
// This makes it easy to detect which mesh is using the global material and which ones are user specified
material_to_spawn.push((e, MeshMaterial3d(material)));
}
commands.insert_or_spawn_batch(material_to_spawn);
commands.try_insert_batch(material_to_spawn);
} else {
for e in &meshes_with_global_material {
commands

View File

@ -154,7 +154,7 @@ fn prepare_uniform_components<C>(
)
})
.collect::<Vec<_>>();
commands.insert_or_spawn_batch(entities);
commands.try_insert_batch(entities);
}
/// This plugin extracts the components into the render world for synced entities.
@ -212,7 +212,7 @@ fn extract_components<C: ExtractComponent>(
}
}
*previous_len = values.len();
commands.insert_or_spawn_batch(values);
commands.try_insert_batch(values);
}
/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::sync_world::SyncToRenderWorld`].
@ -232,5 +232,5 @@ fn extract_visible_components<C: ExtractComponent>(
}
}
*previous_len = values.len();
commands.insert_or_spawn_batch(values);
commands.try_insert_batch(values);
}

View File

@ -53,7 +53,7 @@ fn prepare_gpu_component_array_buffers<C: Component + GpuArrayBufferable>(
.iter()
.map(|(entity, component)| (entity, gpu_array_buffer.push(component.clone())))
.collect::<Vec<_>>();
commands.insert_or_spawn_batch(entities);
commands.try_insert_batch(entities);
gpu_array_buffer.write_buffer(&render_device, &render_queue);
}

View File

@ -180,7 +180,7 @@ fn apply_wireframe_material(
};
wireframes_to_spawn.push((e, MeshMaterial2d(material)));
}
commands.insert_or_spawn_batch(wireframes_to_spawn);
commands.try_insert_batch(wireframes_to_spawn);
}
type Wireframe2dFilter = (With<Mesh2d>, Without<Wireframe2d>, Without<NoWireframe2d>);
@ -209,7 +209,7 @@ fn apply_global_wireframe_material(
// This makes it easy to detect which mesh is using the global material and which ones are user specified
material_to_spawn.push((e, MeshMaterial2d(global_material.handle.clone())));
}
commands.insert_or_spawn_batch(material_to_spawn);
commands.try_insert_batch(material_to_spawn);
} else {
for e in &meshes_with_global_material {
commands

View File

@ -526,7 +526,7 @@ pub fn prepare_shadows(
ui_meta.vertices.write_buffer(&render_device, &render_queue);
ui_meta.indices.write_buffer(&render_device, &render_queue);
*previous_len = batches.len();
commands.insert_or_spawn_batch(batches);
commands.try_insert_batch(batches);
}
extracted_shadows.box_shadows.clear();
}

View File

@ -1389,7 +1389,7 @@ pub fn prepare_uinodes(
ui_meta.vertices.write_buffer(&render_device, &render_queue);
ui_meta.indices.write_buffer(&render_device, &render_queue);
*previous_len = batches.len();
commands.insert_or_spawn_batch(batches);
commands.try_insert_batch(batches);
}
extracted_uinodes.clear();
}

View File

@ -578,7 +578,7 @@ pub fn prepare_uimaterial_nodes<M: UiMaterial>(
}
ui_meta.vertices.write_buffer(&render_device, &render_queue);
*previous_len = batches.len();
commands.insert_or_spawn_batch(batches);
commands.try_insert_batch(batches);
}
extracted_uinodes.uinodes.clear();
}

View File

@ -649,7 +649,7 @@ pub fn prepare_ui_slices(
ui_meta.vertices.write_buffer(&render_device, &render_queue);
ui_meta.indices.write_buffer(&render_device, &render_queue);
*previous_len = batches.len();
commands.insert_or_spawn_batch(batches);
commands.try_insert_batch(batches);
}
extracted_slices.slices.clear();
}

View File

@ -357,7 +357,7 @@ pub fn extract_colored_mesh2d(
);
}
*previous_len = values.len();
commands.insert_or_spawn_batch(values);
commands.try_insert_batch(values);
}
/// Queue the 2d meshes marked with [`ColoredMesh2d`] using our custom pipeline and draw function