From 1ba742937139c049ce5aafc8bc1bb3b9c8f0c201 Mon Sep 17 00:00:00 2001 From: Mark Schmale Date: Mon, 16 May 2022 13:53:20 +0000 Subject: [PATCH] Doc/module style doc blocks for examples (#4438) # Objective Provide a starting point for #3951, or a partial solution. Providing a few comment blocks to discuss, and hopefully find better one in the process. ## Solution Since I am pretty new to pretty much anything in this context, I figured I'd just start with a draft for some file level doc blocks. For some of them I found more relevant details (or at least things I considered interessting), for some others there is less. ## Changelog - Moved some existing comments from main() functions in the 2d examples to the file header level - Wrote some more comment blocks for most other 2d examples TODO: - [x] 2d/sprite_sheet, wasnt able to come up with something good yet - [x] all other example groups... Also: Please let me know if the commit style is okay, or to verbose. I could certainly squash these things, or add more details if needed. I also hope its okay to raise this PR this early, with just a few files changed. Took me long enough and I dont wanted to let it go to waste because I lost motivation to do the whole thing. Additionally I am somewhat uncertain over the style and contents of the commets. So let me know what you thing please. --- examples/2d/mesh2d.rs | 2 + examples/2d/mesh2d_manual.rs | 8 +-- examples/2d/move_sprite.rs | 4 ++ examples/2d/rotation.rs | 2 + examples/2d/shapes.rs | 2 + examples/2d/sprite.rs | 2 + examples/2d/sprite_flipping.rs | 2 + examples/2d/sprite_sheet.rs | 3 ++ examples/2d/text2d.rs | 7 +++ examples/2d/texture_atlas.rs | 5 +- examples/3d/3d_scene.rs | 2 + examples/3d/lighting.rs | 3 ++ examples/3d/load_gltf.rs | 2 + examples/3d/msaa.rs | 15 +++--- examples/3d/orthographic.rs | 2 + examples/3d/parenting.rs | 5 +- examples/3d/pbr.rs | 3 +- examples/3d/render_to_texture.rs | 2 + examples/3d/shadow_biases.rs | 2 + examples/3d/shadow_caster_receiver.rs | 2 + examples/3d/spherical_area_lights.rs | 2 + examples/3d/texture.rs | 3 +- examples/3d/two_passes.rs | 4 ++ examples/3d/update_gltf_scene.rs | 3 ++ examples/3d/vertex_colors.rs | 2 + examples/3d/wireframe.rs | 2 + examples/README.md | 14 ++--- examples/animation/animated_fox.rs | 2 + examples/animation/animated_transform.rs | 2 + examples/animation/custom_skinned_mesh.rs | 5 +- examples/animation/gltf_skinned_mesh.rs | 7 +-- examples/app/custom_loop.rs | 5 +- examples/app/drag_and_drop.rs | 2 + examples/app/empty.rs | 2 + examples/app/empty_defaults.rs | 2 + examples/app/headless.rs | 16 +++--- examples/app/headless_defaults.rs | 3 ++ examples/app/logs.rs | 3 +- examples/app/plugin.rs | 9 ++-- examples/app/plugin_group.rs | 4 +- examples/app/return_after_run.rs | 2 + examples/app/thread_pool_resources.rs | 5 +- examples/app/without_winit.rs | 2 + examples/asset/asset_loading.rs | 3 +- examples/asset/custom_asset.rs | 2 + examples/asset/custom_asset_io.rs | 4 ++ examples/asset/hot_asset_reloading.rs | 7 +-- examples/async_tasks/async_compute.rs | 5 +- .../external_source_external_thread.rs | 2 + examples/audio/audio.rs | 3 +- examples/audio/audio_control.rs | 3 +- examples/diagnostics/custom_diagnostic.rs | 13 ++--- examples/diagnostics/log_diagnostics.rs | 2 + examples/ecs/component_change_detection.rs | 3 +- examples/ecs/custom_query_param.rs | 27 +++++----- examples/ecs/ecs_guide.rs | 52 +++++++++---------- examples/ecs/event.rs | 5 +- examples/ecs/fixed_timestep.rs | 2 + examples/ecs/generic_system.rs | 22 ++++---- examples/ecs/hierarchy.rs | 2 + examples/ecs/iter_combinations.rs | 2 + examples/ecs/parallel_query.rs | 2 + examples/ecs/removal_detection.rs | 2 +- examples/ecs/startup_system.rs | 2 + examples/ecs/state.rs | 5 +- examples/ecs/system_chaining.rs | 3 ++ examples/ecs/system_closure.rs | 2 + examples/ecs/system_param.rs | 3 +- examples/ecs/system_sets.rs | 45 ++++++++-------- examples/ecs/timers.rs | 2 + examples/games/alien_cake_addict.rs | 6 ++- examples/games/breakout.rs | 2 +- examples/games/contributors.rs | 2 + examples/games/game_menu.rs | 8 +-- examples/input/char_input_events.rs | 2 + examples/input/gamepad_input.rs | 2 + examples/input/gamepad_input_events.rs | 2 + examples/input/keyboard_input.rs | 2 + examples/input/keyboard_input_events.rs | 2 + examples/input/keyboard_modifiers.rs | 2 + examples/input/mouse_grab.rs | 2 + examples/input/mouse_input.rs | 2 + examples/input/mouse_input_events.rs | 2 + examples/input/touch_input.rs | 2 + examples/input/touch_input_events.rs | 2 + examples/reflection/generic_reflection.rs | 4 +- examples/reflection/reflection.rs | 9 ++-- examples/reflection/reflection_types.rs | 4 +- examples/reflection/trait_reflection.rs | 2 + examples/scene/scene.rs | 3 +- examples/shader/animate_shader.rs | 4 ++ .../shader/compute_shader_game_of_life.rs | 6 +++ examples/shader/custom_vertex_attribute.rs | 2 + examples/shader/shader_defs.rs | 3 ++ examples/shader/shader_instancing.rs | 4 ++ examples/shader/shader_material.rs | 2 + examples/shader/shader_material_glsl.rs | 2 + .../shader_material_screenspace_texture.rs | 2 + examples/stress_tests/bevymark.rs | 7 +-- examples/stress_tests/many_cubes.rs | 14 +++++ examples/stress_tests/many_lights.rs | 3 ++ examples/stress_tests/many_sprites.rs | 9 +++- examples/stress_tests/transform_hierarchy.rs | 2 +- examples/tools/scene_viewer.rs | 7 +++ examples/transforms/3d_rotation.rs | 2 + .../transforms/global_vs_local_translation.rs | 8 ++- examples/transforms/scale.rs | 2 + examples/transforms/transform.rs | 2 + examples/transforms/translation.rs | 2 + examples/ui/button.rs | 5 +- examples/ui/font_atlas_debug.rs | 6 +-- examples/ui/text.rs | 8 +-- examples/ui/text_debug.rs | 3 +- examples/ui/ui.rs | 3 +- examples/window/clear_color.rs | 4 ++ examples/window/low_power.rs | 8 +-- examples/window/multiple_windows.rs | 3 +- examples/window/scale_factor_override.rs | 4 +- examples/window/transparent_window.rs | 8 ++- examples/window/window_settings.rs | 4 +- 120 files changed, 425 insertions(+), 177 deletions(-) diff --git a/examples/2d/mesh2d.rs b/examples/2d/mesh2d.rs index 8b968a3966..6412c97f88 100644 --- a/examples/2d/mesh2d.rs +++ b/examples/2d/mesh2d.rs @@ -1,3 +1,5 @@ +//! Shows how to render a polygonal [`Mesh`], generated from a [`Quad`] primitive, in a 2D scene. + use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; fn main() { diff --git a/examples/2d/mesh2d_manual.rs b/examples/2d/mesh2d_manual.rs index e585018aa5..0fea936b4f 100644 --- a/examples/2d/mesh2d_manual.rs +++ b/examples/2d/mesh2d_manual.rs @@ -1,3 +1,8 @@ +//! This example shows how to manually render 2d items using "mid level render apis" with a custom +//! pipeline for 2d meshes. +//! It doesn't use the [`Material2d`] abstraction, but changes the vertex buffer to include vertex color. +//! Check out the "mesh2d" example for simpler / higher level 2d meshes. + use bevy::{ core_pipeline::Transparent2d, prelude::*, @@ -23,9 +28,6 @@ use bevy::{ utils::FloatOrd, }; -/// This example shows how to manually render 2d items using "mid level render apis" with a custom pipeline for 2d meshes -/// It doesn't use the [`Material2d`] abstraction, but changes the vertex buffer to include vertex color -/// Check out the "mesh2d" example for simpler / higher level 2d meshes fn main() { App::new() .add_plugins(DefaultPlugins) diff --git a/examples/2d/move_sprite.rs b/examples/2d/move_sprite.rs index a895212b3a..856adcd31b 100644 --- a/examples/2d/move_sprite.rs +++ b/examples/2d/move_sprite.rs @@ -1,3 +1,5 @@ +//! Renders a 2D scene containing a single, moving sprite. + use bevy::prelude::*; fn main() { @@ -25,6 +27,8 @@ fn setup(mut commands: Commands, asset_server: Res) { .insert(Direction::Up); } +/// The sprite is animated by changing its translation depending on the time that has passed since +/// the last frame. fn sprite_movement(time: Res