input stuff

This commit is contained in:
2021-10-14 07:30:12 +02:00
parent 3d449456e6
commit 35f3d0e4a8
4 changed files with 72 additions and 51 deletions

View File

@@ -12,9 +12,9 @@ use player::Player;
use crate::{config::LogConfig, vulkan};
use crate::input::InputState;
use crate::vulkan::{Game, MeshHandle, TextVertex, Texture, TextureHandle, Vertex, VulkanRenderer};
use crate::vulkan::{Game, MeshHandle, TextVertex, TextureHandle, Vertex, VulkanRenderer};
use crate::vulkan::gameobject::{GameObject, GameObjectHandle, Updatable};
use crate::vulkan::mesh::{self, CPUMesh, CPUVertex};
use crate::vulkan::mesh::{self, CPUMesh, CPUVertexList};
use crate::vulkan::pipelines::vs::ty::ObjectUniformData;
pub mod player;
@@ -30,7 +30,8 @@ pub struct TestGame {
pub last_time: f32,
pub components: Vec<Box<dyn Updatable>>,
pub paused: bool,
pub font: FontArc
pub font: FontArc,
pub test_str: String,
}
impl Game for TestGame {
@@ -82,10 +83,17 @@ impl Game for TestGame {
}
if self.input.button_just_pressed("test") {
// self.paused = !self.paused;
self.text_objects[0].update_text("holy shit look at this", 200.0, renderer, &mut self.game_objects);
self.paused = !self.paused;
}
for char in self.input.typed_characters.iter() {
match char {
'\u{8}' => { self.test_str.pop(); },
c => { self.test_str.push(*c); },
}
}
self.text_objects[0].update_text(&self.test_str, 30., renderer, &mut self.game_objects);
// Custom game object stuff
let light_pos = vec3(2.0, 0.5, 2.0);
if !self.paused {
@@ -124,6 +132,7 @@ impl TestGame {
components: vec![],
paused: false,
font: FontArc::try_from_slice(include_bytes!("../../models/FiraCode-Regular.ttf")).unwrap(),
test_str: String::new()
}
}
@@ -255,17 +264,18 @@ pub fn update_text_quads(quads: Vec<Vec<TextVertex>>, texture_index: usize, mesh
let mut final_indices: Vec<u32> = vec![];
let mut index_offset = 0;
for quad in quads {
final_vertices.append(&mut quad.iter().map(|v| CPUVertex::VertexText(TextVertex { position: v.position, uv: [v.uv[0], v.uv[1]] })).collect());
for mut quad in quads {
let len = quad.len();
final_vertices.append(&mut quad);
final_indices.append(&mut [0, 2, 3, 0, 3, 1].iter().map(|x| *x + index_offset).collect());
index_offset += quad.len() as u32;
index_offset += len as u32;
}
if let Some(idx) = mesh_index {
renderer.update_mesh(idx, final_vertices, final_indices);
renderer.update_mesh(idx, CPUVertexList::VertexText(final_vertices), final_indices);
None
} else {
let mesh = CPUMesh {
vertices: final_vertices,
vertices: CPUVertexList::VertexText(final_vertices),
indices: final_indices,
local_texture_index: Some(texture_index),
local_normal_map_index: None,