initial commit
This commit is contained in:
commit
b7ac53ddca
24
Cargo.toml
Normal file
24
Cargo.toml
Normal file
|
@ -0,0 +1,24 @@
|
|||
[workspace]
|
||||
resolver = "2"
|
||||
|
||||
members = [
|
||||
"crates/renderer",
|
||||
"crates/window",
|
||||
"crates/game"
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
anyhow = "1.0.89"
|
||||
ash = "0.38.0"
|
||||
ash-window = "0.13.0"
|
||||
glam = "0.29.0"
|
||||
thiserror = "1.0.64"
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
vk-mem = "0.4.0"
|
||||
vk-sync = "0.1.6"
|
||||
winit = "0.30.5"
|
||||
|
||||
futures = "0.3"
|
||||
smol = "2.0"
|
||||
rayon = "1.10"
|
1
crates/game/.gitignore
vendored
Normal file
1
crates/game/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
10
crates/game/Cargo.toml
Normal file
10
crates/game/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "game"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
winit = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
renderer = { path = "../renderer" }
|
114
crates/game/src/main.rs
Normal file
114
crates/game/src/main.rs
Normal file
|
@ -0,0 +1,114 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use tracing::info;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
dpi::{LogicalSize, PhysicalSize},
|
||||
event_loop::EventLoop,
|
||||
raw_window_handle::HasDisplayHandle,
|
||||
window::{Window, WindowAttributes, WindowId},
|
||||
};
|
||||
|
||||
struct WindowState {
|
||||
last_resize_events: BTreeMap<WindowId, PhysicalSize<u32>>,
|
||||
window_attrs: WindowAttributes,
|
||||
window: Option<Window>,
|
||||
}
|
||||
|
||||
impl WindowState {
|
||||
fn new(window_title: String) -> WindowState {
|
||||
Self {
|
||||
window: None,
|
||||
last_resize_events: BTreeMap::new(),
|
||||
window_attrs: WindowAttributes::default()
|
||||
.with_title(window_title)
|
||||
.with_resizable(true)
|
||||
.with_inner_size(LogicalSize::new(800, 600)),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_final_resize(&mut self, window_id: WindowId, new_size: PhysicalSize<u32>) {
|
||||
_ = (window_id, new_size);
|
||||
info!("TODO: implement resize events");
|
||||
}
|
||||
|
||||
fn handle_draw_request(&mut self, window_id: WindowId) {
|
||||
_ = (window_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for WindowState {
|
||||
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||
tracing::debug!("winit::resumed");
|
||||
self.window = Some(event_loop.create_window(self.window_attrs.clone()).unwrap());
|
||||
tracing::info!(
|
||||
window = u64::from(self.window.as_ref().unwrap().id()),
|
||||
"created new window"
|
||||
);
|
||||
}
|
||||
|
||||
fn about_to_wait(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||
for (&window, &resize) in self.last_resize_events.clone().iter() {
|
||||
self.handle_final_resize(window, resize);
|
||||
}
|
||||
self.last_resize_events.clear();
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &winit::event_loop::ActiveEventLoop,
|
||||
window_id: winit::window::WindowId,
|
||||
event: winit::event::WindowEvent,
|
||||
) {
|
||||
if !matches!(event, winit::event::WindowEvent::Resized(_)) {
|
||||
if let Some(resize) = self.last_resize_events.remove(&window_id) {
|
||||
self.handle_final_resize(window_id, resize);
|
||||
}
|
||||
}
|
||||
match event {
|
||||
winit::event::WindowEvent::Resized(physical_size) => {
|
||||
_ = self.last_resize_events.insert(window_id, physical_size);
|
||||
}
|
||||
winit::event::WindowEvent::CloseRequested => {
|
||||
tracing::info!(window = u64::from(window_id), "window close requested");
|
||||
event_loop.exit();
|
||||
}
|
||||
winit::event::WindowEvent::KeyboardInput {
|
||||
device_id,
|
||||
event,
|
||||
is_synthetic,
|
||||
} => {
|
||||
_ = (device_id, event, is_synthetic);
|
||||
}
|
||||
winit::event::WindowEvent::CursorMoved {
|
||||
device_id,
|
||||
position,
|
||||
} => {
|
||||
_ = (device_id, position);
|
||||
}
|
||||
winit::event::WindowEvent::MouseInput {
|
||||
device_id,
|
||||
state,
|
||||
button,
|
||||
} => {
|
||||
_ = (device_id, state, button);
|
||||
}
|
||||
winit::event::WindowEvent::RedrawRequested => {
|
||||
self.handle_draw_request(window_id);
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
_ => {} // unhandled event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tracing_subscriber::fmt().init();
|
||||
let ev = EventLoop::new().unwrap();
|
||||
|
||||
let display = ev.owned_display_handle().display_handle();
|
||||
let mut game = WindowState::new("Vidya".to_owned());
|
||||
ev.run_app(&mut game).unwrap();
|
||||
}
|
1
crates/renderer/.gitignore
vendored
Normal file
1
crates/renderer/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
17
crates/renderer/Cargo.toml
Normal file
17
crates/renderer/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "renderer"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
dyn-clone = "1"
|
||||
anyhow = "1.0.89"
|
||||
ash = "0.38.0"
|
||||
ash-window = "0.13.0"
|
||||
glam = "0.29.0"
|
||||
thiserror = "1.0.64"
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
vk-mem = "0.4.0"
|
||||
vk-sync = "0.1.6"
|
||||
winit = "0.30.5"
|
1689
crates/renderer/src/lib.rs
Normal file
1689
crates/renderer/src/lib.rs
Normal file
File diff suppressed because it is too large
Load diff
1
crates/window/.gitignore
vendored
Normal file
1
crates/window/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
7
crates/window/Cargo.toml
Normal file
7
crates/window/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "window"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
winit = { workspace = true }
|
1
crates/window/src/lib.rs
Normal file
1
crates/window/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
|
@ -0,0 +1 @@
|
|||
nightly
|
Loading…
Reference in a new issue