Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-string labels (#1423 continued) #1473

Merged
merged 27 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2bd15fa
Add Label type
TheRawMeatball Feb 9, 2021
f41d7eb
General improvement
TheRawMeatball Feb 9, 2021
85eebf2
Fix stuff
TheRawMeatball Feb 9, 2021
857fa83
hotfix
TheRawMeatball Feb 9, 2021
d0cc270
rework to implement suggestions
TheRawMeatball Feb 15, 2021
52567f5
cargo fmt
TheRawMeatball Feb 15, 2021
37941ba
cargo test
TheRawMeatball Feb 15, 2021
fd3747c
Improve Debug impl on dyn Label
TheRawMeatball Feb 16, 2021
4b90fb0
Apply suggestions from code review
TheRawMeatball Feb 16, 2021
b8af092
hotfix
TheRawMeatball Feb 16, 2021
c28f3fd
Implement minor suggestion
TheRawMeatball Feb 16, 2021
099f8a6
Revert changes in tests
TheRawMeatball Feb 16, 2021
e70a8c1
Fix doctest
TheRawMeatball Feb 16, 2021
c002ba2
Fix inconsistencies
TheRawMeatball Feb 16, 2021
2e95129
Merge remote-tracking branch 'upstream/master' into zst-labels
TheRawMeatball Feb 16, 2021
c5724f6
Revert accidental changes
TheRawMeatball Feb 16, 2021
9c70a5d
Switch to requirig Debug impl
TheRawMeatball Feb 16, 2021
6d82c4e
cargo fmt
TheRawMeatball Feb 16, 2021
b7f1e85
Fix test
TheRawMeatball Feb 16, 2021
6e8f6fd
Merge 'upstream/master' into zst-labels
TheRawMeatball Feb 17, 2021
62f1eef
Fancify labels
TheRawMeatball Feb 17, 2021
da24443
mod/use consistency
cart Feb 17, 2021
7c20ed2
Implement requested changes
TheRawMeatball Feb 18, 2021
a904796
cargo fmt
TheRawMeatball Feb 18, 2021
ea539b0
Improvements from @Ratyzs
Ratysz Feb 18, 2021
3f0d074
Resolve conflicts
Ratysz Feb 18, 2021
d2eebf8
Merge branch 'master' into zst-labels
Ratysz Feb 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions crates/bevy_app/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{
app::{App, AppExit},
event::Events,
plugin::Plugin,
stage, startup_stage, PluginGroup, PluginGroupBuilder,
CoreStage, PluginGroup, PluginGroupBuilder, StartupStage,
};
use bevy_ecs::{
clear_trackers_system, FromResources, IntoExclusiveSystem, IntoSystem, Resource, Resources,
RunOnce, Schedule, Stage, StateStage, SystemDescriptor, SystemStage, World,
RunOnce, Schedule, Stage, StageLabel, StateStage, SystemDescriptor, SystemStage, World,
};
use bevy_utils::tracing::debug;

Expand All @@ -24,7 +24,7 @@ impl Default for AppBuilder {
app_builder
.add_default_stages()
.add_event::<AppExit>()
.add_system_to_stage(stage::LAST, clear_trackers_system.exclusive_system());
.add_system_to_stage(CoreStage::Last, clear_trackers_system.exclusive_system());
app_builder
}
}
Expand Down Expand Up @@ -54,110 +54,110 @@ impl AppBuilder {
self
}

pub fn add_stage<S: Stage>(&mut self, name: &'static str, stage: S) -> &mut Self {
self.app.schedule.add_stage(name, stage);
pub fn add_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.app.schedule.add_stage(label, stage);
self
}

pub fn add_stage_after<S: Stage>(
&mut self,
target: &'static str,
name: &'static str,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app.schedule.add_stage_after(target, name, stage);
self.app.schedule.add_stage_after(target, label, stage);
self
}

pub fn add_stage_before<S: Stage>(
&mut self,
target: &'static str,
name: &'static str,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app.schedule.add_stage_before(target, name, stage);
self.app.schedule.add_stage_before(target, label, stage);
self
}

pub fn add_startup_stage<S: Stage>(&mut self, name: &'static str, stage: S) -> &mut Self {
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.app
.schedule
.stage(stage::STARTUP, |schedule: &mut Schedule| {
schedule.add_stage(name, stage)
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage(label, stage)
});
self
}

pub fn add_startup_stage_after<S: Stage>(
&mut self,
target: &'static str,
name: &'static str,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app
.schedule
.stage(stage::STARTUP, |schedule: &mut Schedule| {
schedule.add_stage_after(target, name, stage)
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage_after(target, label, stage)
});
self
}

