Fix and module update
This commit is contained in:
60
src/main.rs
60
src/main.rs
@@ -1,16 +1,14 @@
|
||||
use winit::{Event};
|
||||
use cgmath::{Matrix4, Rad, Vector3, Deg, Quaternion, Rotation3, One, Rotation};
|
||||
use cgmath::{Deg, Matrix4, One, Quaternion, Rad, Rotation, Rotation3, Vector3};
|
||||
use winit::event::Event;
|
||||
|
||||
mod vulkan;
|
||||
use crate::vulkan::{Game, LinePoint, GameObject, VulkanRenderer, RenderResult, MeshHandle, GameObjectHandle};
|
||||
use crate::config::LogConfig;
|
||||
use crate::input::InputState;
|
||||
use crate::vulkan::{Game, GameObject, GameObjectHandle, LinePoint, MeshHandle, VulkanRenderer};
|
||||
use crate::vulkan::vs::ty::UniformBufferObject;
|
||||
|
||||
mod vulkan;
|
||||
mod input;
|
||||
use crate::input::{InputState};
|
||||
|
||||
mod config;
|
||||
use crate::config::LogConfig;
|
||||
|
||||
mod mesh;
|
||||
|
||||
struct TestGame {
|
||||
@@ -23,24 +21,9 @@ struct TestGame {
|
||||
}
|
||||
|
||||
impl Game for TestGame {
|
||||
fn on_window_event(self: &mut Self, event: &Event) {
|
||||
fn on_window_event(self: &mut Self, event: &Event<()>) {
|
||||
self.input.on_window_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
impl TestGame {
|
||||
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
||||
let (meshes, textures) = mesh::load_mesh("models/iski51.gltf", self.log_config.mesh_load_info).unwrap();
|
||||
self.test_meshes = meshes.into_iter().map(|m| {
|
||||
let id = match m.texture_index {
|
||||
Some(tex_id) => tex_id + 1,
|
||||
None => 0,
|
||||
};
|
||||
(renderer.upload_mesh(m), id)
|
||||
}).collect();
|
||||
textures.iter().for_each(|tex| renderer.upload_texture(tex));
|
||||
println!("Game loaded!");
|
||||
}
|
||||
|
||||
fn update(self: &mut Self, renderer: &mut VulkanRenderer) -> UniformBufferObject {
|
||||
self.input.frame_start();
|
||||
@@ -96,6 +79,21 @@ impl TestGame {
|
||||
}
|
||||
}
|
||||
|
||||
impl TestGame {
|
||||
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
||||
let (meshes, textures) = mesh::load_mesh("models/box.gltf", self.log_config.mesh_load_info).unwrap();
|
||||
self.test_meshes = meshes.into_iter().map(|m| {
|
||||
let id = match m.texture_index {
|
||||
Some(tex_id) => tex_id + 1,
|
||||
None => 0,
|
||||
};
|
||||
(renderer.upload_mesh(m), id)
|
||||
}).collect();
|
||||
textures.iter().for_each(|tex| renderer.upload_texture(tex));
|
||||
println!("Game loaded!");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let log_config = LogConfig::from_file("config/log.toml");
|
||||
|
||||
@@ -109,7 +107,7 @@ fn main() {
|
||||
};
|
||||
|
||||
let line_count = 30;
|
||||
let mut renderer = VulkanRenderer::init(
|
||||
let (mut renderer, event_loop) = VulkanRenderer::init(
|
||||
(-line_count..=line_count)
|
||||
.flat_map(|it| vec![
|
||||
LinePoint { position: [it as f32, 0., -line_count as f32] },
|
||||
@@ -121,15 +119,5 @@ fn main() {
|
||||
);
|
||||
|
||||
game.game_start(&mut renderer);
|
||||
|
||||
let mut continue_rendering = true;
|
||||
let mut ubo = game.update(&mut renderer);
|
||||
|
||||
while continue_rendering {
|
||||
match renderer.render_loop(&mut game, ubo) {
|
||||
RenderResult::Ok => ubo = game.update(&mut renderer),
|
||||
RenderResult::Reload => println!("Render loop reloaded..."),
|
||||
RenderResult::Quit => continue_rendering = false,
|
||||
}
|
||||
}
|
||||
vulkan::start_event_loop(renderer, Box::new(game), event_loop);
|
||||
}
|
||||
Reference in New Issue
Block a user