From 2130de17feb98b1e6d3cd6169a66f3da9d3939a5 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 23 Oct 2022 20:21:48 +0200 Subject: [PATCH] Fix updating texture not working because of doubly-borrowed resource. Update dependencies --- .cargo/config.toml | 5 ++ Cargo.lock | 141 ++++++++++++++++++++++++++----------- Cargo.toml | 2 + src/gui/widgets/toolbar.rs | 139 +++++++++++++++++------------------- src/main.rs | 1 + 5 files changed, 171 insertions(+), 117 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..8bf89ab --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[profile.dev.package."*"] +opt-level = 3 + +[profile.release] +lto = "thin" diff --git a/Cargo.lock b/Cargo.lock index 4de28e9..b2ab6da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ab_glyph" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04a9283dace1c41c265496614998d5b9c4a97b3eb770e804f007c5144bf03f2b" +checksum = "4dcdbc68024b653943864d436fe8a24b028095bc1cf91a8926f8241e4aaffe59" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.65" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "approx" @@ -152,9 +152,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bevy" @@ -778,9 +778,9 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "bytemuck" @@ -916,9 +916,9 @@ dependencies = [ [[package]] name = "const_panic" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c0358e41e90e443c69b2b2811f6ec9892c228b93620634cf4344fe89967fa9f" +checksum = "9ed2b28323eee4fb66bb824401daa3e46bd445b9a9298a3d382b320710ba69dd" [[package]] name = "copyless" @@ -1239,15 +1239,15 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-lite" @@ -1275,9 +1275,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -1557,9 +1557,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.134" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" [[package]] name = "libloading" @@ -1661,7 +1661,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1885,9 +1885,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "owned_ttf_parser" -version = "0.15.2" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e6affeb1632d6ff6a23d2cd40ffed138e82f1532571a26f527c8a284bb2fbb" +checksum = "4665508572151759e8d60404e20dc096ef93a99801a05ac2ac6e43bf5b4ca187" dependencies = [ "ttf-parser", ] @@ -1916,7 +1916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.3", + "parking_lot_core 0.9.4", ] [[package]] @@ -1935,15 +1935,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2012,9 +2012,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -2169,18 +2169,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.145" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.145" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -2189,9 +2189,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "itoa", "ryu", @@ -2277,9 +2277,9 @@ checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2" [[package]] name = "syn" -version = "1.0.102" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -2421,9 +2421,9 @@ dependencies = [ [[package]] name = "ttf-parser" -version = "0.15.2" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd" +checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" [[package]] name = "typenum" @@ -2762,43 +2762,100 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winit" version = "0.26.1" diff --git a/Cargo.toml b/Cargo.toml index d4a72e7..5e370d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,8 @@ resolver = "2" release = { strip = "symbols", lto = "thin", opt-level = "z" } [features] +# bevy/trace_chrome for tracing by function +# https://github.com/bevyengine/bevy/blob/main/docs/profiling.md logging = ["planet/logging"] globe_view = ["planet/globe_view", "render"] render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render", "dep:fxhash", "dep:bevy_egui"] diff --git a/src/gui/widgets/toolbar.rs b/src/gui/widgets/toolbar.rs index 93eefc4..b84cce1 100644 --- a/src/gui/widgets/toolbar.rs +++ b/src/gui/widgets/toolbar.rs @@ -40,88 +40,77 @@ iterable_enum!(ToolbarButton { Contours, GlobeView, }); -fn update_textures(world: &mut World) { +fn update_textures(world_manager: &WorldManager, images: &mut Mut>) { debug!("refreshing world texture"); - world.resource_scope(|world, world_manager: Mut| { - let mut images = world.resource_mut::>(); - - let map_image_handle = images.get_handle( - world_manager - .map_image_handle_id - .expect("No map image handle"), - ); - let map_image = images - .get_mut(&map_image_handle) - .expect("Map image handle pointing to non-existing image"); - map_image.resize(Extent3d { - width: world_manager.world().width, - height: world_manager.world().height, - depth_or_array_layers: 1, - }); - map_image.data = world_manager.map_color_bytes(); + let map_image_handle = images.get_handle( + world_manager + .map_image_handle_id + .expect("No map image handle"), + ); + let map_image = images + .get_mut(&map_image_handle) + .expect("Map image handle pointing to non-existing image"); + map_image.resize(Extent3d { + width: world_manager.world().width, + height: world_manager.world().height, + depth_or_array_layers: 1, }); + map_image.data = world_manager.map_color_bytes(); } impl ToolbarButton { fn clicked(self, world: &mut World) { - match self { - ToolbarButton::GenerateWorld => { - world.resource_scope(|world, mut world_manager: Mut<'_, WorldManager>| { - match world_manager.new_world() { - Err(err) => { - eprintln!("Failed to generate world: {}", err); - }, - Ok(_) => { - update_textures(world); - }, - } - }) - }, - ToolbarButton::SaveWorld => { - if let Err(err) = world.resource::().save_world("planet.ron") { - eprintln!("Failed to save planet.ron: {}", err); - } - }, - ToolbarButton::LoadWorld => { - world.resource_scope(|world, mut images: Mut<'_, Assets>| { - if let Err(err) = world - .resource_mut::() - .load_world("planet.ron", &mut images) - { - eprintln!("Failed to save planet.ron: {}", err); + world.resource_scope(|world, mut world_manager: Mut<'_, WorldManager>| { + match self { + ToolbarButton::GenerateWorld => { + if let Err(err) = world_manager.new_world() { + eprintln!("Failed to generate world: {}", err); } else { - update_textures(world); + update_textures(&world_manager, &mut world.resource_mut::>()); } - }); - }, - ToolbarButton::Rainfall => { - world.resource_mut::().toggle_rainfall(); - update_textures(world); - }, - ToolbarButton::Temperature => { - world.resource_mut::().toggle_temperature(); - update_textures(world); - }, - ToolbarButton::PlanetView => { - world.resource_mut::().cycle_view(); - update_textures(world); - }, - ToolbarButton::Contours => { - world.resource_mut::().toggle_contours(); - update_textures(world); - }, - #[cfg(feature = "globe_view")] - ToolbarButton::GlobeView => { - let mut camera_3d = world - .query_filtered::<&mut Camera, (With, Without)>() - .single_mut(world); - camera_3d.is_active = !camera_3d.is_active; - let (mut camera_2d, mut pancam) = world - .query_filtered::<(&mut Camera, &mut Pan2d), (With, Without)>() - .single_mut(world); - camera_2d.is_active = !camera_2d.is_active; - pancam.enabled = camera_2d.is_active; - }, - }; + }, + ToolbarButton::SaveWorld => { + if let Err(err) = world_manager.save_world("planet.ron") { + eprintln!("Failed to save planet.ron: {}", err); + } + }, + ToolbarButton::LoadWorld => { + let mut images = world.resource_mut::>(); + if let Err(err) = world_manager.load_world("planet.ron", &mut images) { + eprintln!("Failed to load planet.ron: {}", err); + } else { + update_textures(&world_manager, &mut images); + } + }, + ToolbarButton::Rainfall => { + world_manager.toggle_rainfall(); + update_textures(&world_manager, &mut world.resource_mut::>()); + }, + ToolbarButton::Temperature => { + world_manager.toggle_temperature(); + update_textures(&world_manager, &mut world.resource_mut::>()); + }, + ToolbarButton::PlanetView => { + world_manager.cycle_view(); + update_textures(&world_manager, &mut world.resource_mut::>()); + }, + ToolbarButton::Contours => { + world_manager.toggle_contours(); + update_textures(&world_manager, &mut world.resource_mut::>()); + }, + #[cfg(feature = "globe_view")] + ToolbarButton::GlobeView => { + let mut camera_3d = world + .query_filtered::<&mut Camera, (With, Without)>() + .single_mut(world); + camera_3d.is_active = !camera_3d.is_active; + let (mut camera_2d, mut pancam) = world + .query_filtered::<(&mut Camera, &mut Pan2d), (With, Without)>() + .single_mut(world); + camera_2d.is_active = !camera_2d.is_active; + pancam.enabled = camera_2d.is_active; + }, + }; + }); } } diff --git a/src/main.rs b/src/main.rs index 25b8aaf..d02229b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,6 +240,7 @@ fn generate_graphics( } fn update_gui(world: &mut World) { + debug_assert!(world.contains_resource::()); world.resource_scope(|world, mut ctx: Mut<'_, EguiContext>| { let ctx = ctx.ctx_mut(); _ = bevy_egui::egui::Window::new("Info panel")