From 1ab4e52cda021062c8547a743492d132134f2e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 10 Nov 2021 03:02:44 +0100 Subject: [PATCH] can disable file system watching from bevy_asset --- Cargo.toml | 4 ++++ crates/bevy_asset/src/io/file_asset_io.rs | 19 ++++++++++++++----- crates/bevy_audio/Cargo.toml | 2 +- crates/bevy_core/Cargo.toml | 2 +- crates/bevy_gltf/Cargo.toml | 2 +- crates/bevy_internal/Cargo.toml | 5 ++++- crates/bevy_pbr/Cargo.toml | 2 +- crates/bevy_render/Cargo.toml | 2 +- crates/bevy_scene/Cargo.toml | 2 +- crates/bevy_sprite/Cargo.toml | 2 +- crates/bevy_text/Cargo.toml | 2 +- crates/bevy_ui/Cargo.toml | 2 +- crates/bevy_wgpu/Cargo.toml | 2 +- docs/cargo_features.md | 1 + 14 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 830f6131abd0de..6ffdf837ef21c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ default = [ "hdr", "mp3", "x11", + "filesystem_watcher" ] # Force dynamic linking, which improves iterative compile times @@ -68,6 +69,9 @@ mp3 = ["bevy_internal/mp3"] vorbis = ["bevy_internal/vorbis"] wav = ["bevy_internal/wav"] +# Enable watching file system for asset hot reload +filesystem_watcher = ["bevy_internal/filesystem_watcher"] + # WASM support for audio (Currently only works with flac, wav and vorbis. Not with mp3) wasm_audio = ["bevy_internal/wasm_audio"] diff --git a/crates/bevy_asset/src/io/file_asset_io.rs b/crates/bevy_asset/src/io/file_asset_io.rs index ee23a6c730c437..efebb81e49ff38 100644 --- a/crates/bevy_asset/src/io/file_asset_io.rs +++ b/crates/bevy_asset/src/io/file_asset_io.rs @@ -1,15 +1,23 @@ -use crate::{filesystem_watcher::FilesystemWatcher, AssetIo, AssetIoError, AssetServer}; +#[cfg(feature = "filesystem_watcher")] +use crate::{filesystem_watcher::FilesystemWatcher, AssetServer}; +use crate::{AssetIo, AssetIoError}; use anyhow::Result; +#[cfg(feature = "filesystem_watcher")] use bevy_ecs::system::Res; -use bevy_utils::{BoxedFuture, HashSet}; +use bevy_utils::BoxedFuture; +#[cfg(feature = "filesystem_watcher")] +use bevy_utils::HashSet; +#[cfg(feature = "filesystem_watcher")] use crossbeam_channel::TryRecvError; use fs::File; -use io::Read; +#[cfg(feature = "filesystem_watcher")] use parking_lot::RwLock; +#[cfg(feature = "filesystem_watcher")] +use std::sync::Arc; use std::{ - env, fs, io, + env, fs, + io::Read, path::{Path, PathBuf}, - sync::Arc, }; pub struct FileAssetIo { @@ -21,6 +29,7 @@ pub struct FileAssetIo { impl FileAssetIo { pub fn new>(path: P) -> Self { FileAssetIo { + #[cfg(feature = "filesystem_watcher")] filesystem_watcher: Default::default(), root_path: Self::get_root_path().join(path.as_ref()), } diff --git a/crates/bevy_audio/Cargo.toml b/crates/bevy_audio/Cargo.toml index 2e780270dbca0b..71c30db26f0fc1 100644 --- a/crates/bevy_audio/Cargo.toml +++ b/crates/bevy_audio/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] } bevy_utils = { path = "../bevy_utils", version = "0.5.0" } diff --git a/crates/bevy_core/Cargo.toml b/crates/bevy_core/Cargo.toml index 6579d619610ef3..c94dd5ffc8320d 100644 --- a/crates/bevy_core/Cargo.toml +++ b/crates/bevy_core/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy -bevy_app = { path = "../bevy_app", version = "0.5.0" } +bevy_app = { path = "../bevy_app", version = "0.5.0", features = ["bevy_reflect"] } bevy_derive = { path = "../bevy_derive", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0", features = ["bevy_reflect"] } bevy_math = { path = "../bevy_math", version = "0.5.0" } diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index 850c031633adaf..5aabd5b3ac7e33 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_pbr = { path = "../bevy_pbr", version = "0.5.0" } diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 3ae9121fb7715a..5deceb022120d2 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -32,6 +32,9 @@ wav = ["bevy_audio/wav"] # WASM support for audio wasm_audio = ["bevy_audio/wasm_audio"] +# Enable watching file system for asset hot reload +filesystem_watcher = ["bevy_asset/filesystem_watcher"] + serialize = ["bevy_input/serialize"] # Display server protocol support (X11 is enabled by default) @@ -47,7 +50,7 @@ bevy_ci_testing = ["bevy_app/bevy_ci_testing"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_derive = { path = "../bevy_derive", version = "0.5.0" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.5.0" } diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index b978fcf2fa4b61..a5d804bf7c2ba4 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_math = { path = "../bevy_math", version = "0.5.0" } diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 6dbad550a95fbc..67674585c30795 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_derive = { path = "../bevy_derive", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index 8b39b191a86e02..a2b5e9352f87a9 100644 --- a/crates/bevy_scene/Cargo.toml +++ b/crates/bevy_scene/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] } bevy_transform = { path = "../bevy_transform", version = "0.5.0" } diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index 4b1097c8ee1534..c3c92f6706dac9 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_log = { path = "../bevy_log", version = "0.5.0" } diff --git a/crates/bevy_text/Cargo.toml b/crates/bevy_text/Cargo.toml index 613e50f93be408..6647e45f68426d 100644 --- a/crates/bevy_text/Cargo.toml +++ b/crates/bevy_text/Cargo.toml @@ -14,7 +14,7 @@ subpixel_glyph_atlas = [] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_math = { path = "../bevy_math", version = "0.5.0" } diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index ab2f886e814e9e..204ea1d1b0d04c 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["bevy"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_input = { path = "../bevy_input", version = "0.5.0" } diff --git a/crates/bevy_wgpu/Cargo.toml b/crates/bevy_wgpu/Cargo.toml index ad9dc720190cfe..2c9fbd3de44b4b 100644 --- a/crates/bevy_wgpu/Cargo.toml +++ b/crates/bevy_wgpu/Cargo.toml @@ -15,7 +15,7 @@ trace = ["wgpu/trace"] [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.5.0" } -bevy_asset = { path = "../bevy_asset", version = "0.5.0" } +bevy_asset = { path = "../bevy_asset", version = "0.5.0", default-features = false } bevy_core = { path = "../bevy_core", version = "0.5.0" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } diff --git a/docs/cargo_features.md b/docs/cargo_features.md index 839515e17da376..0a681f7b4f67db 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -14,6 +14,7 @@ |hdr|[HDR](https://en.wikipedia.org/wiki/High_dynamic_range) support.| |mp3|MP3 audio format support.| |x11|Make GUI applications use X11 protocol. You could enable wayland feature to override this.| +|filesystem_watcher|Enable watching the file system for asset hot reload| ## Optional Features