refactor 4
This commit is contained in:
@@ -69,6 +69,9 @@ pub struct GameObject {
|
||||
pub model_matrix: Matrix4<f32>,
|
||||
}
|
||||
|
||||
pub(crate) type GameObjectHandle = usize;
|
||||
pub(crate) type MeshHandle = usize;
|
||||
|
||||
pub struct GameData {
|
||||
pub start_time: SystemTime,
|
||||
pub line_vertices: Vec<LinePoint>,
|
||||
@@ -101,7 +104,8 @@ pub struct VulkanRenderer {
|
||||
|
||||
pub enum RenderLoopResult {
|
||||
Ok,
|
||||
Quit
|
||||
Reload,
|
||||
Quit,
|
||||
}
|
||||
|
||||
impl VulkanRenderer {
|
||||
@@ -303,15 +307,15 @@ impl VulkanRenderer {
|
||||
let dimensions: (u32, u32) = dimensions.to_physical(window.get_hidpi_factor()).into();
|
||||
[dimensions.0, dimensions.1]
|
||||
} else {
|
||||
return RenderLoopResult::Ok;
|
||||
panic!("Window no longer exists!");
|
||||
};
|
||||
|
||||
let (new_swapchain, new_images) = match self.swapchain.recreate_with_dimension(self.game_data.dimensions) {
|
||||
Ok(r) => r,
|
||||
// This error tends to happen when the user is manually resizing the window.
|
||||
// Simply restarting the loop is the easiest way to fix this issue.
|
||||
Err(SwapchainCreationError::UnsupportedDimensions) => return RenderLoopResult::Ok,
|
||||
Err(err) => panic!("{:?}", err)
|
||||
Err(SwapchainCreationError::UnsupportedDimensions) => return RenderLoopResult::Reload,
|
||||
Err(err) => panic!("{:?}", err),
|
||||
};
|
||||
|
||||
self.swapchain = new_swapchain;
|
||||
@@ -343,7 +347,7 @@ impl VulkanRenderer {
|
||||
Ok(r) => r,
|
||||
Err(AcquireError::OutOfDate) => {
|
||||
self.recreate_swapchain = true;
|
||||
return RenderLoopResult::Ok;
|
||||
return RenderLoopResult::Reload;
|
||||
},
|
||||
Err(err) => panic!("{:?}", err)
|
||||
};
|
||||
@@ -423,6 +427,11 @@ impl VulkanRenderer {
|
||||
self.game_data.meshes.push(Mesh { vertex_buffer, index_buffer });
|
||||
self.game_data.meshes.len() - 1
|
||||
}
|
||||
|
||||
pub fn add_game_object(self: &mut Self, game_object: GameObject) -> usize {
|
||||
self.game_data.game_objects.push(game_object);
|
||||
self.game_data.game_objects.len() - 1
|
||||
}
|
||||
}
|
||||
|
||||
/// This method is called once during initialization, then again whenever the window is resized
|
||||
@@ -533,6 +542,12 @@ fn create_pipeline<V: vulkano::pipeline::vertex::Vertex>(device: Arc<Device>, re
|
||||
}
|
||||
}
|
||||
|
||||
impl GameObject {
|
||||
pub fn new(mesh: MeshHandle) -> GameObject {
|
||||
GameObject { mesh_index: mesh, model_matrix: Matrix4::identity() }
|
||||
}
|
||||
}
|
||||
|
||||
fn read_shader(vert_path_relative: &str, frag_path_relative: &str) -> Option<(CompiledShaders, Entry)> {
|
||||
let project_root = std::env::current_dir().expect("failed to get root directory");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user