Push break job work [not work]
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 7m55s

This commit is contained in:
Florian RICHER 2025-05-26 16:46:26 +02:00
parent e58c22b531
commit 5b74eef561
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
13 changed files with 118 additions and 18 deletions

4
src/core/mod.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod input;
pub mod render;
pub mod scene;
pub mod timer;

View file

@ -1,6 +1,9 @@
use std::collections::HashMap;
use crate::render::scene::Scene;
use crate::core::input::InputState;
use crate::core::scene::SceneManager;
use crate::core::timer::Timer;
use crate::game::main_scene::MainScene;
use egui_winit_vulkano::{Gui, GuiConfig, egui};
use vulkano::command_buffer::{
AutoCommandBufferBuilder, CommandBufferUsage, RenderingAttachmentInfo, RenderingInfo,
@ -16,16 +19,16 @@ use winit::event::{ElementState, WindowEvent};
use winit::event_loop::ActiveEventLoop;
use winit::window::WindowId;
use super::input::InputState;
use super::vulkan_context::VulkanContext;
pub struct App {
vulkan_context: VulkanContext,
vulkano_windows: VulkanoWindows,
gui: HashMap<WindowId, Gui>,
scene: Option<Scene>,
clear_color: [f32; 3],
input_state: InputState,
scene_manager: SceneManager,
timer: Timer,
}
impl From<VulkanoContext> for App {
@ -34,9 +37,10 @@ impl From<VulkanoContext> for App {
vulkan_context: VulkanContext::new(vulkano_context),
vulkano_windows: VulkanoWindows::default(),
gui: HashMap::new(),
scene: None,
clear_color: [0.0, 0.0, 0.0],
input_state: InputState::default(),
scene_manager: SceneManager::new(),
timer: Timer::new(),
}
}
}
@ -71,13 +75,8 @@ impl ApplicationHandler for App {
};
self.gui.insert(window_id, gui);
self.scene = Some(
Scene::load(
&self.vulkan_context,
self.vulkano_windows.get_primary_renderer_mut().unwrap(),
)
.unwrap(),
);
self.scene_manager
.load_scene(Box::new(MainScene::default()));
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {

View file

@ -1,6 +1,4 @@
pub mod app;
pub mod input;
pub mod pipelines;
pub mod scene;
pub mod vertex;
pub mod vulkan_context;

View file

@ -20,7 +20,7 @@ use vulkano::pipeline::{
};
use vulkano::shader::{EntryPoint, ShaderStages};
use crate::render::vertex::Vertex2D;
use crate::core::render::vertex::Vertex2D;
pub mod shaders {
pub mod vs {

29
src/core/scene.rs Normal file
View file

@ -0,0 +1,29 @@
use vulkano_util::renderer::VulkanoWindowRenderer;
use super::{input::InputState, render::vulkan_context::VulkanContext, timer::Timer};
pub trait Scene {
fn load(&mut self, app: &mut App);
fn update(&mut self, app: &mut App);
fn render(&self);
fn unload(&mut self);
}
pub struct SceneManager {
current_scene: Option<Box<dyn Scene>>,
}
impl SceneManager {
pub fn new() -> Self {
Self {
current_scene: None,
}
}
pub fn load_scene(&mut self, scene: Box<dyn Scene>) {
if let Some(current_scene) = self.current_scene.as_mut() {
current_scene.unload();
}
self.current_scene = Some(scene);
}
}

30
src/core/timer.rs Normal file
View file

@ -0,0 +1,30 @@
pub struct Timer {
start_time: std::time::Instant,
last_time: std::time::Instant,
current_time: std::time::Instant,
delta_time: f32,
}
impl Timer {
pub fn new() -> Self {
Self {
start_time: std::time::Instant::now(),
last_time: std::time::Instant::now(),
current_time: std::time::Instant::now(),
delta_time: 0.0,
}
}
pub fn update(&mut self) {
self.current_time = std::time::Instant::now();
self.delta_time = self
.current_time
.duration_since(self.last_time)
.as_secs_f32();
self.last_time = self.current_time;
}
pub fn get_delta_time(&self) -> f32 {
self.delta_time
}
}

View file

@ -1,3 +1,4 @@
use crate::core::scene::Scene;
use crate::render::pipelines::triangle_pipeline::shaders::vs;
use glam::{Mat3, Mat4, Vec3};
use std::error::Error;
@ -70,14 +71,50 @@ const VERTICES: [Vertex2D; 12] = [
},
];
pub struct Scene {
pub struct MainSceneState {
pipeline: Arc<GraphicsPipeline>,
vertex_buffer: Subbuffer<[Vertex2D]>,
rotation_start: Instant,
}
impl Scene {
#[derive(Default)]
pub struct MainScene {
state: Option<MainSceneState>,
}
impl Scene for MainScene {
fn load(&mut self, app: &mut App) {
let pipeline = create_triangle_pipeline(
app.vulkan_context.vulkano_context().device(),
app.vulkano_windows.swapchain_format(),
)?;
let vertex_buffer = Vertex2D::create_buffer(
Vec::from_iter(VERTICES),
vulkano_context.vulkano_context().memory_allocator(),
)?;
self.state = Some(MainSceneState {
pipeline,
vertex_buffer,
rotation_start: Instant::now(),
})
}
fn update(&mut self, app: &mut App) {
todo!()
}
fn render(&self) {
todo!()
}
fn unload(&mut self) {
todo!()
}
}
impl MainScene {
pub fn load(
vulkano_context: &VulkanContext,
vulkano_window_renderer: &VulkanoWindowRenderer,

1
src/game/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod main_scene;

View file

@ -2,7 +2,9 @@ use vulkano::device::{DeviceExtensions, DeviceFeatures};
use vulkano_util::context::{VulkanoConfig, VulkanoContext};
use winit::event_loop::{ControlFlow, EventLoop};
mod render;
mod core;
mod game;
fn main() {
env_logger::init();
@ -28,7 +30,7 @@ fn main() {
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(ControlFlow::Poll);
let mut app = render::app::App::from(vulkano_context);
let mut app = core::render::app::App::from(vulkano_context);
match event_loop.run_app(&mut app) {
Ok(_) => {}