wde/lib.rs
1//! WaterDropEngine - A modular game engine.
2//!
3//! # Overview
4//! WaterDropEngine is a modular game engine built on top of Bevy's ECS. It provides a collection of plugins and tools.
5//! The engine is composed of several modules, organized from low-level to high-level:
6//! - High-Level:
7//! - [`wde_terrain`](wde_terrain): A plugin for generating and rendering procedural terrain.
8//! - [`wde_terrain_editor`](wde_terrain_editor): A plugin for editing terrain in-game.
9//! - [`wde_terrain_grid`](wde_terrain_grid): A plugin for managing terrain grids and LOD.
10//! - Render:
11//! - [`wde_pbr`](wde_pbr): A plugin for physically based rendering (PBR) materials and lighting.
12//! - [`wde_camera`](wde_camera): A plugin for managing cameras and viewports.
13//! - [`wde_camera_controller`](wde_camera_controller): A plugin for controlling cameras with various input methods.
14//! - [`wde_gltf`](wde_gltf): A plugin for loading and rendering glTF 3D models.
15//! - [`wde_gizmos`](wde_gizmos): A plugin for rendering debug gizmos and visualizations.
16//! - Core:
17//! - [`wde_renderer`](wde_renderer): A plugin for rendering 3D graphics using the `wgpu` graphics API.
18//! - [`wde_scene`](wde_scene): A plugin for managing scenes, entities, and components.
19//! - [`wde_editor`](wde_editor): A plugin for creating in-game editors and tools.
20//! - Wrappers:
21//! - [`wde_wgpu`](wde_wgpu): A wrapper around the `wgpu` graphics API for rendering. It is superseeded by [`wde_renderer`](wde_renderer).
22//! - [`wde_physics`](wde_physics): A wrapper around the `rapier` physics engine for 3D physics simulation.
23//! - [`wde_logger`](wde_logger): A wrapper around the `tracing` library for logging and diagnostics.
24//! - [`wde_egui`](wde_egui): A wrapper around the `egui` library for creating user interfaces. It is superseeded by [`wde_editor`](wde_editor).
25//!
26//! # Getting Started
27//! To get started with WaterDropEngine, add the `wde` crate to your `Cargo.toml`:
28//! ```toml
29//! [dependencies]
30//! wde = "0.1"
31//! ```
32//! Then, in your main Rust file, you can use the default plugins to set up a basic application:
33//! ```rust
34//! app.add_plugins(WdeDefaultPlugins);
35//! ```
36//!
37//! To modify and configure individual plugins, use:
38//! ```rust
39//! app.add_plugins(WdeDefaultPlugins.set(LogPlugin {
40//! level: LogLevel::DEBUG,
41//! ..Default::default()
42//! }));
43//! ```
44//!
45//! # Features
46//! WaterDropEngine is designed to be modular and extensible. You can enable or disable features! using Cargo features. For example, to enable the `pbr` feature for physically based rendering, add the following to your `Cargo.toml`:
47//! ```toml
48//! [dependencies]
49//! wde = { version = "0.1", features = ["pbr"] }
50//! ```
51
52use bevy::{
53 app::{ScheduleRunnerPlugin, TaskPoolThreadAssignmentPolicy, plugin_group},
54 diagnostic::FrameCountPlugin,
55 input::InputPlugin,
56 prelude::*,
57 time::TimePlugin
58};
59
60/// Custom Bevy plugins for WaterDropEngine default plugins.
61#[derive(Default)]
62struct CustomBevyPlugins;
63impl Plugin for CustomBevyPlugins {
64 fn build(&self, app: &mut App) {
65 app.add_plugins((
66 TaskPoolPlugin {
67 task_pool_options: TaskPoolOptions {
68 min_total_threads: 1,
69 max_total_threads: usize::MAX,
70
71 // Use 1 core for IO
72 io: TaskPoolThreadAssignmentPolicy {
73 min_threads: 1,
74 max_threads: 2,
75 percent: 0.25,
76 on_thread_spawn: None,
77 on_thread_destroy: None
78 },
79
80 // Use 1 core for async compute
81 async_compute: TaskPoolThreadAssignmentPolicy {
82 min_threads: 1,
83 max_threads: 2,
84 percent: 0.25,
85 on_thread_spawn: None,
86 on_thread_destroy: None
87 },
88
89 // Use all remaining cores for compute (at least 1)
90 compute: TaskPoolThreadAssignmentPolicy {
91 min_threads: 1,
92 max_threads: usize::MAX,
93 percent: 1.0, // This 1.0 here means "whatever is left over"
94 on_thread_spawn: None,
95 on_thread_destroy: None
96 }
97 }
98 },
99 FrameCountPlugin,
100 TimePlugin,
101 ScheduleRunnerPlugin::default(),
102 bevy::prelude::AssetPlugin {
103 mode: AssetMode::Unprocessed,
104 file_path: "res".to_string(),
105 ..Default::default()
106 },
107 InputPlugin,
108 TransformPlugin
109 ));
110 }
111}
112
113/// Custom WaterDropEngine plugins.
114#[derive(Default)]
115struct CustomWdePlugins;
116impl Plugin for CustomWdePlugins {
117 fn build(&self, app: &mut App) {
118 app.add_plugins((
119 wde_logger::LogPlugin::default().auto_level(),
120 wde_renderer::RenderPlugin,
121 wde_camera::CameraPlugin,
122 wde_camera_controller::CameraControllerPlugin,
123 wde_physics::PhysicsPlugin,
124 wde_terrain::TerrainPlugin,
125 wde_terrain_grid::TerrainGridPlugin,
126 wde_terrain_editor::TerrainEditorPlugin
127 ));
128
129 #[cfg(feature = "gizmos")]
130 app.add_plugins(wde_gizmos::GizmosPlugin);
131 #[cfg(feature = "pbr")]
132 app.add_plugins(wde_pbr::PbrPlugin);
133 #[cfg(feature = "editor")]
134 app.add_plugins(wde_editor::EditorPlugin);
135
136 // Always add the scene plugin last
137 app.add_plugins(wde_scene::ScenePlugin);
138 }
139}
140
141plugin_group! {
142 /// Default plugins for WaterDropEngine.
143 pub struct WdeDefaultPlugins {
144 :CustomBevyPlugins,
145 :CustomWdePlugins,
146 }
147}
148
149/// The prelude module of WaterDropEngine.
150/// Import this to get access to the most commonly used types and traits.
151#[doc(hidden)]
152pub mod prelude {
153 // Default plugins
154 pub use crate::WdeDefaultPlugins;
155
156 // Core modules
157 pub use wde_camera::prelude::*;
158 pub use wde_camera_controller::prelude::*;
159 pub use wde_gltf::prelude::*;
160 pub use wde_logger::prelude::*;
161 pub use wde_physics::prelude::*;
162 pub use wde_renderer::prelude::*;
163 pub use wde_scene::prelude::*;
164 pub use wde_terrain::prelude::*;
165 pub use wde_terrain_grid::prelude::*;
166
167 // Optional feature modules
168 #[cfg(feature = "editor")]
169 pub use wde_editor::prelude::*;
170 #[cfg(feature = "pbr")]
171 pub use wde_pbr::prelude::*;
172}