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

Windows as Entities #1

Closed
wants to merge 32 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3e5ff59
Replacing `Window_id` with `Entity`
Weibye Jun 6, 2022
07da9f5
Adding `WindowCommandsExtensions` for `Commands`
Weibye Jun 6, 2022
0c11956
Exploding `Window` into multiple coponents
Weibye Jun 6, 2022
ee35b2a
Adding `WindowCommands` to replace methods previously existing on `Wi…
Weibye Jun 6, 2022
f9a4529
Adding new `ExitCondition`
Weibye Jun 6, 2022
0e0c43c
Updating bevy_window to follow new pattern more
Weibye Jun 6, 2022
9325098
Deleting `Windows` as this should now be replaced by a query
Weibye Jun 6, 2022
b1f57bb
Split `change_window` system into multiple system that handle `Window…
Weibye Jun 6, 2022
29453d7
Start reworking `winit_runner()`
Weibye Jun 6, 2022
b64d741
Add initial sketch of example
Weibye Jun 6, 2022
1e1599b
Adding notes
Weibye Jun 6, 2022
00cee99
Fully implement spawning of created window
Weibye Jun 6, 2022
7c4b815
Start updating `bevy_render` to new patterns
Weibye Jun 6, 2022
317fef3
More cleanup of winit main loop
Weibye Jun 9, 2022
28944d5
minor fix
Weibye Jun 9, 2022
1d95cdb
And more tweaks
Weibye Jun 10, 2022
8df34dc
continuing refactor of winit-loop
Weibye Jun 10, 2022
537e4b0
Finish setting up components for new windows
Weibye Jun 10, 2022
c97365a
cleanup
Weibye Jun 10, 2022
0e05569
Start attempting to get rendering to compile again
Weibye Jun 10, 2022
d852a55
Updating `bevy_text`
Weibye Jun 10, 2022
dc6875c
Fixing up `bevy_ui`
Weibye Jun 10, 2022
0696336
Cleanup
Weibye Jun 10, 2022
aca8773
Fixing up `bevy_ui`
Weibye Jun 10, 2022
f6f793a
fixing examples
Weibye Jun 10, 2022
c2b99cd
Fixing up more examples
Weibye Jun 12, 2022
98da3ce
Every finally compiles!
Weibye Jun 13, 2022
60e81be
Fixing runtime bugs
Weibye Jun 13, 2022
5099960
Wrangling with timing issues in render
Weibye Jun 13, 2022
6182f9f
Window setup operations need to happen during build-time
Weibye Jun 14, 2022
c409ceb
Further attempts at spawning components in build-time
Weibye Jun 26, 2022
542660a
Using system-state apply
Weibye Jun 26, 2022
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
Prev Previous commit
Next Next commit
Window setup operations need to happen during build-time
Weibye committed Jun 14, 2022
commit 6182f9fc5ee3af534e9ac007c5fa13014731cf7a
4 changes: 2 additions & 2 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ use bevy_ecs::{
use bevy_math::{Mat4, UVec2, Vec2, Vec3};
use bevy_reflect::prelude::*;
use bevy_transform::components::GlobalTransform;
use bevy_utils::{default, HashSet};
use bevy_utils::HashSet;
use bevy_window::{Window, WindowCreated, WindowResized, WindowResolution};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, ops::Range};
@@ -254,7 +254,7 @@ impl RenderTarget {

pub fn get_render_target_info(
&self,
windows: &Query<(&WindowResolution), With<Window>>, // TODO: Maybe this could just be a Vec?
windows: &Query<&WindowResolution, With<Window>>, // TODO: Maybe this could just be a Vec?
images: &Assets<Image>,
) -> Option<RenderTargetInfo> {
Some(match self {
37 changes: 28 additions & 9 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ pub mod prelude {
}

use bevy_app::prelude::*;
use bevy_ecs::{entity::Entity, event::Events, schedule::{SystemLabel, SystemStage}, system::{SystemState, Commands, ResMut}};
use bevy_ecs::{entity::Entity, event::Events, schedule::{SystemLabel, SystemStage}, system::{SystemState, Commands, ResMut, Command}};

pub struct WindowPlugin {
/// Whether to create a window when added.
@@ -99,18 +99,37 @@ impl Plugin for WindowPlugin {
bevy_utils::tracing::info!("Hello");

if self.add_primary_window {
// TODO: Creating window should be done through commands as entities instead of old way
// app.add_startup_system(create_primary_window);
// TODO: Creating primary window should ideally be done through commands instead of the old way
// however, commands aren't executed until the end of the "build-stage"
// which means the primary-window does not exist until just before startup-systems starts running (?)
// which means bevy_render does not have a window to use as attach to during plugin build.

// Wishlist item; for this to work:
// app.add_startup_system(create_primary_window);
// or this:
// app.add_build_system(create_primary_window)

// TODO: The unwrap_or_default is necessary for the user to setup ahead of time what the window should be
// if not we'll regress on this
let window_descriptor = app
.world
.get_resource::<WindowDescriptor>()
.map(|descriptor| (*descriptor).clone())
.unwrap_or_default();

let window_id = app.world.spawn().id();

let mut system_state: SystemState<(Commands, ResMut<PrimaryWindow>)> = SystemState::new(&mut app.world);
let (mut commands, mut primary_window) = system_state.get_mut(&mut app.world);
create_primary_window(commands, primary_window);
primary_window.window = Some(window_id);
// create_primary_window(commands, primary_window);


let command = CreateWindowCommand { entity: window_id, descriptor: window_descriptor };
// Apply the command directly on the world
// I wonder if this causes timing issue: this will trigger a CreateWindowCommand event, but will bevy_winit exist in time to listen to the event?
command.write(&mut app.world);

// let window_descriptor = app
// .world
// .get_resource::<WindowDescriptor>()
// .map(|descriptor| (*descriptor).clone())
// .unwrap_or_default();
// let mut create_window_event = app.world.resource_mut::<Events<CreateWindow>>();

// // TODO: Replace with commands
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ struct InputEvents<'w, 's> {
mouse_button_input: EventWriter<'w, 's, MouseButtonInput>,
mouse_wheel_input: EventWriter<'w, 's, MouseWheel>,
touch_input: EventWriter<'w, 's, TouchInput>,
mouse_motion: EventWriter<'w, 's, MouseMotion>,
// mouse_motion: EventWriter<'w, 's, MouseMotion>,
}

#[derive(SystemParam)]