improvements
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
use crate::{input::InputState, text::update_text, vulkan::{PERF_COUNTER_SIZE, VulkanRenderer, gameobject::{GameObject, GameObjectHandle, Updatable}}};
|
||||
use crate::{input::InputState, text::{create_text_object, update_text}, vulkan::{PERF_COUNTER_SIZE, VulkanRenderer, gameobject::{GameObject, GameObjectHandle, Updatable}}};
|
||||
|
||||
use super::GameState;
|
||||
use super::{GameState, TestGame};
|
||||
|
||||
pub struct FpsCounter {
|
||||
pub game_object: GameObjectHandle
|
||||
}
|
||||
|
||||
impl FpsCounter {
|
||||
pub fn new(game: &mut TestGame, renderer: &mut VulkanRenderer) -> Box<FpsCounter> {
|
||||
let text_mesh = create_text_object(&mut game.game_state.brush, renderer, "", 30.);
|
||||
Box::new(FpsCounter { game_object: game.add_game_object(renderer, text_mesh) })
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
let update_duration = renderer.game_data.update_perf_counters.iter().sum::<u128>() / PERF_COUNTER_SIZE as u128;
|
||||
|
||||
@@ -7,7 +7,7 @@ use level::{load_level, save_level};
|
||||
use player::Player;
|
||||
|
||||
use crate::game::components::FpsCounter;
|
||||
use crate::text::{create_brush, create_text_object};
|
||||
use crate::text::create_brush;
|
||||
use crate::{config::LogConfig, vulkan};
|
||||
use crate::input::InputState;
|
||||
use crate::vulkan::{Game, MeshHandle, TextVertex, Vertex, VulkanRenderer};
|
||||
@@ -151,11 +151,11 @@ impl TestGame {
|
||||
|
||||
pub fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
||||
load_level("levels/test.lvl", self, renderer).unwrap();
|
||||
println!("Game loaded!");
|
||||
|
||||
let text_mesh = create_text_object(&mut self.game_state.brush, renderer, "aaxx", 30.);
|
||||
let fps = Box::new(FpsCounter { game_object: self.add_game_object(renderer, text_mesh) });
|
||||
let fps = FpsCounter::new(self, renderer);
|
||||
self.components.push(fps);
|
||||
|
||||
println!("Game loaded!");
|
||||
}
|
||||
|
||||
pub fn offset_texture_id(&mut self, local_tex_id: Option<usize>) -> usize {
|
||||
|
||||
@@ -213,8 +213,7 @@ impl Updatable for Player {
|
||||
if self.movement_mode == FirstPerson {
|
||||
let mut world_input = self.camera.local_to_world(local_input);
|
||||
world_input.y = 0.0;
|
||||
self.camera.position += world_input.normalize();
|
||||
self.camera.position.y = self.height;
|
||||
self.camera.position += world_input;
|
||||
} else if self.movement_mode == Flying {
|
||||
self.camera.position += self.camera.local_to_world(local_input);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,13 @@ pub fn create_text_object(brush: &mut GlyphBrush<Vec<TextVertex>>, renderer: &mu
|
||||
uploaded_texture = update_text_texture(None, renderer, rect, text_data);
|
||||
}, convert_vertices) {
|
||||
Ok(BrushAction::Draw(quads)) => {
|
||||
uploaded_mesh = update_text_quads(quads, uploaded_texture.unwrap(), None, renderer);
|
||||
let t = if let Some(tex) = uploaded_texture {
|
||||
tex
|
||||
} else {
|
||||
let brush_size = brush.texture_dimensions();
|
||||
update_text_texture(None, renderer, Rectangle { min: [0, 0], max: [brush_size.0, brush_size.1] }, &[]).unwrap()
|
||||
};
|
||||
uploaded_mesh = update_text_quads(quads, t, None, renderer);
|
||||
},
|
||||
Ok(BrushAction::ReDraw) => {},
|
||||
Err(BrushError::TextureTooSmall { suggested }) => {
|
||||
|
||||
Reference in New Issue
Block a user