From e7edd1e6d5da207c7f4e456c7d4627575d47c701 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 7 Nov 2020 21:54:25 +0100 Subject: [PATCH] Add bevy_dylib to force dynamic linking of bevy This easily improve compilation time by 2x --- Cargo.toml | 72 +----- crates/bevy/Cargo.toml | 81 +++++++ {src => crates/bevy/src}/default_plugins.rs | 0 crates/bevy/src/lib.rs | 174 ++++++++++++++ {src => crates/bevy/src}/prelude.rs | 0 crates/bevy_dylib/Cargo.toml | 19 ++ crates/bevy_dylib/src/lib.rs | 5 + examples/2d/sprite.rs | 2 + examples/2d/sprite_sheet.rs | 2 + examples/2d/texture_atlas.rs | 2 + examples/3d/3d_scene.rs | 2 + examples/3d/load_gltf.rs | 2 + examples/3d/msaa.rs | 2 + examples/3d/parenting.rs | 2 + examples/3d/spawner.rs | 2 + examples/3d/texture.rs | 2 + examples/3d/z_sort_debug.rs | 2 + examples/app/empty.rs | 2 + examples/app/empty_defaults.rs | 2 + examples/app/headless.rs | 2 + examples/app/plugin.rs | 2 + examples/app/plugin_group.rs | 2 + examples/app/return_after_run.rs | 2 + examples/app/thread_pool_resources.rs | 2 + examples/asset/asset_loading.rs | 2 + examples/asset/custom_asset.rs | 2 + examples/asset/hot_asset_reloading.rs | 2 + examples/audio/audio.rs | 2 + examples/diagnostics/custom_diagnostic.rs | 2 + examples/diagnostics/print_diagnostics.rs | 2 + examples/ecs/ecs_guide.rs | 2 + examples/ecs/event.rs | 2 + examples/ecs/hierarchy.rs | 2 + examples/ecs/parallel_query.rs | 2 + examples/ecs/startup_system.rs | 2 + examples/game/breakout.rs | 2 + examples/game/breakout1.rs | 254 ++++++++++++++++++++ examples/game/breakout2.rs | 253 +++++++++++++++++++ examples/hello_world.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/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/ios/Cargo.toml | 2 +- examples/ios/src/lib.rs | 2 + examples/scene/properties.rs | 2 + examples/scene/scene.rs | 2 + examples/shader/mesh_custom_attribute.rs | 2 + examples/shader/shader_custom_material.rs | 2 + examples/shader/shader_defs.rs | 2 + examples/ui/button.rs | 2 + examples/ui/font_atlas_debug.rs | 2 + examples/ui/text.rs | 2 + examples/ui/ui.rs | 2 + examples/window/clear_color.rs | 2 + examples/window/multiple_windows.rs | 2 + examples/window/window_settings.rs | 2 + src/lib.rs | 173 ------------- 62 files changed, 893 insertions(+), 242 deletions(-) create mode 100644 crates/bevy/Cargo.toml rename {src => crates/bevy/src}/default_plugins.rs (100%) create mode 100644 crates/bevy/src/lib.rs rename {src => crates/bevy/src}/prelude.rs (100%) create mode 100644 crates/bevy_dylib/Cargo.toml create mode 100644 crates/bevy_dylib/src/lib.rs create mode 100644 examples/game/breakout1.rs create mode 100644 examples/game/breakout2.rs diff --git a/Cargo.toml b/Cargo.toml index 8d18c2969c90af..5e89732246d46f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,90 +1,26 @@ [package] -name = "bevy" +name = "bevy_examples" version = "0.3.0" edition = "2018" authors = [ "Bevy Contributors ", "Carter Anderson ", ] -description = "A refreshingly simple data-driven game engine and app framework" +description = "Examples for the Bevy game engine" homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" license = "MIT" keywords = ["game", "engine", "gamedev", "graphics", "bevy"] categories = ["game-engines", "graphics", "gui", "rendering"] -readme = "README.md" exclude = ["assets/**/*", "tools/**/*", ".github/**/*", "crates/**/*"] -[features] -default = [ - "bevy_audio", - "bevy_dynamic_plugin", - "bevy_gilrs", - "bevy_gltf", - "bevy_wgpu", - "bevy_winit", - "render", - "png", - "hdr", - "mp3", - "x11", -] - -profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"] -wgpu_trace = ["bevy_wgpu/trace"] - -# Rendering support -render = ["bevy_pbr", "bevy_render", "bevy_sprite", "bevy_text", "bevy_ui"] -# Image format support for texture loading (PNG and HDR are enabled by default) -png = ["bevy_render/png"] -hdr = ["bevy_render/hdr"] - -# Audio format support (MP3 is enabled by default) -mp3 = ["bevy_audio/mp3"] -flac = ["bevy_audio/flac"] -wav = ["bevy_audio/wav"] -vorbis = ["bevy_audio/vorbis"] - -serialize = ["bevy_input/serialize"] - -# Display server protocol support (X11 is enabled by default) -wayland = ["bevy_winit/wayland"] -x11 = ["bevy_winit/x11"] - [workspace] members = ["crates/*", "crates/bevy_ecs/hecs", "examples/ios"] exclude = ["benches"] -[dependencies] -# bevy -bevy_app = { path = "crates/bevy_app", version = "0.3.0" } -bevy_asset = { path = "crates/bevy_asset", version = "0.3.0" } -bevy_type_registry = { path = "crates/bevy_type_registry", version = "0.3.0" } -bevy_core = { path = "crates/bevy_core", version = "0.3.0" } -bevy_diagnostic = { path = "crates/bevy_diagnostic", version = "0.3.0" } -bevy_ecs = { path = "crates/bevy_ecs", version = "0.3.0" } -bevy_input = { path = "crates/bevy_input", version = "0.3.0" } -bevy_math = { path = "crates/bevy_math", version = "0.3.0" } -bevy_property = { path = "crates/bevy_property", version = "0.3.0" } -bevy_scene = { path = "crates/bevy_scene", version = "0.3.0" } -bevy_transform = { path = "crates/bevy_transform", version = "0.3.0" } -bevy_utils = { path = "crates/bevy_utils", version = "0.3.0" } -bevy_window = { path = "crates/bevy_window", version = "0.3.0" } -bevy_tasks = { path = "crates/bevy_tasks", version = "0.3.0" } -# bevy (optional) -bevy_audio = { path = "crates/bevy_audio", optional = true, version = "0.3.0" } -bevy_gltf = { path = "crates/bevy_gltf", optional = true, version = "0.3.0" } -bevy_pbr = { path = "crates/bevy_pbr", optional = true, version = "0.3.0" } -bevy_render = { path = "crates/bevy_render", optional = true, version = "0.3.0" } -bevy_dynamic_plugin = { path = "crates/bevy_dynamic_plugin", optional = true, version = "0.3.0" } -bevy_sprite = { path = "crates/bevy_sprite", optional = true, version = "0.3.0" } -bevy_text = { path = "crates/bevy_text", optional = true, version = "0.3.0" } -bevy_ui = { path = "crates/bevy_ui", optional = true, version = "0.3.0" } -bevy_wgpu = { path = "crates/bevy_wgpu", optional = true, version = "0.3.0" } -bevy_winit = { path = "crates/bevy_winit", optional = true, version = "0.3.0" } -bevy_gilrs = { path = "crates/bevy_gilrs", optional = true, version = "0.3.0" } - [dev-dependencies] +bevy = { path = "crates/bevy", version = "0.3.0" } +bevy_dylib = { path = "crates/bevy_dylib", version = "0.3.0" } rand = "0.7.3" serde = { version = "1", features = ["derive"] } log = "0.4" diff --git a/crates/bevy/Cargo.toml b/crates/bevy/Cargo.toml new file mode 100644 index 00000000000000..401d4f61999bb6 --- /dev/null +++ b/crates/bevy/Cargo.toml @@ -0,0 +1,81 @@ +[package] +name = "bevy" +version = "0.3.0" +edition = "2018" +authors = [ + "Bevy Contributors ", + "Carter Anderson ", +] +description = "A refreshingly simple data-driven game engine and app framework" +homepage = "https://bevyengine.org" +repository = "https://github.com/bevyengine/bevy" +license = "MIT" +keywords = ["game", "engine", "gamedev", "graphics", "bevy"] +categories = ["game-engines", "graphics", "gui", "rendering"] +readme = "../../README.md" + +[features] +default = [ + "bevy_audio", + "bevy_dynamic_plugin", + "bevy_gilrs", + "bevy_gltf", + "bevy_wgpu", + "bevy_winit", + "render", + "png", + "hdr", + "mp3", + "x11", +] + +profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"] +wgpu_trace = ["bevy_wgpu/trace"] + +# Rendering support +render = ["bevy_pbr", "bevy_render", "bevy_sprite", "bevy_text", "bevy_ui"] +# Image format support for texture loading (PNG and HDR are enabled by default) +png = ["bevy_render/png"] +hdr = ["bevy_render/hdr"] + +# Audio format support (MP3 is enabled by default) +mp3 = ["bevy_audio/mp3"] +flac = ["bevy_audio/flac"] +wav = ["bevy_audio/wav"] +vorbis = ["bevy_audio/vorbis"] + +serialize = ["bevy_input/serialize"] + +# Display server protocol support (X11 is enabled by default) +wayland = ["bevy_winit/wayland"] +x11 = ["bevy_winit/x11"] + +[dependencies] +# bevy +bevy_app = { path = "../bevy_app", version = "0.3.0" } +bevy_asset = { path = "../bevy_asset", version = "0.3.0" } +bevy_type_registry = { path = "../bevy_type_registry", version = "0.3.0" } +bevy_core = { path = "../bevy_core", version = "0.3.0" } +bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.3.0" } +bevy_ecs = { path = "../bevy_ecs", version = "0.3.0" } +bevy_input = { path = "../bevy_input", version = "0.3.0" } +bevy_math = { path = "../bevy_math", version = "0.3.0" } +bevy_property = { path = "../bevy_property", version = "0.3.0" } +bevy_scene = { path = "../bevy_scene", version = "0.3.0" } +bevy_transform = { path = "../bevy_transform", version = "0.3.0" } +bevy_utils = { path = "../bevy_utils", version = "0.3.0" } +bevy_window = { path = "../bevy_window", version = "0.3.0" } +bevy_tasks = { path = "../bevy_tasks", version = "0.3.0" } +# bevy (optional) +bevy_audio = { path = "../bevy_audio", optional = true, version = "0.3.0" } +bevy_gltf = { path = "../bevy_gltf", optional = true, version = "0.3.0" } +bevy_pbr = { path = "../bevy_pbr", optional = true, version = "0.3.0" } +bevy_render = { path = "../bevy_render", optional = true, version = "0.3.0" } +bevy_dynamic_plugin = { path = "../bevy_dynamic_plugin", optional = true, version = "0.3.0" } +bevy_sprite = { path = "../bevy_sprite", optional = true, version = "0.3.0" } +bevy_text = { path = "../bevy_text", optional = true, version = "0.3.0" } +bevy_ui = { path = "../bevy_ui", optional = true, version = "0.3.0" } +bevy_wgpu = { path = "../bevy_wgpu", optional = true, version = "0.3.0" } +bevy_winit = { path = "../bevy_winit", optional = true, version = "0.3.0" } +bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.3.0" } + diff --git a/src/default_plugins.rs b/crates/bevy/src/default_plugins.rs similarity index 100% rename from src/default_plugins.rs rename to crates/bevy/src/default_plugins.rs diff --git a/crates/bevy/src/lib.rs b/crates/bevy/src/lib.rs new file mode 100644 index 00000000000000..c3f8893919e80b --- /dev/null +++ b/crates/bevy/src/lib.rs @@ -0,0 +1,174 @@ +//! [![](https://bevyengine.org/assets/bevy_logo_docs.svg)](https://bevyengine.org) +//! +//! Bevy is an open-source modular game engine built in Rust, with a focus on developer productivity and performance. +//! +//! Check out the [Bevy website](https://bevyengine.org) for more information, read the +//! [Bevy Book](https://bevyengine.org/learn/book/introduction) for a step-by-step guide, and [engage with our +//! community](https://bevyengine.org/community/) if you have any questions or ideas! +//! +//! ## Example +//!Here is a simple "Hello World" Bevy app: +//! ``` +//!use bevy::prelude::*; +//! +//!fn main() { +//! App::build() +//! .add_system(hello_world_system.system()) +//! .run(); +//!} +//! +//!fn hello_world_system() { +//! println!("hello world"); +//!} +//! ``` + +//! Don't let the simplicity of the example above fool you. Bevy is a [fully featured game engine](https://bevyengine.org) +//! and it gets more powerful every day! +//! +//! ### This Crate +//! The `bevy` crate is just a container crate that makes it easier to consume Bevy components. +//! The defaults provide a "full" engine experience, but you can easily enable / disable features +//! in your project's `Cargo.toml` to meet your specific needs. See Bevy's `Cargo.toml` for a full list of features available. +//! +//! If you prefer, you can also consume the individual bevy crates directly. +//! Each module in the root of this crate, except for the prelude, can be found on crates.io +//! with `bevy_` appended to the front, e.g. `app` -> [`bevy_app`](https://docs.rs/bevy_app/*/bevy_app/). + +#![doc( + html_logo_url = "https://bevyengine.org/assets/icon.png", + html_favicon_url = "https://bevyengine.org/assets/icon.png" +)] + +/// `use bevy::prelude::*;` to import common components, bundles, and plugins. +pub mod prelude; + +mod default_plugins; +pub use default_plugins::*; + +pub mod app { + //! Build bevy apps, create plugins, and read events. + pub use bevy_app::*; +} + +pub mod asset { + //! Load and store assets and resources for Apps. + pub use bevy_asset::*; +} + +pub mod core { + //! Contains core plugins and utilities for time. + pub use bevy_core::*; +} + +pub mod diagnostic { + //! Useful diagnostic plugins and types for bevy apps. + pub use bevy_diagnostic::*; +} + +pub mod ecs { + //! Bevy's entity-component-system. + pub use bevy_ecs::*; +} + +pub mod input { + //! Resources and events for inputs, e.g. mouse/keyboard, touch, gamepads, etc. + pub use bevy_input::*; +} + +pub mod math { + //! Math types (Vec3, Mat4, Quat, etc) and helpers. + pub use bevy_math::*; +} + +pub mod property { + //! Dynamically interact with struct fields and names. + pub use bevy_property::*; +} + +pub mod scene { + //! Save/load collections of entities and components to/from file. + pub use bevy_scene::*; +} + +pub mod tasks { + //! Pools for async, IO, and compute tasks. + pub use bevy_tasks::*; +} + +pub mod transform { + //! Local and global transforms (e.g. translation, scale, rotation). + pub use bevy_transform::*; +} + +pub mod type_registry { + //! Registered types and components can be used when loading scenes. + pub use bevy_type_registry::*; +} + +pub mod utils { + pub use bevy_utils::*; +} + +pub mod window { + //! Configuration, creation, and management of one or more windows. + pub use bevy_window::*; +} + +#[cfg(feature = "bevy_audio")] +pub mod audio { + //! Provides types and plugins for audio playback. + pub use bevy_audio::*; +} + +#[cfg(feature = "bevy_gltf")] +pub mod gltf { + //! Support for GLTF file loading. + pub use bevy_gltf::*; +} + +#[cfg(feature = "bevy_pbr")] +pub mod pbr { + //! Physically based rendering. + //! **Note**: true PBR has not yet been implemented; the name `pbr` is aspirational. + pub use bevy_pbr::*; +} + +#[cfg(feature = "bevy_render")] +pub mod render { + //! Cameras, meshes, textures, shaders, and pipelines. + pub use bevy_render::*; +} + +#[cfg(feature = "bevy_sprite")] +pub mod sprite { + //! Items for sprites, rects, texture atlases, etc. + pub use bevy_sprite::*; +} + +#[cfg(feature = "bevy_text")] +pub mod text { + //! Text drawing, styling, and font assets. + pub use bevy_text::*; +} + +#[cfg(feature = "bevy_ui")] +pub mod ui { + //! User interface components and widgets. + pub use bevy_ui::*; +} + +#[cfg(feature = "bevy_winit")] +pub mod winit { + pub use bevy_winit::*; +} + +#[cfg(feature = "bevy_wgpu")] +pub mod wgpu { + //! A render backend utilizing [wgpu](https://github.com/gfx-rs/wgpu-rs). + pub use bevy_wgpu::*; +} + +#[cfg(feature = "bevy_dynamic_plugin")] +pub mod dynamic_plugin { + pub use bevy_dynamic_plugin::*; +} diff --git a/src/prelude.rs b/crates/bevy/src/prelude.rs similarity index 100% rename from src/prelude.rs rename to crates/bevy/src/prelude.rs diff --git a/crates/bevy_dylib/Cargo.toml b/crates/bevy_dylib/Cargo.toml new file mode 100644 index 00000000000000..b1384a27373ee2 --- /dev/null +++ b/crates/bevy_dylib/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "bevy_dylib" +version = "0.3.0" +edition = "2018" +authors = [ + "Bevy Contributors ", + "Carter Anderson ", +] +description = "Force the Bevy Engine to be dynamically linked for faster linking" +homepage = "https://bevyengine.org" +repository = "https://github.com/bevyengine/bevy" +license = "MIT" +keywords = ["bevy"] + +[lib] +crate-type = ["dylib"] + +[dependencies] +bevy = { path = "../bevy", version = "0.3.0", default-features = false } diff --git a/crates/bevy_dylib/src/lib.rs b/crates/bevy_dylib/src/lib.rs new file mode 100644 index 00000000000000..fa933de75e1ee9 --- /dev/null +++ b/crates/bevy_dylib/src/lib.rs @@ -0,0 +1,5 @@ +//! Forces dynamic linking of Bevy + +// Force linking of the main bevy crate +#[allow(unused_imports)] +use bevy; diff --git a/examples/2d/sprite.rs b/examples/2d/sprite.rs index b4cff1721d19b8..25d6ff36cf2c34 100644 --- a/examples/2d/sprite.rs +++ b/examples/2d/sprite.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/2d/sprite_sheet.rs b/examples/2d/sprite_sheet.rs index ae774b6120a1f0..88706160003708 100644 --- a/examples/2d/sprite_sheet.rs +++ b/examples/2d/sprite_sheet.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index e6036d1d34414a..8459f2bf98f5cc 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -1,4 +1,6 @@ use bevy::{asset::LoadState, prelude::*, sprite::TextureAtlasBuilder}; +#[allow(unused_imports)] +use bevy_dylib; /// In this example we generate a new texture atlas (sprite sheet) from a folder containing individual sprites fn main() { diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index e053e10fa818f7..d326a13c869b63 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index 248c525a5c4d49..9b02ae539e8ac7 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/3d/msaa.rs b/examples/3d/msaa.rs index 264facd4dbf946..3da61e7bbb44f5 100644 --- a/examples/3d/msaa.rs +++ b/examples/3d/msaa.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example shows how to configure Multi-Sample Anti-Aliasing. Setting the sample count higher will result in smoother edges, /// but it will also increase the cost to render those edges. The range should generally be somewhere between 1 (no multi sampling, diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index f97b35c71a4054..8e88f4d69c2016 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example illustrates how to create parent->child relationships between entities how parent transforms /// are propagated to their descendants diff --git a/examples/3d/spawner.rs b/examples/3d/spawner.rs index 00cd45439702fb..ff711c2c0a05d8 100644 --- a/examples/3d/spawner.rs +++ b/examples/3d/spawner.rs @@ -2,6 +2,8 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, PrintDiagnosticsPlugin}, prelude::*, }; +#[allow(unused_imports)] +use bevy_dylib; use rand::{rngs::StdRng, Rng, SeedableRng}; /// This example spawns a large number of cubes, each with its own changing position and material diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index 298e1f591a3f2f..0e3c60bd61dbea 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example shows various ways to configure texture materials in 3D fn main() { diff --git a/examples/3d/z_sort_debug.rs b/examples/3d/z_sort_debug.rs index 8640d9b60f0380..2a892a96103ff8 100644 --- a/examples/3d/z_sort_debug.rs +++ b/examples/3d/z_sort_debug.rs @@ -5,6 +5,8 @@ use bevy::{ mesh::shape, }, }; +#[allow(unused_imports)] +use bevy_dylib; /// This example visualizes camera z-ordering by setting the material of rotating cubes to their distance from the camera fn main() { diff --git a/examples/app/empty.rs b/examples/app/empty.rs index 7ee2c99993f3e1..dd989ab08e1cba 100644 --- a/examples/app/empty.rs +++ b/examples/app/empty.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build().run(); diff --git a/examples/app/empty_defaults.rs b/examples/app/empty_defaults.rs index bebb62b61533d0..43bfec3466e012 100644 --- a/examples/app/empty_defaults.rs +++ b/examples/app/empty_defaults.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build().add_plugins(DefaultPlugins).run(); diff --git a/examples/app/headless.rs b/examples/app/headless.rs index 9b13f8fe415c5e..b97c1adf8cce73 100644 --- a/examples/app/headless.rs +++ b/examples/app/headless.rs @@ -1,4 +1,6 @@ use bevy::{app::ScheduleRunnerSettings, prelude::*}; +#[allow(unused_imports)] +use bevy_dylib; use std::time::Duration; // This example only enables a minimal set of plugins required for bevy to run. diff --git a/examples/app/plugin.rs b/examples/app/plugin.rs index 602a3bfd92c2be..4093f357b8dc1a 100644 --- a/examples/app/plugin.rs +++ b/examples/app/plugin.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; use std::time::Duration; /// Plugins are the foundation of Bevy. They are scoped sets of components, resources, and systems diff --git a/examples/app/plugin_group.rs b/examples/app/plugin_group.rs index 81cd0b2ef22017..bcb97c177cd79c 100644 --- a/examples/app/plugin_group.rs +++ b/examples/app/plugin_group.rs @@ -1,4 +1,6 @@ use bevy::{app::PluginGroupBuilder, prelude::*}; +#[allow(unused_imports)] +use bevy_dylib; /// PluginGroups are a way to group sets of plugins that should be registered together. fn main() { diff --git a/examples/app/return_after_run.rs b/examples/app/return_after_run.rs index ab951341a62dc9..57565d2ccd9cbb 100644 --- a/examples/app/return_after_run.rs +++ b/examples/app/return_after_run.rs @@ -1,4 +1,6 @@ use bevy::{prelude::*, render::pass::ClearColor, winit::WinitConfig}; +#[allow(unused_imports)] +use bevy_dylib; fn main() { println!("Running first App."); diff --git a/examples/app/thread_pool_resources.rs b/examples/app/thread_pool_resources.rs index 52427d4e00bbc5..57fde26a467c2d 100644 --- a/examples/app/thread_pool_resources.rs +++ b/examples/app/thread_pool_resources.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example illustrates how to customize the thread pool used internally (e.g. to only use a /// certain number of threads). diff --git a/examples/asset/asset_loading.rs b/examples/asset/asset_loading.rs index e081446810f6c5..2133ff7f6df0b2 100644 --- a/examples/asset/asset_loading.rs +++ b/examples/asset/asset_loading.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example illustrates various ways to load assets fn main() { diff --git a/examples/asset/custom_asset.rs b/examples/asset/custom_asset.rs index 1d7cd87da21242..fa17e28a3e37e3 100644 --- a/examples/asset/custom_asset.rs +++ b/examples/asset/custom_asset.rs @@ -4,6 +4,8 @@ use bevy::{ type_registry::TypeUuid, utils::BoxedFuture, }; +#[allow(unused_imports)] +use bevy_dylib; use serde::Deserialize; #[derive(Debug, Deserialize, TypeUuid)] diff --git a/examples/asset/hot_asset_reloading.rs b/examples/asset/hot_asset_reloading.rs index 89319e10f06048..6e2fda3ffaa348 100644 --- a/examples/asset/hot_asset_reloading.rs +++ b/examples/asset/hot_asset_reloading.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// Hot reloading allows you to modify assets on disk and they will be "live reloaded" while your game is running. /// This lets you immediately see the results of your changes without restarting the game. diff --git a/examples/audio/audio.rs b/examples/audio/audio.rs index a8296ad95305b5..9091c9bda92962 100644 --- a/examples/audio/audio.rs +++ b/examples/audio/audio.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example illustrates how to load and play an audio file fn main() { diff --git a/examples/diagnostics/custom_diagnostic.rs b/examples/diagnostics/custom_diagnostic.rs index 4b2e832467a444..62f0a6dcc03b70 100644 --- a/examples/diagnostics/custom_diagnostic.rs +++ b/examples/diagnostics/custom_diagnostic.rs @@ -2,6 +2,8 @@ use bevy::{ diagnostic::{Diagnostic, DiagnosticId, Diagnostics, PrintDiagnosticsPlugin}, prelude::*, }; +#[allow(unused_imports)] +use bevy_dylib; /// This example illustrates how to create a custom diagnostic fn main() { diff --git a/examples/diagnostics/print_diagnostics.rs b/examples/diagnostics/print_diagnostics.rs index 5ed9a5f1081098..81267eec657a3f 100644 --- a/examples/diagnostics/print_diagnostics.rs +++ b/examples/diagnostics/print_diagnostics.rs @@ -2,6 +2,8 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, PrintDiagnosticsPlugin}, prelude::*, }; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/ecs/ecs_guide.rs b/examples/ecs/ecs_guide.rs index 10a7c706d56b65..9b0524327f5f14 100644 --- a/examples/ecs/ecs_guide.rs +++ b/examples/ecs/ecs_guide.rs @@ -2,6 +2,8 @@ use bevy::{ app::{AppExit, ScheduleRunnerPlugin, ScheduleRunnerSettings}, prelude::*, }; +#[allow(unused_imports)] +use bevy_dylib; use rand::random; use std::time::Duration; diff --git a/examples/ecs/event.rs b/examples/ecs/event.rs index a7c10025f3779c..2813784e393f58 100644 --- a/examples/ecs/event.rs +++ b/examples/ecs/event.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; /// This example creates a new event, a system that triggers the event once per second, /// and a system that prints a message whenever the event is received. diff --git a/examples/ecs/hierarchy.rs b/examples/ecs/hierarchy.rs index cc84790bb381d2..5e02f04543e3a4 100644 --- a/examples/ecs/hierarchy.rs +++ b/examples/ecs/hierarchy.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/ecs/parallel_query.rs b/examples/ecs/parallel_query.rs index 46f2f1918256ee..bbfdd5f8896375 100644 --- a/examples/ecs/parallel_query.rs +++ b/examples/ecs/parallel_query.rs @@ -1,4 +1,6 @@ use bevy::{prelude::*, tasks::prelude::*}; +#[allow(unused_imports)] +use bevy_dylib; use rand::random; struct Velocity(Vec2); diff --git a/examples/ecs/startup_system.rs b/examples/ecs/startup_system.rs index 395d69322b12d7..618a270a46055a 100644 --- a/examples/ecs/startup_system.rs +++ b/examples/ecs/startup_system.rs @@ -1,4 +1,6 @@ use bevy::prelude::*; +#[allow(unused_imports)] +use bevy_dylib; fn main() { App::build() diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 6097971e63929e..6749fef52be060 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -3,6 +3,8 @@ use bevy::{ render::pass::ClearColor, sprite::collide_aabb::{collide, Collision}, }; +#[allow(unused_imports)] +use bevy_dylib; /// An implementation of the classic game "Breakout" fn main() { diff --git a/examples/game/breakout1.rs b/examples/game/breakout1.rs new file mode 100644 index 00000000000000..a939707bf2c888 --- /dev/null +++ b/examples/game/breakout1.rs @@ -0,0 +1,254 @@ +use bevy::{ + prelude::*, + render::pass::ClearColor, + sprite::collide_aabb::{collide, Collision}, +}; +#[allow(unused_imports)] +use bevy_dylib; + +/// An implementation of the classic game "Breakout" +fn main() { + println!(); + App::build() + .add_plugins(DefaultPlugins) + .add_resource(Scoreboard { score: 0 }) + .add_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9))) + .add_startup_system(setup.system()) + .add_system(paddle_movement_system.system()) + .add_system(ball_collision_system.system()) + .add_system(ball_movement_system.system()) + .add_system(scoreboard_system.system()) + .run(); +} + +struct Paddle { + speed: f32, +} + +struct Ball { + velocity: Vec3, +} + +struct Scoreboard { + score: usize, +} + +enum Collider { + Solid, + Scorable, + Paddle, +} + +fn setup( + mut commands: Commands, + mut materials: ResMut>, + asset_server: Res, +) { + // Add the game's entities to our world + commands + // cameras + .spawn(Camera2dComponents::default()) + .spawn(UiCameraComponents::default()) + // paddle + .spawn(SpriteComponents { + material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()), + transform: Transform::from_translation(Vec3::new(0.0, -215.0, 0.0)), + sprite: Sprite::new(Vec2::new(120.0, 30.0)), + ..Default::default() + }) + .with(Paddle { speed: 500.0 }) + .with(Collider::Paddle) + // ball + .spawn(SpriteComponents { + material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()), + transform: Transform::from_translation(Vec3::new(0.0, -50.0, 1.0)), + sprite: Sprite::new(Vec2::new(30.0, 30.0)), + ..Default::default() + }) + .with(Ball { + velocity: 400.0 * Vec3::new(0.5, -0.5, 0.0).normalize(), + }) + // scoreboard + .spawn(TextComponents { + text: Text { + font: asset_server.load("fonts/FiraSans-Bold.ttf"), + value: "Score:".to_string(), + style: TextStyle { + color: Color::rgb(0.5, 0.5, 1.0), + font_size: 40.0, + }, + }, + style: Style { + position_type: PositionType::Absolute, + position: Rect { + top: Val::Px(5.0), + left: Val::Px(5.0), + ..Default::default() + }, + ..Default::default() + }, + ..Default::default() + }); + + // Add walls + let wall_material = materials.add(Color::rgb(0.8, 0.8, 0.8).into()); + let wall_thickness = 10.0; + let bounds = Vec2::new(900.0, 600.0); + + commands + // left + .spawn(SpriteComponents { + material: wall_material.clone(), + transform: Transform::from_translation(Vec3::new(-bounds.x() / 2.0, 0.0, 0.0)), + sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y() + wall_thickness)), + ..Default::default() + }) + .with(Collider::Solid) + // right + .spawn(SpriteComponents { + material: wall_material.clone(), + transform: Transform::from_translation(Vec3::new(bounds.x() / 2.0, 0.0, 0.0)), + sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y() + wall_thickness)), + ..Default::default() + }) + .with(Collider::Solid) + // bottom + .spawn(SpriteComponents { + material: wall_material.clone(), + transform: Transform::from_translation(Vec3::new(0.0, -bounds.y() / 2.0, 0.0)), + sprite: Sprite::new(Vec2::new(bounds.x() + wall_thickness, wall_thickness)), + ..Default::default() + }) + .with(Collider::Solid) + // top + .spawn(SpriteComponents { + material: wall_material, + transform: Transform::from_translation(Vec3::new(0.0, bounds.y() / 2.0, 0.0)), + sprite: Sprite::new(Vec2::new(bounds.x() + wall_thickness, wall_thickness)), + ..Default::default() + }) + .with(Collider::Solid); + + // Add bricks + let brick_rows = 4; + let brick_columns = 5; + let brick_spacing = 20.0; + let brick_size = Vec2::new(150.0, 30.0); + let bricks_width = brick_columns as f32 * (brick_size.x() + brick_spacing) - brick_spacing; + // center the bricks and move them up a bit + let bricks_offset = Vec3::new(-(bricks_width - brick_size.x()) / 2.0, 100.0, 0.0); + let brick_material = materials.add(Color::rgb(0.5, 0.5, 1.0).into()); + for row in 0..brick_rows { + let y_position = row as f32 * (brick_size.y() + brick_spacing); + for column in 0..brick_columns { + let brick_position = Vec3::new( + column as f32 * (brick_size.x() + brick_spacing), + y_position, + 0.0, + ) + bricks_offset; + commands + // brick + .spawn(SpriteComponents { + material: brick_material.clone(), + sprite: Sprite::new(brick_size), + transform: Transform::from_translation(brick_position), + ..Default::default() + }) + .with(Collider::Scorable); + } + } +} + +fn paddle_movement_system( + time: Res