refactor 3
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -2,7 +2,7 @@ use winit::{Event};
|
|||||||
use cgmath::{Matrix4, Rad, Vector3, Deg, Quaternion, Rotation3, One, Rotation, SquareMatrix};
|
use cgmath::{Matrix4, Rad, Vector3, Deg, Quaternion, Rotation3, One, Rotation, SquareMatrix};
|
||||||
|
|
||||||
mod vulkan;
|
mod vulkan;
|
||||||
use crate::vulkan::{GameData, Game, LinePoint, GameObject, VulkanRenderer, RenderLoopResult};
|
use crate::vulkan::{Game, LinePoint, GameObject, VulkanRenderer, RenderLoopResult};
|
||||||
|
|
||||||
mod input;
|
mod input;
|
||||||
use crate::input::{InputState};
|
use crate::input::{InputState};
|
||||||
@@ -19,12 +19,19 @@ struct TestGame<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Game for TestGame<'_> {
|
impl Game for TestGame<'_> {
|
||||||
fn game_start(self: &mut Self, _game_data: &mut GameData) {
|
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 player_mesh = renderer.upload_mesh(mesh::load_mesh("models/iski51.dae", true).into_iter().nth(0).unwrap());
|
||||||
println!("Game started.");
|
println!("Game started.");
|
||||||
// let player_mesh = init_data.upload_mesh(mesh::load_mesh("models/iski51.dae").into_iter().nth(0).unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(self: &mut Self, game_data: &mut GameData) {
|
fn update(self: &mut Self, renderer: &mut VulkanRenderer) {
|
||||||
|
let game_data = &mut renderer.game_data;
|
||||||
let new_time = game_data.start_time.elapsed().unwrap().as_millis() as f32 / 1000.0;
|
let new_time = game_data.start_time.elapsed().unwrap().as_millis() as f32 / 1000.0;
|
||||||
let frame_time = new_time - game_data.push_constants.time;
|
let frame_time = new_time - game_data.push_constants.time;
|
||||||
game_data.push_constants.time = new_time;
|
game_data.push_constants.time = new_time;
|
||||||
@@ -73,10 +80,6 @@ impl Game for TestGame<'_> {
|
|||||||
|
|
||||||
self.input.frame_end();
|
self.input.frame_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_window_event(self: &mut Self, event: &Event) {
|
|
||||||
self.input.on_window_event(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -99,11 +102,13 @@ fn main() {
|
|||||||
]).collect(),
|
]).collect(),
|
||||||
log_config.vulkan_validation_layers,
|
log_config.vulkan_validation_layers,
|
||||||
);
|
);
|
||||||
renderer.upload_mesh(mesh::load_mesh("models/cube.dae", true).into_iter().nth(0).unwrap());
|
|
||||||
|
game.game_start(&mut renderer);
|
||||||
|
|
||||||
let mut continue_rendering = true;
|
let mut continue_rendering = true;
|
||||||
|
|
||||||
while continue_rendering {
|
while continue_rendering {
|
||||||
|
game.update(&mut renderer);
|
||||||
match renderer.render_loop(&mut game) {
|
match renderer.render_loop(&mut game) {
|
||||||
RenderLoopResult::Ok => {},
|
RenderLoopResult::Ok => {},
|
||||||
RenderLoopResult::Quit => continue_rendering = false,
|
RenderLoopResult::Quit => continue_rendering = false,
|
||||||
|
|||||||
@@ -55,10 +55,6 @@ pub struct LinePoint {
|
|||||||
vulkano::impl_vertex!(LinePoint, position);
|
vulkano::impl_vertex!(LinePoint, position);
|
||||||
|
|
||||||
pub trait Game {
|
pub trait Game {
|
||||||
fn game_start(self: &mut Self, game_data: &mut GameData);
|
|
||||||
|
|
||||||
fn update(self: &mut Self, game_data: &mut GameData);
|
|
||||||
|
|
||||||
/// Returns true if event should be ignored by the vulkan handler
|
/// Returns true if event should be ignored by the vulkan handler
|
||||||
fn on_window_event(self: &mut Self, event: &Event);
|
fn on_window_event(self: &mut Self, event: &Event);
|
||||||
}
|
}
|
||||||
@@ -352,8 +348,6 @@ impl VulkanRenderer {
|
|||||||
Err(err) => panic!("{:?}", err)
|
Err(err) => panic!("{:?}", err)
|
||||||
};
|
};
|
||||||
|
|
||||||
game.update(&mut self.game_data);
|
|
||||||
|
|
||||||
let mut cbb = AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap()
|
let mut cbb = AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap()
|
||||||
// Before we can draw, we have to *enter a render pass*. There are two methods to do
|
// Before we can draw, we have to *enter a render pass*. There are two methods to do
|
||||||
// this: `draw_inline` and `draw_secondary`. The latter is a bit more advanced and is
|
// this: `draw_inline` and `draw_secondary`. The latter is a bit more advanced and is
|
||||||
|
|||||||
Reference in New Issue
Block a user