Architecture for bevy_egui update for multi-window #340
Replies: 2 comments 8 replies
-
|
This is great Anders. I love the small discovery programming code project you've got. I'm curious what's in their schedule? How many systems are in there? If it's only a few, we can probably just call them ourselves. On Monday for the code that you have working here what I'd try is this: modify your a window_sys to accept an input identifying your context ( |
Beta Was this translation helpful? Give feedback.
-
|
I looked at the Egui example code a little more carefully. I wonder if we changed the argument from this function fn ui_second_window_system(
mut egui_user_textures: ResMut<EguiUserTextures>,
mut ui_state: Local<UiState>,
mut shared_ui_state: ResMut<SharedUiState>,
images: Res<Images>,
mut egui_ctx: Single<&mut EguiContext, Without<PrimaryEguiContext>>,
) {to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@shanecelis no need to look at this until next week, but I wanted to get it down while it's fresh.
Current situation
Root problem
The official way to have multiple windows with bevy_egui is by creating a separate
EguiMultiPassSchedulefor each window. See the example here.The problem with that approach for us is that we render our UI for all windows in a single system that loops through our windows, whereas that example uses separate systems for each window. A corollary is that the separate schedules are hard-coded, where we need to be able to spawn an unknown number of windows at runtime. I've opened an issue upstream asking what the recommended way to do this is.
I believe I have tortured the Rust type system into something that could work with our current architecture, but it feels extremely hacky. The code is here. I'm hoping this can be a starting point of coming up with something cleaner.
The main downside with my current approach is that you have to hard code an upper limit on the number of concurrent windows, with lots of duplicated code. Maybe we can get around it with generics or something, but the whole thing is just gross.
One potential alternative would be to change our architecture so each window runs in it's own system. I believe that would entail creating custom schedules dynamically at runtime and attaching instances of our window system to it. I haven't experimented much with this design.
Anyway, here's my code: https://github.com/anderspitman/bevy_egui_multi_window
Beta Was this translation helpful? Give feedback.
All reactions