This commit is contained in:
parent
df99ef3a3f
commit
4f6216635f
17 changed files with 110 additions and 100 deletions
|
@ -1,4 +1,2 @@
|
|||
mod app;
|
||||
pub mod plugin;
|
||||
|
||||
pub use app::App;
|
||||
pub use app::*;
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
use super::app::App;
|
||||
|
||||
pub trait Plugin {
|
||||
fn build(&self, app: &mut App);
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
pub mod app;
|
||||
pub mod camera;
|
||||
pub mod old_app;
|
||||
pub mod render;
|
||||
pub mod scene;
|
||||
pub mod window;
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
use bevy_ecs::world::World;
|
||||
|
||||
pub struct Scene {
|
||||
world: World,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
world: World::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn world(&self) -> &World {
|
||||
&self.world
|
||||
}
|
||||
|
||||
pub fn world_mut(&mut self) -> &mut World {
|
||||
&mut self.world
|
||||
}
|
||||
}
|
17
src/core/window/config.rs
Normal file
17
src/core/window/config.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use bevy_ecs::system::Resource;
|
||||
use winit::{dpi::PhysicalSize, window::WindowAttributes};
|
||||
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct WindowConfig {
|
||||
pub title: String,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
impl Into<WindowAttributes> for &WindowConfig {
|
||||
fn into(self) -> WindowAttributes {
|
||||
WindowAttributes::default()
|
||||
.with_title(self.title.clone())
|
||||
.with_inner_size(PhysicalSize::new(self.width as f64, self.height as f64))
|
||||
}
|
||||
}
|
|
@ -1,24 +1,27 @@
|
|||
pub mod window_handler;
|
||||
|
||||
use super::app::{App, plugin::Plugin};
|
||||
use window_handler::WindowHandler;
|
||||
use config::WindowConfig;
|
||||
use state::WindowState;
|
||||
use winit::event_loop::EventLoop;
|
||||
use winit::window::WindowAttributes;
|
||||
|
||||
pub struct WindowPlugin {
|
||||
window_attributes: WindowAttributes,
|
||||
event_loop: EventLoop<()>,
|
||||
use super::app::{App, AppExit};
|
||||
|
||||
pub mod config;
|
||||
pub mod state;
|
||||
|
||||
pub fn init(app: &mut App, window_config: WindowConfig) {
|
||||
let world = app.world_mut();
|
||||
world.insert_resource(window_config);
|
||||
|
||||
let mut event_loop_builder = EventLoop::with_user_event();
|
||||
let event_loop = event_loop_builder.build().unwrap();
|
||||
|
||||
app.set_runner(Box::new(move |app| runner(app, event_loop)));
|
||||
}
|
||||
|
||||
impl Plugin for WindowPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
let world = app.world_mut();
|
||||
world.insert_resource(WindowHandler::new(self.window_attributes.clone()));
|
||||
fn runner(app: App, event_loop: EventLoop<()>) -> AppExit {
|
||||
let mut window_state = WindowState::new(app);
|
||||
|
||||
let window_handler = world.get_resource_mut::<WindowHandler>().unwrap();
|
||||
|
||||
// app.set_runner(Box::new(move || {
|
||||
// self.event_loop.run_app(&mut window_handler);
|
||||
// }));
|
||||
match event_loop.run_app(&mut window_state) {
|
||||
Ok(_) => AppExit::Success,
|
||||
Err(e) => AppExit::Error(Box::new(e)),
|
||||
}
|
||||
}
|
||||
|
|
45
src/core/window/state.rs
Normal file
45
src/core/window/state.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use bevy_ecs::world::World;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::ActiveEventLoop,
|
||||
window::{Window, WindowId},
|
||||
};
|
||||
|
||||
use crate::core::app::App;
|
||||
|
||||
use super::config::WindowConfig;
|
||||
|
||||
pub struct WindowState {
|
||||
app: App,
|
||||
window: Option<Window>,
|
||||
}
|
||||
|
||||
impl WindowState {
|
||||
pub fn new(app: App) -> Self {
|
||||
Self { app, window: None }
|
||||
}
|
||||
|
||||
fn world(&self) -> &World {
|
||||
self.app.world()
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for WindowState {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window_config = self.world().get_resource::<WindowConfig>().unwrap();
|
||||
|
||||
let window = event_loop.create_window(window_config.into()).unwrap();
|
||||
self.window = Some(window);
|
||||
}
|
||||
|
||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
log::debug!("The close button was pressed; stopping");
|
||||
event_loop.exit();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
use bevy_ecs::system::Resource;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::ActiveEventLoop,
|
||||
window::{Window, WindowAttributes, WindowId},
|
||||
};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct WindowHandler {
|
||||
window_attributes: WindowAttributes,
|
||||
window: Option<Box<Window>>,
|
||||
}
|
||||
|
||||
impl WindowHandler {
|
||||
pub fn new(window_attributes: WindowAttributes) -> Self {
|
||||
Self {
|
||||
window_attributes,
|
||||
window: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ApplicationHandler for WindowHandler {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window = event_loop
|
||||
.create_window(self.window_attributes.clone())
|
||||
.unwrap();
|
||||
self.window = Some(Box::new(window));
|
||||
}
|
||||
|
||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
log::debug!("The close button was pressed; stopping");
|
||||
event_loop.exit();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +1,14 @@
|
|||
use crate::core::{
|
||||
app::App,
|
||||
window::{self, config::WindowConfig},
|
||||
};
|
||||
|
||||
pub fn init(app: &mut App) {
|
||||
let window_config = WindowConfig {
|
||||
title: "Rust ASH Test".to_string(),
|
||||
width: 800,
|
||||
height: 600,
|
||||
};
|
||||
|
||||
window::init(app, window_config);
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -3,16 +3,18 @@ use winit::event_loop::{ControlFlow, EventLoop};
|
|||
|
||||
pub mod core;
|
||||
pub mod game;
|
||||
pub mod vulkan;
|
||||
pub mod old_app;
|
||||
|
||||
fn main() -> Result<(), impl Error> {
|
||||
env_logger::init();
|
||||
|
||||
run_new_app()
|
||||
// run_new_app()
|
||||
run_old_app()
|
||||
}
|
||||
|
||||
fn run_new_app() -> Result<(), impl Error> {
|
||||
let app = core::app::App::default();
|
||||
let mut app = core::app::App::default();
|
||||
game::init(&mut app);
|
||||
app.run()
|
||||
}
|
||||
|
||||
|
@ -20,8 +22,8 @@ fn run_old_app() -> Result<(), impl Error> {
|
|||
let event_loop = EventLoop::new().unwrap();
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
|
||||
let vulkan_context = vulkan::vulkan_context::VulkanContext::from(&event_loop);
|
||||
let mut app = core::old_app::App::from(vulkan_context);
|
||||
let vulkan_context = old_app::vulkan_context::VulkanContext::from(&event_loop);
|
||||
let mut app = old_app::app::App::from(vulkan_context);
|
||||
|
||||
event_loop.run_app(&mut app)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::vulkan::scene::Scene;
|
||||
use crate::vulkan::vulkan_context::VulkanContext;
|
||||
use crate::vulkan::window_render_context::WindowRenderContext;
|
||||
use crate::old_app::scene::Scene;
|
||||
use crate::old_app::vulkan_context::VulkanContext;
|
||||
use crate::old_app::window_render_context::WindowRenderContext;
|
||||
use std::sync::Arc;
|
||||
use vulkano::command_buffer::{RenderingAttachmentInfo, RenderingInfo};
|
||||
use vulkano::render_pass::{AttachmentLoadOp, AttachmentStoreOp};
|
|
@ -1,5 +1,5 @@
|
|||
pub mod app;
|
||||
pub mod pipelines;
|
||||
pub mod scene;
|
||||
pub mod vulkan_context;
|
||||
pub mod window_render_context;
|
||||
|
||||
pub mod scene;
|
|
@ -1,4 +1,4 @@
|
|||
use crate::vulkan::pipelines::triangle_pipeline::shaders::vs;
|
||||
use crate::old_app::pipelines::triangle_pipeline::shaders::vs;
|
||||
use glam::{Mat3, Mat4, Vec3};
|
||||
use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
|
@ -10,7 +10,7 @@ use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter};
|
|||
use vulkano::pipeline::{GraphicsPipeline, Pipeline, PipelineBindPoint};
|
||||
|
||||
use crate::core::render::vertex::Vertex2D;
|
||||
use crate::vulkan::pipelines::triangle_pipeline::create_triangle_pipeline;
|
||||
use crate::old_app::pipelines::triangle_pipeline::create_triangle_pipeline;
|
||||
|
||||
use super::vulkan_context::VulkanContext;
|
||||
use super::window_render_context::WindowRenderContext;
|
Loading…
Add table
Reference in a new issue