This commit is contained in:
2021-10-22 07:37:38 +02:00
parent c63f7fc556
commit 0ccc56bbad
7 changed files with 18 additions and 13 deletions

3
.gitignore vendored
View File

@@ -81,4 +81,5 @@ fabric.properties
# cusotm # cusotm
build/deploy/ build/deploy/
build/capture/ build/capture/
*.blend1 *.blend1
.idea/

View File

@@ -14,8 +14,8 @@ name = "reload_shaders"
vk_code = "VK_F5" vk_code = "VK_F5"
[[button]] [[button]]
name = "print_framerate" name = "toggle_framerate"
scan_code = 33 vk_code = "VK_F2"
[[button]] [[button]]
name = "button_forward" name = "button_forward"

View File

@@ -14,12 +14,17 @@ impl FpsCounter {
} }
impl Updatable for FpsCounter { impl Updatable for FpsCounter {
fn update(&mut self, _delta_time: f32, _input: &InputState, game_state: &mut GameState, game_objects: &mut Vec<GameObject>, renderer: &mut VulkanRenderer) { fn update(&mut self, _delta_time: f32, input: &InputState, game_state: &mut GameState, game_objects: &mut Vec<GameObject>, renderer: &mut VulkanRenderer) {
if input.button_just_pressed("toggle_framerate") {
let go = &mut game_objects[self.game_object];
go.visible = !go.visible;
}
let update_duration = renderer.game_data.update_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128; let update_duration = renderer.game_data.update_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128;
let render_duration = renderer.game_data.render_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128; let render_duration = renderer.game_data.render_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128;
let other_duration = renderer.game_data.other_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128; let other_duration = renderer.game_data.other_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128;
let other_variance = renderer.game_data.other_perf_counters.iter().fold(0, |acc, b| acc + (*b as i128 - other_duration as i128) * (*b as i128 - other_duration as i128)) / PERF_COUNTER_SIZE as i128; let other_variance = renderer.game_data.other_perf_counters.iter().fold(0, |acc, b| acc + (*b as i128 - other_duration as i128) * (*b as i128 - other_duration as i128)) / PERF_COUNTER_SIZE as i128;
let text = format!("Update: {:.0}ms\nRender: {:.0}ms\nTotal: {:.0}ms (±{:.1})\nDelta: {:.0}ms", update_duration as f64 / 1000., render_duration as f64 / 1000., other_duration as f64 / 1000., f64::sqrt(other_variance as f64) / 1000., _delta_time * 1000.); let text = format!("Update: {:.0}ms\nRender: {:.0}ms\nTotal: {:.0}ms (±{:.1})\nDelta: {:.0}ms", update_duration as f64 / 1000., render_duration as f64 / 1000., other_duration as f64 / 1000., f64::sqrt(other_variance as f64) / 1000., _delta_time * 1000.);
update_text(self.game_object, &text, 30., renderer, &mut game_state.brush, game_objects) update_text(self.game_object, &text, 30., renderer, &mut game_state.brush, game_objects);
} }
} }

View File

@@ -12,7 +12,7 @@ use crate::{config::LogConfig, vulkan};
use crate::input::InputState; use crate::input::InputState;
use crate::vulkan::{Game, MeshHandle, TextVertex, Vertex, VulkanRenderer}; use crate::vulkan::{Game, MeshHandle, TextVertex, Vertex, VulkanRenderer};
use crate::vulkan::gameobject::{GameObject, GameObjectHandle, Updatable}; use crate::vulkan::gameobject::{GameObject, GameObjectHandle, Updatable};
use crate::vulkan::mesh::{self}; use crate::vulkan::mesh;
use crate::vulkan::pipelines::vs::ty::ObjectUniformData; use crate::vulkan::pipelines::vs::ty::ObjectUniformData;
pub mod player; pub mod player;
@@ -95,10 +95,6 @@ impl Game for TestGame {
load_level("levels/test.lvl", self, renderer).unwrap(); load_level("levels/test.lvl", self, renderer).unwrap();
} }
if self.input.button_down("print_framerate") {
println!("{:?}", renderer.game_data.other_perf_counters);
}
if self.input.button_just_pressed("test") { if self.input.button_just_pressed("test") {
self.game_state.paused = !self.game_state.paused; self.game_state.paused = !self.game_state.paused;
} }
@@ -216,7 +212,7 @@ impl TestGame {
} }
} }
pub fn print_quat_as_euler(quat: Quaternion<f32>) { pub fn _print_quat_as_euler(quat: Quaternion<f32>) {
let euler = Euler::from(quat); let euler = Euler::from(quat);
print!("({:?},{:?},{:?})", Deg::from(euler.x), Deg::from(euler.y), Deg::from(euler.z)); print!("({:?},{:?},{:?})", Deg::from(euler.x), Deg::from(euler.y), Deg::from(euler.z));
} }

View File

@@ -1,4 +1,5 @@
#[cfg(test)] #[cfg(test)]
#[allow(deprecated)]
mod tests { mod tests {
use cgmath::{vec3}; use cgmath::{vec3};
use winit::{dpi::PhysicalPosition, event::{DeviceId, ElementState, Event, Force, KeyboardInput, ModifiersState, Touch, TouchPhase, WindowEvent}, window::WindowId}; use winit::{dpi::PhysicalPosition, event::{DeviceId, ElementState, Event, Force, KeyboardInput, ModifiersState, Touch, TouchPhase, WindowEvent}, window::WindowId};

View File

@@ -20,6 +20,7 @@ pub struct GameObject {
pub descriptor_sets: Vec<Arc<RendererDescriptorSets>>, pub descriptor_sets: Vec<Arc<RendererDescriptorSets>>,
pub is_selected: bool, pub is_selected: bool,
pub pipeline_index: usize, pub pipeline_index: usize,
pub visible: bool,
} }
#[derive(Clone)] #[derive(Clone)]
@@ -37,7 +38,7 @@ impl GameObject {
GameObject { mesh_index: mesh.index, textures, position: Vector3::new(0.0, 0.0, 0.0), GameObject { mesh_index: mesh.index, textures, position: Vector3::new(0.0, 0.0, 0.0),
rotation: Quaternion::new(1.0, 0.0, 0.0, 0.0), scale: Vector3::new(1.0, 1.0, 1.0), children: vec![], rotation: Quaternion::new(1.0, 0.0, 0.0, 0.0), scale: Vector3::new(1.0, 1.0, 1.0), children: vec![],
descriptor_sets: vec![], is_selected: false, pipeline_index: mesh.pipeline_index } descriptor_sets: vec![], is_selected: false, pipeline_index: mesh.pipeline_index, visible: true }
} }
pub fn init_descriptor_sets(&mut self, renderer: &mut VulkanRenderer) { pub fn init_descriptor_sets(&mut self, renderer: &mut VulkanRenderer) {

View File

@@ -335,7 +335,8 @@ impl VulkanRenderer {
// Draw meshes etc. // Draw meshes etc.
let mut index = 0; let mut index = 0;
for pipeline in &self.pipelines { for pipeline in &self.pipelines {
pipeline.draw(&mut builder, fb_index, game_objects.iter().filter(|go| go.pipeline_index == index).collect(), &self.game_data, &self.dynamic_state); let objects = game_objects.iter().filter(|go| go.visible && go.pipeline_index == index).collect();
pipeline.draw(&mut builder, fb_index, objects, &self.game_data, &self.dynamic_state);
index += 1; index += 1;
} }