pub fn add_startup_stage_before<S: Stage>(
&mut self,
target: &'static str,
name: &'static str,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app
.schedule
.stage(stage::STARTUP, |schedule: &mut Schedule| {
schedule.add_stage_before(target, name, stage)
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage_before(target, label, stage)
});
self
}

pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
&mut self,
name: &str,
label: impl StageLabel,
func: F,
) -> &mut Self {
self.app.schedule.stage(name, func);
self.app.schedule.stage(label, func);
self
}

pub fn add_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut Self {
self.add_system_to_stage(stage::UPDATE, system)
self.add_system_to_stage(CoreStage::Update, system)
}

pub fn add_system_to_stage(
&mut self,
stage_name: &'static str,
stage_label: impl StageLabel,
system: impl Into<SystemDescriptor>,
) -> &mut Self {
self.app.schedule.add_system_to_stage(stage_name, system);
self.app.schedule.add_system_to_stage(stage_label, system);
self
}

pub fn add_startup_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut Self {
self.add_startup_system_to_stage(startup_stage::STARTUP, system)
self.add_startup_system_to_stage(StartupStage::Startup, system)
}

pub fn add_startup_system_to_stage(
&mut self,
stage_name: &'static str,
stage_label: impl StageLabel,
system: impl Into<SystemDescriptor>,
) -> &mut Self {
self.app
.schedule
.stage(stage::STARTUP, |schedule: &mut Schedule| {
schedule.add_system_to_stage(stage_name, system)
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_system_to_stage(stage_label, system)
});
self
}

