Skip to content

Commit

Permalink
Remove [vent-common]
Browse files Browse the repository at this point in the history
Expand Project structure
  • Loading branch information
Snowiiii committed Jul 4, 2024
1 parent 6fca7af commit 1be5dad
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 116 deletions.
28 changes: 6 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions crates/vent-common/Cargo.toml

This file was deleted.

12 changes: 0 additions & 12 deletions crates/vent-common/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions crates/vent-common/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/vent-common/src/util/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/vent-editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
vent-runtime = { path = "../vent-runtime"}
vent-common = { path = "../vent-common"}

vent-rendering = { path = "../vent-rendering"}

Expand Down
42 changes: 36 additions & 6 deletions crates/vent-rendering/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct VulkanInstance {
pub in_flight_fences: Vec<vk::Fence>,
pub images_in_flight: Vec<vk::Fence>,

pub vsync: bool,

frame: usize,

#[cfg(debug_assertions)]
Expand All @@ -69,17 +71,27 @@ pub struct VulkanInstance {
}

impl VulkanInstance {
pub fn new(application_name: &str, window: &vent_window::Window) -> Self {
pub fn new(
application_name: &String,
application_version: u32,
vsync: bool,
window: &vent_window::Window,
) -> Self {
let entry = Entry::linked();

let engine_version: u32 = env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap();
let engine_version = vk::make_api_version(
0,
env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
);

let app_info = unsafe {
vk::ApplicationInfo::default()
.application_name(CStr::from_bytes_with_nul_unchecked(
application_name.as_bytes(),
))
.application_version(0) // TODO
.application_version(application_version) // TODO
.engine_name(CStr::from_bytes_with_nul_unchecked(b"Vent-Engine\0"))
.engine_version(engine_version)
.api_version(vk::API_VERSION_1_3)
Expand Down Expand Up @@ -162,6 +174,7 @@ impl VulkanInstance {
surface_format,
&surface_loader,
pdevice,
vsync,
surface,
(
window.width().try_into().unwrap(),
Expand Down Expand Up @@ -236,6 +249,7 @@ impl VulkanInstance {
image_available_semaphores,
render_finished_semaphores,
in_flight_fences,
vsync,
images_in_flight,
frame: 0,
}
Expand All @@ -261,7 +275,11 @@ impl VulkanInstance {
}
}

pub fn recreate_swap_chain(&mut self, new_size: (u32, u32)) {
pub fn recreate_swap_chain(&mut self, new_size: Option<(u32, u32)>) {
let new_size = new_size.unwrap_or((
self.surface_resolution.width,
self.surface_resolution.height,
));
unsafe {
self.device.device_wait_idle().unwrap();

Expand All @@ -270,6 +288,7 @@ impl VulkanInstance {
self.surface_format,
&self.surface_loader,
self.physical_device,
self.vsync,
self.surface,
new_size,
Some(self.swapchain),
Expand Down Expand Up @@ -515,6 +534,7 @@ impl VulkanInstance {
surface_format: vk::SurfaceFormatKHR,
surface_loader: &khr::surface::Instance,
pdevice: vk::PhysicalDevice,
vsync: bool,
surface: vk::SurfaceKHR,
size: (u32, u32),
old_swapchain: Option<vk::SwapchainKHR>,
Expand Down Expand Up @@ -556,10 +576,20 @@ impl VulkanInstance {
let present_modes =
unsafe { surface_loader.get_physical_device_surface_present_modes(pdevice, surface) }
.unwrap();

let wanted_mode = if vsync {
vk::PresentModeKHR::FIFO
} else {
vk::PresentModeKHR::IMMEDIATE
};

let present_mode = present_modes
.iter()
.find(|&mode| *mode == vk::PresentModeKHR::IMMEDIATE)
.unwrap_or(&vk::PresentModeKHR::FIFO);
.find(|&mode| *mode == wanted_mode)
.unwrap_or({
log::warn!("Swapchain: Wanted mode is not supported, Using FIFO");
&vk::PresentModeKHR::FIFO
});

let swapchain_create_info = vk::SwapchainCreateInfoKHR::default()
.surface(surface)
Expand Down
11 changes: 8 additions & 3 deletions crates/vent-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
vent-common = { path = "../vent-common"}
vent-rendering = { path = "../vent-rendering"}
vent-assets = { path = "../vent-assets" }
vent-ecs = { path = "../vent-ecs"}
vent-window = { path = "../vent-window"}
vent-logging = { path = "../vent-logging"}
vent-math = { path = "../vent-math"}

# Rendering
ash = { version= "0.38", default-features = false, features = ["linked"] }

glam = "0.28"

pollster = "0.3.0"
log = "0.4"

sysinfo = "0.30"
chrono = "0.4"

# serde
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

downcast-rs = "1.2.0"

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
24 changes: 15 additions & 9 deletions crates/vent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ use std::process::exit;

use crate::render::Dimension;

use project::{RenderSettings, VentApplicationProject};
use render::{camera::camera_controller3d::CameraController3D, DefaultRuntimeRenderer};
use vent_common::project::VentApplicationProject;

use vent_common::util::crash::init_panic_hook;
use util::{crash::init_panic_hook, version::Version};
use vent_logging::Logger;
use vent_window::{EventLoop, Window, WindowAttribs, WindowEvent};

pub mod project;
pub mod render;
pub mod util;

pub struct VentApplication {
project: VentApplicationProject,
Expand All @@ -22,7 +24,12 @@ impl VentApplication {

let project = VentApplicationProject {
name: "Placeholder".to_string(),
version: "1.0.0".to_string(),
version: Version::new(1, 0, 0),
window_settings: WindowAttribs::default().with_title("Placeholder".to_string()),
render_settings: RenderSettings {
dimension: Dimension::D3,
vsync: false,
},
};
let app = VentApplication::new(project);
app.start();
Expand All @@ -33,18 +40,17 @@ impl VentApplication {
}

pub fn start(self) {
let window_size = (800, 600);
let project = self.project;
let mut event_loop = EventLoop::new();
let attribs = WindowAttribs::default().with_title(self.project.name);
let vent_window = Window::new(attribs);
let app_window = Window::new(project.window_settings.clone());

// TODO
let mut renderer = DefaultRuntimeRenderer::new(Dimension::D3, &vent_window);
let mut renderer = DefaultRuntimeRenderer::new(&project, &app_window);

let mut controller = CameraController3D::new(1000.0, 10.0);
let mut delta_time = 0.0;

event_loop.add_window(vent_window);
event_loop.add_window(app_window);

event_loop.poll(move |event| {
match event {
Expand All @@ -66,7 +72,7 @@ impl VentApplication {
} => {
renderer.resize((new_width, new_height));
}
WindowEvent::Draw => delta_time = renderer.render(window_size), // Default,
WindowEvent::Draw => delta_time = renderer.render(), // Default,
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use vent_window::WindowAttribs;

use crate::{render::Dimension, util::version::Version};

/// Basic Project Information's
#[derive(Serialize, Deserialize)]
// Basic Project Information's
pub struct VentApplicationProject {
// Name of the Application
pub name: String,
pub version: String,
// Version of the Application
pub version: Version,
// Inital Window settings, can be changed later
pub window_settings: WindowAttribs,
// Inital Render settings, can be changed later
pub render_settings: RenderSettings,
}

#[derive(Serialize, Deserialize)]
pub struct RenderSettings {
// Inital vsync setting, can be changed later
pub dimension: Dimension,
pub vsync: bool,
}

impl VentApplicationProject {
Expand All @@ -17,7 +33,7 @@ impl VentApplicationProject {
.truncate(true)
.create(true)
.open(path_str)?;

log::debug!("Saving {}", path);
serde_json::to_writer(file, self)?;

Ok(())
Expand All @@ -26,6 +42,7 @@ impl VentApplicationProject {
// Serialize the project data from a .vent file
pub fn serialize(path: &str) -> Result<Self, std::io::Error> {
let path_str = format!("{}/project.vent", path);
log::debug!("Loading {}", path);
let file = File::open(path_str)?;

let project = serde_json::from_reader(file)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/vent-runtime/src/render/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Camera for Camera3D {
fn recreate_projection(&mut self, aspect_ratio: f32) {
self.ubo.projection =
Mat4::perspective_rh(self.fovy.to_radians(), aspect_ratio, self.znear, self.zfar);
// Flip the cameras prospective upside down as glam assumes that the renderer we are using renders top to bottom, vulkan is the opposite
// Flip the cameras prospective upside down
self.ubo.projection.y_axis.y *= -1.0;
}
}
Expand Down
Loading

0 comments on commit 1be5dad

Please sign in to comment.