diff --git a/crates/bevy_app/src/ci_testing.rs b/crates/bevy_app/src/ci_testing.rs index 66206d91095c35..17d8d929d6a4ce 100644 --- a/crates/bevy_app/src/ci_testing.rs +++ b/crates/bevy_app/src/ci_testing.rs @@ -1,6 +1,7 @@ use crate::{app::AppExit, App}; use serde::Deserialize; +use bevy_ecs::prelude::Resource; use bevy_utils::tracing::info; /// A configuration struct for automated CI testing. @@ -8,7 +9,7 @@ use bevy_utils::tracing::info; /// It gets used when the `bevy_ci_testing` feature is enabled to automatically /// exit a Bevy app when run through the CI. This is needed because otherwise /// Bevy apps would be stuck in the game loop and wouldn't allow the CI to progress. -#[derive(Deserialize)] +#[derive(Deserialize, Resource)] pub struct CiTestingConfig { /// The number of frames after which Bevy should exit. pub exit_after: Option, diff --git a/crates/bevy_app/src/schedule_runner.rs b/crates/bevy_app/src/schedule_runner.rs index aa63ce1a8b3d01..04535c045dd9d0 100644 --- a/crates/bevy_app/src/schedule_runner.rs +++ b/crates/bevy_app/src/schedule_runner.rs @@ -3,6 +3,7 @@ use crate::{ plugin::Plugin, }; use bevy_ecs::event::{Events, ManualEventReader}; +use bevy_ecs::prelude::Resource; use bevy_utils::{Duration, Instant}; #[cfg(target_arch = "wasm32")] @@ -34,7 +35,7 @@ impl Default for RunMode { /// The configuration information for the [`ScheduleRunnerPlugin`]. /// /// It gets added as a [`Resource`](bevy_ecs::system::Resource) inside of the [`ScheduleRunnerPlugin`]. -#[derive(Copy, Clone, Default)] +#[derive(Copy, Clone, Default, Resource)] pub struct ScheduleRunnerSettings { /// Determines whether the [`Schedule`](bevy_ecs::schedule::Schedule) is run once or repeatedly. pub run_mode: RunMode, diff --git a/crates/bevy_ecs/examples/change_detection.rs b/crates/bevy_ecs/examples/change_detection.rs index 1a3e135b654e2c..1f2af2e35c812d 100644 --- a/crates/bevy_ecs/examples/change_detection.rs +++ b/crates/bevy_ecs/examples/change_detection.rs @@ -40,7 +40,7 @@ fn main() { } // This struct will be used as a Resource keeping track of the total amount of spawned entities -#[derive(Debug)] +#[derive(Debug, Resource)] struct EntityCounter { pub value: i32, } diff --git a/crates/bevy_ecs/examples/resources.rs b/crates/bevy_ecs/examples/resources.rs index c6700a6b9ed9dd..3127f52d907328 100644 --- a/crates/bevy_ecs/examples/resources.rs +++ b/crates/bevy_ecs/examples/resources.rs @@ -27,7 +27,7 @@ fn main() { } // Counter resource to be increased and read by systems -#[derive(Debug)] +#[derive(Debug, Resource)] struct Counter { pub value: i32, } diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index fdcb2a0d0d9745..c5f6b1793d9964 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -1,6 +1,6 @@ //! Types for declaring and storing [`Component`]s. -use crate::{ +pub use crate::{ change_detection::MAX_CHANGE_AGE, storage::{SparseSetIndex, Storages}, system::Resource, diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index 22af1b3ed2dffa..33b94c3926804b 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -1,7 +1,7 @@ //! Event handling types. use crate as bevy_ecs; -use crate::system::{Local, Res, ResMut, SystemParam}; +use crate::system::{Local, Res, ResMut, SystemParam, Resource}; use bevy_utils::tracing::trace; use std::ops::{Deref, DerefMut}; use std::{ @@ -128,7 +128,7 @@ struct EventInstance { /// [Example usage.](https://github.com/bevyengine/bevy/blob/latest/examples/ecs/event.rs) /// [Example usage standalone.](https://github.com/bevyengine/bevy/blob/latest/bevy_ecs/examples/events.rs) /// -#[derive(Debug)] +#[derive(Debug, Resource)] pub struct Events { /// Holds the oldest still active events. /// Note that a.start_event_count + a.len() should always === events_b.start_event_count. diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index c82924b0e276c5..d83b65685d25b1 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -324,8 +324,12 @@ mod tests { use crate as bevy_ecs; use crate::component::Component; + use crate::system::Resource; + #[derive(Component)] struct W(T); + #[derive(Resource)] + struct Counter(usize); fn receive_events(world: &World) -> Vec { let mut events = Vec::new(); @@ -355,8 +359,8 @@ mod tests { fn resources() { let mut world = World::new(); world.insert_resource(0usize); - fn wants_mut(_: ResMut) {} - fn wants_ref(_: Res) {} + fn wants_mut(_: ResMut) {} + fn wants_ref(_: Res) {} let mut stage = SystemStage::parallel() .with_system(wants_mut) .with_system(wants_mut); diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index ff26ced892a6f1..69ae546190f9d2 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -958,8 +958,12 @@ mod tests { use crate as bevy_ecs; use crate::component::Component; + use crate::system::Resource; + #[derive(Component)] struct W(T); + #[derive(Resource)] + struct R(usize); fn make_exclusive(tag: usize) -> impl FnMut(&mut World) { move |world| world.resource_mut::>().push(tag) @@ -1606,7 +1610,7 @@ mod tests { } fn empty() {} - fn resource(_: ResMut) {} + fn resource(_: ResMut) {} fn component(_: Query<&mut W>) {} let mut world = World::new(); @@ -1976,15 +1980,12 @@ mod tests { #[test] fn archetype_update_single_executor() { - fn query_count_system( - mut entity_count: ResMut, - query: Query, - ) { + fn query_count_system(mut entity_count: ResMut, query: Query) { *entity_count = query.iter().count(); } let mut world = World::new(); - world.insert_resource(0_usize); + world.insert_resource(R(0)); let mut stage = SystemStage::single(query_count_system); let entity = world.spawn().insert_bundle(()).id(); diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 1693f0adce7e36..34d0262693cefc 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -3,13 +3,15 @@ use crate::{ RunCriteriaDescriptor, RunCriteriaDescriptorCoercion, RunCriteriaLabel, ShouldRun, SystemSet, }, - system::{In, IntoChainSystem, Local, Res, ResMut}, + system::{In, IntoChainSystem, Local, Res, ResMut, Resource}, }; use std::{ any::TypeId, fmt::{self, Debug}, hash::Hash, }; +// Required for derive macros +use crate as bevy_ecs; pub trait StateData: Send + Sync + Clone + Eq + Debug + Hash + 'static {} impl StateData for T where T: Send + Sync + Clone + Eq + Debug + Hash + 'static {} @@ -21,7 +23,7 @@ impl StateData for T where T: Send + Sync + Clone + Eq + Debug + Hash + 'stat /// * Pop removes the current state, and unpauses the last paused state /// * Set replaces the active state with a new one /// * Replace unwinds the state stack, and replaces the entire stack with a single new state -#[derive(Debug)] +#[derive(Debug, Resource)] pub struct State { transition: Option>, /// The current states in the stack. diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 04d14f9afe6527..941ad8af798230 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -111,7 +111,7 @@ mod tests { schedule::{Schedule, Stage, SystemStage}, system::{ Commands, IntoExclusiveSystem, IntoSystem, Local, NonSend, NonSendMut, ParamSet, Query, - RemovedComponents, Res, ResMut, System, SystemState, + RemovedComponents, Res, ResMut, Resource, System, SystemState, }, world::{FromWorld, World}, }; @@ -244,10 +244,19 @@ mod tests { #[test] fn changed_resource_system() { + use crate::system::Resource; + + #[derive(Resource)] + struct Flipper(bool); + + #[derive(Resource)] struct Added(usize); + + #[derive(Resource)] struct Changed(usize); + fn incr_e_on_flip( - value: Res, + value: Res, mut changed: ResMut, mut added: ResMut, ) { @@ -261,7 +270,7 @@ mod tests { } let mut world = World::default(); - world.insert_resource(false); + world.insert_resource(Flipper(false)); world.insert_resource(Added(0)); world.insert_resource(Changed(0)); @@ -406,7 +415,7 @@ mod tests { run_system(&mut world, sys); } - #[derive(Default)] + #[derive(Default, Resource)] struct BufferRes { _buffer: Vec, } diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index e0ec4892f31fa2..d15c206492e6d5 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -1,4 +1,5 @@ pub use crate::change_detection::{NonSendMut, ResMut}; +pub use bevy_ecs_macros::Resource; use crate::{ archetype::{Archetype, Archetypes}, bundle::Bundles,