pub fn on_state_enter<T: Clone + Resource>(
&mut self,
stage: &str,
stage: impl StageLabel,
state: T,
system: impl Into<SystemDescriptor>,
) -> &mut Self {
Expand All @@ -168,7 +168,7 @@ impl AppBuilder {

pub fn on_state_update<T: Clone + Resource>(
&mut self,
stage: &str,
stage: impl StageLabel,
state: T,
system: impl Into<SystemDescriptor>,
) -> &mut Self {
Expand All @@ -179,7 +179,7 @@ impl AppBuilder {

pub fn on_state_exit<T: Clone + Resource>(
&mut self,
stage: &str,
stage: impl StageLabel,
state: T,
system: impl Into<SystemDescriptor>,
) -> &mut Self {
Expand All @@ -190,28 +190,28 @@ impl AppBuilder {

pub fn add_default_stages(&mut self) -> &mut Self {
self.add_stage(
stage::STARTUP,
CoreStage::Startup,
Schedule::default()
.with_run_criteria(RunOnce::default())
.with_stage(startup_stage::PRE_STARTUP, SystemStage::parallel())
.with_stage(startup_stage::STARTUP, SystemStage::parallel())
.with_stage(startup_stage::POST_STARTUP, SystemStage::parallel()),
.with_stage(StartupStage::PreStartup, SystemStage::parallel())
.with_stage(StartupStage::Startup, SystemStage::parallel())
.with_stage(StartupStage::PostStartup, SystemStage::parallel()),
)
.add_stage(stage::FIRST, SystemStage::parallel())
.add_stage(stage::PRE_EVENT, SystemStage::parallel())
.add_stage(stage::EVENT, SystemStage::parallel())
.add_stage(stage::PRE_UPDATE, SystemStage::parallel())
.add_stage(stage::UPDATE, SystemStage::parallel())
.add_stage(stage::POST_UPDATE, SystemStage::parallel())
.add_stage(stage::LAST, SystemStage::parallel())
.add_stage(CoreStage::First, SystemStage::parallel())
.add_stage(CoreStage::PreEvent, SystemStage::parallel())
.add_stage(CoreStage::Event, SystemStage::parallel())
.add_stage(CoreStage::PreUpdate, SystemStage::parallel())
.add_stage(CoreStage::Update, SystemStage::parallel())
.add_stage(CoreStage::PostUpdate, SystemStage::parallel())
.add_stage(CoreStage::Last, SystemStage::parallel())
}

pub fn add_event<T>(&mut self) -> &mut Self
where
T: Send + Sync + 'static,
{
self.insert_resource(Events::<T>::default())
.add_system_to_stage(stage::EVENT, Events::<T>::update_system.system())
.add_system_to_stage(CoreStage::Event, Events::<T>::update_system.system())
}

/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.
Expand Down
40 changes: 34 additions & 6 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// The names of the default App stages
pub mod stage;
/// The names of the default App startup stages
pub mod startup_stage;

mod app;
mod app_builder;
mod event;
Expand All @@ -23,6 +18,39 @@ pub mod prelude {
app::App,
app_builder::AppBuilder,
event::{EventReader, Events},
stage, DynamicPlugin, Plugin, PluginGroup,
CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage,
};
}

use bevy_ecs::StageLabel;

/// The names of the default App stages
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
pub enum CoreStage {
/// Runs once at the beginning of the app.
Startup,
/// Name of app stage that runs before all other app stages
First,
/// Name of app stage that runs before EVENT
PreEvent,
/// Name of app stage that updates events. Runs before UPDATE
Event,
/// Name of app stage responsible for performing setup before an update. Runs before UPDATE.
PreUpdate,
/// Name of app stage responsible for doing most app logic. Systems should be registered here by default.
Update,
/// Name of app stage responsible for processing the results of UPDATE. Runs after UPDATE.
PostUpdate,
/// Name of app stage that runs after all other app stages
Last,
}
/// The names of the default App startup stages
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
pub enum StartupStage {
/// Name of app stage that runs once before the startup stage
PreStartup,
/// Name of app stage that runs once when an app starts up
Startup,
/// Name of app stage that runs once after the startup stage
PostStartup,
}
23 changes: 0 additions & 23 deletions crates/bevy_app/src/stage.rs

This file was deleted.

8 changes: 0 additions & 8 deletions crates/bevy_app/src/startup_stage.rs

This file was deleted.

7 changes: 4 additions & 3 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
update_asset_storage_system, Asset, AssetLoader, AssetServer, Handle, HandleId, RefChange,
update_asset_storage_system, Asset, AssetLoader, AssetServer, AssetStage, Handle, HandleId,
RefChange,
};
use bevy_app::{prelude::Events, AppBuilder};
use bevy_ecs::{FromResources, IntoSystem, ResMut};
Expand Down Expand Up @@ -219,11 +220,11 @@ impl AddAsset for AppBuilder {

self.insert_resource(assets)
.add_system_to_stage(
super::stage::ASSET_EVENTS,
AssetStage::AssetEvents,
Assets::<T>::asset_event_system.system(),
)
.add_system_to_stage(
crate::stage::LOAD_ASSETS,
AssetStage::LoadAssets,
update_asset_storage_system::<T>.system(),
)
.register_type::<Handle<T>>()
Expand Down
34 changes: 19 additions & 15 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ mod path;

pub use asset_server::*;
pub use assets::*;
use bevy_ecs::{IntoSystem, SystemStage};
use bevy_reflect::RegisterTypeBuilder;
use bevy_tasks::IoTaskPool;
pub use handle::*;
pub use info::*;
pub use io::*;
pub use loader::*;
pub use path::*;

/// The names of asset stages in an App Schedule
pub mod stage {
pub const LOAD_ASSETS: &str = "load_assets";
pub const ASSET_EVENTS: &str = "asset_events";
}

pub mod prelude {
pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped};
}

use bevy_app::{prelude::Plugin, AppBuilder};
use bevy_ecs::{IntoSystem, StageLabel, SystemStage};
use bevy_reflect::RegisterTypeBuilder;
use bevy_tasks::IoTaskPool;

/// The names of asset stages in an App Schedule
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
pub enum AssetStage {
LoadAssets,
AssetEvents,
}

/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are added as App Resources.
/// Examples of assets: textures, sounds, 3d models, maps, scenes
Expand Down Expand Up @@ -89,25 +90,28 @@ impl Plugin for AssetPlugin {
}

app.add_stage_before(
bevy_app::stage::PRE_UPDATE,
stage::LOAD_ASSETS,
bevy_app::CoreStage::PreUpdate,
AssetStage::LoadAssets,
SystemStage::parallel(),
)
.add_stage_after(
bevy_app::stage::POST_UPDATE,
stage::ASSET_EVENTS,
bevy_app::CoreStage::PostUpdate,
AssetStage::AssetEvents,
SystemStage::parallel(),
)
.register_type::<HandleId>()
.add_system_to_stage(
bevy_app::stage::PRE_UPDATE,
bevy_app::CoreStage::PreUpdate,
asset_server::free_unused_assets_system.system(),
);

#[cfg(all(
feature = "filesystem_watcher",
all(not(target_arch = "wasm32"), not(target_os = "android"))
))]
app.add_system_to_stage(stage::LOAD_ASSETS, io::filesystem_watcher_system.system());
app.add_system_to_stage(
AssetStage::LoadAssets,
io::filesystem_watcher_system.system(),
);
}
}
Loading