Refactor + Begin add SceneSchedule
This commit is contained in:
parent
7b1373620c
commit
77affedf93
14 changed files with 286 additions and 188 deletions
|
@ -8,7 +8,7 @@ use egui_winit_vulkano::Gui;
|
|||
use vulkano_util::{renderer::VulkanoWindowRenderer, window::VulkanoWindows};
|
||||
use winit::{event_loop::EventLoopProxy, monitor::MonitorHandle, window::WindowId};
|
||||
|
||||
use crate::core::{input::InputManager, render::vulkan_context::VulkanContext, timer::Timer};
|
||||
use crate::core::{input::InputManager, render::vulkan_context::VulkanContext};
|
||||
|
||||
use super::user_event::UserEvent;
|
||||
|
||||
|
@ -22,7 +22,6 @@ pub struct WindowContext {
|
|||
// Données mutables partagées avec Arc<Mutex<>>
|
||||
pub vulkano_windows: Rc<RefCell<VulkanoWindows>>,
|
||||
pub input_manager: Arc<RwLock<InputManager>>,
|
||||
pub timer: Arc<RwLock<Timer>>,
|
||||
pub gui: Rc<RefCell<Gui>>,
|
||||
}
|
||||
|
||||
|
@ -31,7 +30,6 @@ impl WindowContext {
|
|||
vulkan_context: Arc<VulkanContext>,
|
||||
vulkano_windows: Rc<RefCell<VulkanoWindows>>,
|
||||
input_manager: Arc<RwLock<InputManager>>,
|
||||
timer: Arc<RwLock<Timer>>,
|
||||
gui: Rc<RefCell<Gui>>,
|
||||
event_loop_proxy: EventLoopProxy<UserEvent>,
|
||||
window_id: WindowId,
|
||||
|
@ -45,7 +43,6 @@ impl WindowContext {
|
|||
// Données mutables partagées
|
||||
vulkano_windows,
|
||||
input_manager,
|
||||
timer,
|
||||
gui,
|
||||
}
|
||||
}
|
||||
|
@ -85,11 +82,6 @@ impl WindowContext {
|
|||
})
|
||||
}
|
||||
|
||||
/// Récupère le delta time actuel depuis le timer
|
||||
pub fn get_delta_time(&self) -> f32 {
|
||||
self.with_timer(|timer| timer.delta_time())
|
||||
}
|
||||
|
||||
/// Récupère la taille de la fenêtre depuis le renderer
|
||||
pub fn get_window_size(&self) -> [f32; 2] {
|
||||
self.with_renderer(|renderer| renderer.window_size())
|
||||
|
@ -140,13 +132,4 @@ impl WindowContext {
|
|||
let mut gui = self.gui.borrow_mut();
|
||||
f(&mut gui)
|
||||
}
|
||||
|
||||
/// Méthode utilitaire pour accéder au timer de manière thread-safe
|
||||
pub fn with_timer<T, F>(&self, f: F) -> T
|
||||
where
|
||||
F: FnOnce(&Timer) -> T,
|
||||
{
|
||||
let timer = self.timer.read().expect("Failed to lock timer");
|
||||
f(&timer)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use std::sync::{Arc, RwLock};
|
|||
use super::render::vulkan_context::VulkanContext;
|
||||
use crate::core::input::InputManager;
|
||||
use crate::core::scene::manager::SceneManager;
|
||||
use crate::core::timer::Timer;
|
||||
use crate::game::scenes::main_scene::MainScene;
|
||||
use egui_winit_vulkano::{Gui, GuiConfig};
|
||||
use user_event::UserEvent;
|
||||
|
@ -33,7 +32,6 @@ pub struct App {
|
|||
gui: HashMap<WindowId, Rc<RefCell<Gui>>>,
|
||||
scene_manager: HashMap<WindowId, SceneManager>,
|
||||
input_manager: Arc<RwLock<InputManager>>,
|
||||
timer: Arc<RwLock<Timer>>,
|
||||
event_loop_proxy: EventLoopProxy<UserEvent>,
|
||||
|
||||
// Context d'application partagé par fenêtre - architecture unifiée
|
||||
|
@ -52,7 +50,6 @@ impl App {
|
|||
gui: HashMap::new(),
|
||||
input_manager: Arc::new(RwLock::new(input_manager)),
|
||||
scene_manager: HashMap::new(),
|
||||
timer: Arc::new(RwLock::new(Timer::new())),
|
||||
event_loop_proxy,
|
||||
app_contexts: HashMap::new(),
|
||||
}
|
||||
|
@ -104,7 +101,6 @@ impl ApplicationHandler<UserEvent> for App {
|
|||
self.vulkan_context.clone(),
|
||||
self.vulkano_windows.clone(),
|
||||
self.input_manager.clone(),
|
||||
self.timer.clone(),
|
||||
self.gui.get(&window_id).unwrap().clone(),
|
||||
self.event_loop_proxy.clone(),
|
||||
window_id,
|
||||
|
@ -158,11 +154,6 @@ impl ApplicationHandler<UserEvent> for App {
|
|||
.expect("Failed to lock input manager");
|
||||
input_manager.update();
|
||||
}
|
||||
{
|
||||
let _timer_span = tracing::debug_span!("timer_update").entered();
|
||||
let mut timer = self.timer.write().expect("Failed to lock timer");
|
||||
timer.update();
|
||||
}
|
||||
|
||||
// Créer ou mettre à jour le contexte d'application
|
||||
let window_context = self.app_contexts.get(&id).unwrap().clone();
|
||||
|
|
|
@ -2,4 +2,3 @@ pub mod app;
|
|||
pub mod input;
|
||||
pub mod render;
|
||||
pub mod scene;
|
||||
pub mod timer;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
mod buffer;
|
||||
mod command;
|
||||
mod descriptor_set;
|
||||
pub mod vulkan_resource;
|
||||
|
||||
pub mod camera;
|
||||
pub mod mvp;
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
use bevy_ecs::prelude::Resource;
|
||||
use bevy_ecs::world::World;
|
||||
use std::sync::Arc;
|
||||
use vulkano::{
|
||||
command_buffer::allocator::StandardCommandBufferAllocator,
|
||||
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
||||
device::{Device, Queue},
|
||||
instance::Instance,
|
||||
memory::allocator::StandardMemoryAllocator,
|
||||
};
|
||||
|
||||
/// Vulkan Instance resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanInstance(pub Arc<Instance>);
|
||||
|
||||
/// Vulkan Device resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanDevice(pub Arc<Device>);
|
||||
|
||||
/// Vulkan Graphics Queue resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanGraphicsQueue(pub Arc<Queue>);
|
||||
|
||||
/// Vulkan Compute Queue resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanComputeQueue(pub Arc<Queue>);
|
||||
|
||||
/// Vulkan Transfer Queue resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanTransferQueue(pub Option<Arc<Queue>>);
|
||||
|
||||
/// Vulkan Memory Allocator resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanMemoryAllocator(pub Arc<StandardMemoryAllocator>);
|
||||
|
||||
/// Vulkan Command Buffer Allocator resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanCommandBufferAllocator(pub Arc<StandardCommandBufferAllocator>);
|
||||
|
||||
/// Vulkan Descriptor Set Allocator resource
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanDescriptorSetAllocator(pub Arc<StandardDescriptorSetAllocator>);
|
||||
|
||||
/// Helper functions to access vulkan resources from the ECS world
|
||||
impl VulkanDevice {
|
||||
pub fn get_from_world(world: &World) -> &Arc<Device> {
|
||||
&world.resource::<VulkanDevice>().0
|
||||
}
|
||||
}
|
||||
|
||||
impl VulkanMemoryAllocator {
|
||||
pub fn get_from_world(world: &World) -> &Arc<StandardMemoryAllocator> {
|
||||
&world.resource::<VulkanMemoryAllocator>().0
|
||||
}
|
||||
}
|
||||
|
||||
impl VulkanCommandBufferAllocator {
|
||||
pub fn get_from_world(world: &World) -> &Arc<StandardCommandBufferAllocator> {
|
||||
&world.resource::<VulkanCommandBufferAllocator>().0
|
||||
}
|
||||
}
|
||||
|
||||
impl VulkanDescriptorSetAllocator {
|
||||
pub fn get_from_world(world: &World) -> &Arc<StandardDescriptorSetAllocator> {
|
||||
&world.resource::<VulkanDescriptorSetAllocator>().0
|
||||
}
|
||||
}
|
||||
|
||||
impl VulkanGraphicsQueue {
|
||||
pub fn get_from_world(world: &World) -> &Arc<Queue> {
|
||||
&world.resource::<VulkanGraphicsQueue>().0
|
||||
}
|
||||
}
|
||||
|
||||
impl VulkanTransferQueue {
|
||||
pub fn get_from_world(world: &World) -> Option<&Arc<Queue>> {
|
||||
world.resource::<VulkanTransferQueue>().0.as_ref()
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
pub mod meshes;
|
||||
pub mod pipeline;
|
||||
pub mod texture;
|
||||
pub mod timer;
|
||||
pub mod vulkan;
|
||||
|
|
145
src/core/render/resources/vulkan.rs
Normal file
145
src/core/render/resources/vulkan.rs
Normal file
|
@ -0,0 +1,145 @@
|
|||
use bevy_ecs::prelude::Resource;
|
||||
use std::{ops::Deref, sync::Arc};
|
||||
use vulkano::{
|
||||
command_buffer::allocator::StandardCommandBufferAllocator,
|
||||
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
||||
device::{Device, Queue},
|
||||
instance::Instance,
|
||||
memory::allocator::StandardMemoryAllocator,
|
||||
};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanInstance(Arc<Instance>);
|
||||
|
||||
impl From<&Arc<Instance>> for VulkanInstance {
|
||||
fn from(instance: &Arc<Instance>) -> Self {
|
||||
Self(instance.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanInstance {
|
||||
type Target = Arc<Instance>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanDevice(Arc<Device>);
|
||||
|
||||
impl From<&Arc<Device>> for VulkanDevice {
|
||||
fn from(device: &Arc<Device>) -> Self {
|
||||
Self(device.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanDevice {
|
||||
type Target = Arc<Device>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanGraphicsQueue(Arc<Queue>);
|
||||
|
||||
impl From<&Arc<Queue>> for VulkanGraphicsQueue {
|
||||
fn from(queue: &Arc<Queue>) -> Self {
|
||||
Self(queue.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanGraphicsQueue {
|
||||
type Target = Arc<Queue>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanComputeQueue(Arc<Queue>);
|
||||
|
||||
impl From<&Arc<Queue>> for VulkanComputeQueue {
|
||||
fn from(queue: &Arc<Queue>) -> Self {
|
||||
Self(queue.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanComputeQueue {
|
||||
type Target = Arc<Queue>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanTransferQueue(Option<Arc<Queue>>);
|
||||
|
||||
impl From<Option<&Arc<Queue>>> for VulkanTransferQueue {
|
||||
fn from(queue: Option<&Arc<Queue>>) -> Self {
|
||||
Self(queue.cloned())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanTransferQueue {
|
||||
type Target = Option<Arc<Queue>>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanMemoryAllocator(Arc<StandardMemoryAllocator>);
|
||||
|
||||
impl From<&Arc<StandardMemoryAllocator>> for VulkanMemoryAllocator {
|
||||
fn from(allocator: &Arc<StandardMemoryAllocator>) -> Self {
|
||||
Self(allocator.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanMemoryAllocator {
|
||||
type Target = Arc<StandardMemoryAllocator>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanCommandBufferAllocator(Arc<StandardCommandBufferAllocator>);
|
||||
|
||||
impl From<&Arc<StandardCommandBufferAllocator>> for VulkanCommandBufferAllocator {
|
||||
fn from(allocator: &Arc<StandardCommandBufferAllocator>) -> Self {
|
||||
Self(allocator.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanCommandBufferAllocator {
|
||||
type Target = Arc<StandardCommandBufferAllocator>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct VulkanDescriptorSetAllocator(Arc<StandardDescriptorSetAllocator>);
|
||||
|
||||
impl From<&Arc<StandardDescriptorSetAllocator>> for VulkanDescriptorSetAllocator {
|
||||
fn from(allocator: &Arc<StandardDescriptorSetAllocator>) -> Self {
|
||||
Self(allocator.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for VulkanDescriptorSetAllocator {
|
||||
type Target = Arc<StandardDescriptorSetAllocator>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
81
src/core/scene/extract.rs
Normal file
81
src/core/scene/extract.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
use bevy_ecs::world::World;
|
||||
|
||||
use crate::core::{
|
||||
app::{DEPTH_IMAGE_ID, context::WindowContext},
|
||||
render::{
|
||||
resources::vulkan::{
|
||||
VulkanCommandBufferAllocator, VulkanComputeQueue, VulkanDescriptorSetAllocator,
|
||||
VulkanDevice, VulkanGraphicsQueue, VulkanInstance, VulkanMemoryAllocator,
|
||||
VulkanTransferQueue,
|
||||
},
|
||||
resources::{pipeline::PipelineLoader, texture::TextureLoader},
|
||||
vulkan_context::VulkanContext,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn extract_vulkan_ressources(world: &mut World, vulkan_context: &VulkanContext) {
|
||||
let vulkano_context = vulkan_context.vulkano_context();
|
||||
|
||||
let vulkan_instance = vulkano_context.instance();
|
||||
let vulkan_device = vulkano_context.device();
|
||||
let vulkan_graphics_queue = vulkano_context.graphics_queue();
|
||||
let vulkan_compute_queue = vulkano_context.compute_queue();
|
||||
let vulkan_transfer_queue = vulkano_context.transfer_queue();
|
||||
let vulkan_memory_allocator = vulkano_context.memory_allocator();
|
||||
let vulkan_command_buffer_allocator = vulkan_context.command_buffer_allocator();
|
||||
let vulkan_descriptor_set_allocator = vulkan_context.descriptor_set_allocator();
|
||||
|
||||
world.insert_resource(VulkanInstance::from(vulkan_instance));
|
||||
world.insert_resource(VulkanDevice::from(vulkan_device));
|
||||
world.insert_resource(VulkanGraphicsQueue::from(vulkan_graphics_queue));
|
||||
world.insert_resource(VulkanComputeQueue::from(vulkan_compute_queue));
|
||||
world.insert_resource(VulkanTransferQueue::from(vulkan_transfer_queue));
|
||||
world.insert_resource(VulkanMemoryAllocator::from(vulkan_memory_allocator));
|
||||
world.insert_resource(VulkanCommandBufferAllocator::from(
|
||||
vulkan_command_buffer_allocator,
|
||||
));
|
||||
world.insert_resource(VulkanDescriptorSetAllocator::from(
|
||||
vulkan_descriptor_set_allocator,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn extract_texture_loader(world: &mut World, vulkan_context: &VulkanContext) {
|
||||
let vulkano_context = vulkan_context.vulkano_context();
|
||||
|
||||
let vulkan_device = vulkano_context.device();
|
||||
let vulkan_command_buffer_allocator = vulkan_context.command_buffer_allocator();
|
||||
let vulkan_memory_allocator = vulkano_context.memory_allocator();
|
||||
let vulkan_graphics_queue = vulkano_context.graphics_queue();
|
||||
let vulkan_transfer_queue = vulkano_context.transfer_queue();
|
||||
|
||||
let texture_loader = TextureLoader::new(
|
||||
vulkan_device.clone(),
|
||||
vulkan_command_buffer_allocator.clone(),
|
||||
vulkan_memory_allocator.clone(),
|
||||
TextureLoader::select_best_suitable_queue(vulkan_graphics_queue, vulkan_transfer_queue),
|
||||
);
|
||||
|
||||
world.insert_resource(texture_loader);
|
||||
}
|
||||
|
||||
pub fn extract_pipeline_loader(world: &mut World, window_context: &mut WindowContext) {
|
||||
let vulkan_device = window_context
|
||||
.vulkan_context()
|
||||
.vulkano_context()
|
||||
.device()
|
||||
.clone();
|
||||
|
||||
let depth_image_view = window_context
|
||||
.with_renderer_mut(|renderer| renderer.get_additional_image_view(DEPTH_IMAGE_ID).clone());
|
||||
|
||||
let swapchain_image_view =
|
||||
window_context.with_renderer(|renderer| renderer.swapchain_image_view().clone());
|
||||
|
||||
let pipeline_loader = PipelineLoader::new(
|
||||
vulkan_device.clone(),
|
||||
swapchain_image_view.format(),
|
||||
depth_image_view.format(),
|
||||
);
|
||||
|
||||
world.insert_resource(pipeline_loader);
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
use std::error::Error;
|
||||
|
||||
use crate::core::app::DEPTH_IMAGE_ID;
|
||||
use crate::core::app::context::WindowContext;
|
||||
use crate::core::input::InputManagerResource;
|
||||
use crate::core::render::primitives::vulkan_resource::{
|
||||
VulkanCommandBufferAllocator, VulkanComputeQueue, VulkanDescriptorSetAllocator, VulkanDevice,
|
||||
VulkanGraphicsQueue, VulkanInstance, VulkanMemoryAllocator, VulkanTransferQueue,
|
||||
};
|
||||
use crate::core::render::resources::pipeline::PipelineLoader;
|
||||
use crate::core::render::resources::texture::TextureLoader;
|
||||
use crate::core::scene::AsScene;
|
||||
use crate::core::scene::extract::{
|
||||
extract_pipeline_loader, extract_texture_loader, extract_vulkan_ressources,
|
||||
};
|
||||
use bevy_ecs::world::World;
|
||||
|
||||
use super::Scene;
|
||||
|
@ -31,52 +27,9 @@ impl SceneManager {
|
|||
fn create_world_with_resources(window_context: &mut WindowContext) -> World {
|
||||
let mut world = World::new();
|
||||
|
||||
let depth_image_view = window_context.with_renderer_mut(|renderer| {
|
||||
renderer.get_additional_image_view(DEPTH_IMAGE_ID).clone()
|
||||
});
|
||||
|
||||
let swapchain_image_view =
|
||||
window_context.with_renderer(|renderer| renderer.swapchain_image_view().clone());
|
||||
|
||||
let vulkan_context = window_context.vulkan_context();
|
||||
let vulkano_context = vulkan_context.vulkano_context();
|
||||
|
||||
let vulkan_instance = vulkano_context.instance();
|
||||
let vulkan_device = vulkano_context.device();
|
||||
let vulkan_graphics_queue = vulkano_context.graphics_queue();
|
||||
let vulkan_compute_queue = vulkano_context.compute_queue();
|
||||
let vulkan_transfer_queue = vulkano_context.transfer_queue();
|
||||
let vulkan_memory_allocator = vulkano_context.memory_allocator();
|
||||
let vulkan_command_buffer_allocator = vulkan_context.command_buffer_allocator();
|
||||
let vulkan_descriptor_set_allocator = vulkan_context.descriptor_set_allocator();
|
||||
|
||||
let texture_loader = TextureLoader::new(
|
||||
vulkan_device.clone(),
|
||||
vulkan_command_buffer_allocator.clone(),
|
||||
vulkan_memory_allocator.clone(),
|
||||
TextureLoader::select_best_suitable_queue(vulkan_graphics_queue, vulkan_transfer_queue),
|
||||
);
|
||||
|
||||
let pipeline_loader = PipelineLoader::new(
|
||||
vulkan_device.clone(),
|
||||
swapchain_image_view.format(),
|
||||
depth_image_view.format(),
|
||||
);
|
||||
|
||||
world.insert_resource(VulkanInstance(vulkan_instance.clone()));
|
||||
world.insert_resource(VulkanDevice(vulkan_device.clone()));
|
||||
world.insert_resource(VulkanGraphicsQueue(vulkan_graphics_queue.clone()));
|
||||
world.insert_resource(VulkanComputeQueue(vulkan_compute_queue.clone()));
|
||||
world.insert_resource(VulkanTransferQueue(vulkan_transfer_queue.cloned()));
|
||||
world.insert_resource(VulkanMemoryAllocator(vulkan_memory_allocator.clone()));
|
||||
world.insert_resource(VulkanCommandBufferAllocator(
|
||||
vulkan_command_buffer_allocator.clone(),
|
||||
));
|
||||
world.insert_resource(VulkanDescriptorSetAllocator(
|
||||
vulkan_descriptor_set_allocator.clone(),
|
||||
));
|
||||
world.insert_resource(texture_loader);
|
||||
world.insert_resource(pipeline_loader);
|
||||
extract_vulkan_ressources(&mut world, window_context.vulkan_context());
|
||||
extract_texture_loader(&mut world, window_context.vulkan_context());
|
||||
extract_pipeline_loader(&mut world, window_context);
|
||||
world.insert_resource(InputManagerResource(window_context.input_manager.clone()));
|
||||
|
||||
world
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
use std::error::Error;
|
||||
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_ecs::{schedule::Schedule, world::World};
|
||||
use vulkano::sync::GpuFuture;
|
||||
|
||||
use crate::core::app::context::WindowContext;
|
||||
use crate::core::{app::context::WindowContext, scene::schedule::SceneScedule};
|
||||
|
||||
mod extract;
|
||||
pub mod manager;
|
||||
pub mod schedule;
|
||||
|
||||
/// Structure Scene qui contient le world et l'implémentation AsScene
|
||||
pub struct Scene {
|
||||
pub world: World,
|
||||
pub loop_schedule: Schedule,
|
||||
pub implementation: Box<dyn AsScene>,
|
||||
}
|
||||
|
||||
|
@ -17,6 +20,7 @@ impl Scene {
|
|||
pub fn new(implementation: Box<dyn AsScene>, world: World) -> Self {
|
||||
Self {
|
||||
world,
|
||||
loop_schedule: SceneScedule::base_schedule(),
|
||||
implementation,
|
||||
}
|
||||
}
|
||||
|
|
24
src/core/scene/schedule.rs
Normal file
24
src/core/scene/schedule.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use bevy_ecs::schedule::{IntoScheduleConfigs, Schedule, ScheduleLabel, SystemSet};
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
||||
pub enum SceneSystems {
|
||||
ExtractViews,
|
||||
Update,
|
||||
Render,
|
||||
Present,
|
||||
}
|
||||
|
||||
#[derive(ScheduleLabel, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct SceneScedule;
|
||||
|
||||
impl SceneScedule {
|
||||
pub fn base_schedule() -> Schedule {
|
||||
use SceneSystems::*;
|
||||
|
||||
let mut schedule = Schedule::new(Self);
|
||||
|
||||
schedule.configure_sets((ExtractViews, Update, Render, Present).chain());
|
||||
|
||||
schedule
|
||||
}
|
||||
}
|
|
@ -9,17 +9,17 @@ use crate::core::input::InputManagerResource;
|
|||
use crate::core::render::primitives::camera::{Camera3D, Camera3DTransform};
|
||||
use crate::core::render::primitives::transform::Transform;
|
||||
use crate::core::render::primitives::velocity::Velocity;
|
||||
use crate::core::render::primitives::vulkan_resource::{
|
||||
VulkanCommandBufferAllocator, VulkanDescriptorSetAllocator, VulkanGraphicsQueue,
|
||||
VulkanMemoryAllocator,
|
||||
};
|
||||
use crate::core::render::primitives::{AsDescriptorSet, AsRecordable};
|
||||
use crate::core::render::render_pass_manager::{RenderPassConfig, RenderPassManager};
|
||||
use crate::core::render::resources::meshes::{ObjMesh, SquareMesh};
|
||||
use crate::core::render::resources::pipeline::PipelineLoader;
|
||||
use crate::core::render::resources::texture::{TextureLoadInfo, TextureLoader, TextureSourceKind};
|
||||
use crate::core::render::resources::timer::Timer;
|
||||
use crate::core::render::resources::vulkan::{
|
||||
VulkanCommandBufferAllocator, VulkanDescriptorSetAllocator, VulkanGraphicsQueue,
|
||||
VulkanMemoryAllocator,
|
||||
};
|
||||
use crate::core::scene::AsScene;
|
||||
use crate::core::timer::Timer;
|
||||
use crate::game::assets::pipelines::simple::SimplePipeline;
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_ecs::schedule::Schedule;
|
||||
|
@ -102,11 +102,11 @@ impl AsScene for MainScene {
|
|||
);
|
||||
texture_loader.load_pending_textures()?;
|
||||
|
||||
let square = SquareMesh::new(VulkanMemoryAllocator::get_from_world(world))?;
|
||||
let square = SquareMesh::new(world.resource::<VulkanMemoryAllocator>())?;
|
||||
|
||||
let obj = {
|
||||
let obj = ObjMesh::new(
|
||||
VulkanMemoryAllocator::get_from_world(world),
|
||||
world.resource::<VulkanMemoryAllocator>(),
|
||||
"res/objects/cube.obj",
|
||||
)?;
|
||||
obj.into_iter().next().unwrap()
|
||||
|
@ -203,8 +203,8 @@ impl AsScene for MainScene {
|
|||
let state = self.state.as_mut().ok_or("State not loaded")?;
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::primary(
|
||||
VulkanCommandBufferAllocator::get_from_world(world).clone(),
|
||||
VulkanGraphicsQueue::get_from_world(world).queue_family_index(),
|
||||
(*world.resource::<VulkanCommandBufferAllocator>()).clone(),
|
||||
world.resource::<VulkanGraphicsQueue>().queue_family_index(),
|
||||
CommandBufferUsage::OneTimeSubmit,
|
||||
)?;
|
||||
|
||||
|
@ -234,7 +234,7 @@ impl AsScene for MainScene {
|
|||
Arc::new(
|
||||
result
|
||||
.0
|
||||
.create_buffer(result.1, VulkanMemoryAllocator::get_from_world(world))?,
|
||||
.create_buffer(result.1, world.resource::<VulkanMemoryAllocator>())?,
|
||||
)
|
||||
};
|
||||
let square_transforms = world
|
||||
|
@ -243,7 +243,7 @@ impl AsScene for MainScene {
|
|||
.cloned()
|
||||
.collect::<Vec<Transform>>();
|
||||
let square_transform_uniform = Transform::create_buffer(
|
||||
VulkanMemoryAllocator::get_from_world(world),
|
||||
world.resource::<VulkanMemoryAllocator>(),
|
||||
&square_transforms,
|
||||
)?;
|
||||
let cube_transforms = world
|
||||
|
@ -251,10 +251,8 @@ impl AsScene for MainScene {
|
|||
.iter(&world)
|
||||
.cloned()
|
||||
.collect::<Vec<Transform>>();
|
||||
let cube_transform_uniform = Transform::create_buffer(
|
||||
VulkanMemoryAllocator::get_from_world(world),
|
||||
&cube_transforms,
|
||||
)?;
|
||||
let cube_transform_uniform =
|
||||
Transform::create_buffer(world.resource::<VulkanMemoryAllocator>(), &cube_transforms)?;
|
||||
|
||||
let texture_loader = world.resource::<TextureLoader>();
|
||||
let pipeline_loader = world.resource::<PipelineLoader>();
|
||||
|
@ -262,7 +260,7 @@ impl AsScene for MainScene {
|
|||
pipeline_loader.with_pipeline::<SimplePipeline, _>(|pipeline| {
|
||||
SimplePipeline::record_commands(
|
||||
&mut builder,
|
||||
&VulkanDescriptorSetAllocator::get_from_world(world),
|
||||
world.resource::<VulkanDescriptorSetAllocator>(),
|
||||
pipeline,
|
||||
&state.square,
|
||||
&square_transform_uniform,
|
||||
|
@ -274,7 +272,7 @@ impl AsScene for MainScene {
|
|||
|
||||
SimplePipeline::record_commands(
|
||||
&mut builder,
|
||||
&VulkanDescriptorSetAllocator::get_from_world(world),
|
||||
world.resource::<VulkanDescriptorSetAllocator>(),
|
||||
pipeline,
|
||||
&state.obj,
|
||||
&cube_transform_uniform,
|
||||
|
@ -292,7 +290,7 @@ impl AsScene for MainScene {
|
|||
let command_buffer = builder.build()?;
|
||||
|
||||
let render_future = before_future.then_execute(
|
||||
VulkanGraphicsQueue::get_from_world(world).clone(),
|
||||
(*world.resource::<VulkanGraphicsQueue>()).clone(),
|
||||
command_buffer,
|
||||
)?;
|
||||
|
||||
|
@ -303,7 +301,7 @@ impl AsScene for MainScene {
|
|||
format!("{:#?}", input_manager)
|
||||
};
|
||||
let event_loop_proxy = window_context.event_loop_proxy.clone();
|
||||
let delta_time = window_context.get_delta_time();
|
||||
let delta_time = world.resource::<Timer>().delta_time();
|
||||
let window_id = window_context.window_id;
|
||||
let window_size = window_context.get_window_size();
|
||||
let camera_transform = world
|
||||
|
|
|
@ -3,10 +3,8 @@ use std::error::Error;
|
|||
use crate::core::app::DEPTH_IMAGE_ID;
|
||||
use crate::core::app::context::WindowContext;
|
||||
use crate::core::app::user_event::UserEvent;
|
||||
use crate::core::render::primitives::vulkan_resource::{
|
||||
VulkanCommandBufferAllocator, VulkanGraphicsQueue,
|
||||
};
|
||||
use crate::core::render::render_pass_manager::{RenderPassConfig, RenderPassManager};
|
||||
use crate::core::render::resources::vulkan::{VulkanCommandBufferAllocator, VulkanGraphicsQueue};
|
||||
use crate::core::scene::AsScene;
|
||||
use bevy_ecs::world::World;
|
||||
use egui_winit_vulkano::egui;
|
||||
|
@ -64,8 +62,8 @@ impl AsScene for SettingsScene {
|
|||
let state = self.state.as_ref().ok_or("State not found")?;
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::primary(
|
||||
VulkanCommandBufferAllocator::get_from_world(world).clone(),
|
||||
VulkanGraphicsQueue::get_from_world(world).queue_family_index(),
|
||||
(*world.resource::<VulkanCommandBufferAllocator>()).clone(),
|
||||
world.resource::<VulkanGraphicsQueue>().queue_family_index(),
|
||||
CommandBufferUsage::OneTimeSubmit,
|
||||
)?;
|
||||
|
||||
|
@ -93,7 +91,7 @@ impl AsScene for SettingsScene {
|
|||
let command_buffer = builder.build()?;
|
||||
|
||||
let render_future = before_future.then_execute(
|
||||
VulkanGraphicsQueue::get_from_world(world).clone(),
|
||||
(*world.resource::<VulkanGraphicsQueue>()).clone(),
|
||||
command_buffer,
|
||||
)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue