better inputs, log config
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -1,23 +1,26 @@
|
||||
use crate::vulkan::{GameData, Game, LinePoint};
|
||||
use winit::{Event, WindowEvent, ElementState};
|
||||
use winit::{Event, WindowEvent};
|
||||
use std::iter::FromIterator;
|
||||
use cgmath::{Matrix4, Rad, Point3, Vector3, Deg};
|
||||
use crate::input::{InputState, VirtualButton, DigitalInput, VirtualAxis, AxisInput};
|
||||
|
||||
mod vulkan;
|
||||
mod input;
|
||||
use crate::vulkan::{GameData, Game, LinePoint};
|
||||
|
||||
const PRINT_KEYBOARD_INPUT: bool = true;
|
||||
mod input;
|
||||
use crate::input::{InputState};
|
||||
|
||||
mod config;
|
||||
use crate::config::LogConfig;
|
||||
|
||||
struct TestGame {
|
||||
input: InputState,
|
||||
cam_pos: Point3<f32>
|
||||
cam_pos: Point3<f32>,
|
||||
log_config: LogConfig,
|
||||
}
|
||||
|
||||
impl Game for TestGame {
|
||||
fn update(self: &mut Self, game_data: &mut GameData) {
|
||||
// User interaction
|
||||
if self.input.button_down("QUIT") {
|
||||
if self.input.button_just_released("QUIT") {
|
||||
game_data.shutdown = true;
|
||||
}
|
||||
|
||||
@@ -56,10 +59,10 @@ impl Game for TestGame {
|
||||
self.input.frame_end();
|
||||
}
|
||||
|
||||
fn on_window_event(self: &mut Self, game_data: &mut GameData, event: &Event) {
|
||||
fn on_window_event(self: &mut Self, event: &Event) {
|
||||
match event {
|
||||
Event::WindowEvent { event: WindowEvent::KeyboardInput { device_id, input }, .. } => {
|
||||
if PRINT_KEYBOARD_INPUT {
|
||||
if self.log_config.input {
|
||||
let mods = String::from_iter(
|
||||
vec!["shift", "ctrl", "alt", "logo"].iter()
|
||||
.zip(vec![input.modifiers.shift, input.modifiers.ctrl, input.modifiers.alt, input.modifiers.logo])
|
||||
@@ -85,7 +88,8 @@ impl Game for TestGame {
|
||||
fn main() {
|
||||
let mut game = TestGame {
|
||||
input: InputState::new("config/input.toml"),
|
||||
cam_pos: Point3::new(2.0, 2.0, 2.0)
|
||||
cam_pos: Point3::new(2.0, 2.0, 2.0),
|
||||
log_config: LogConfig::from_file("config/log.toml"),
|
||||
};
|
||||
|
||||
vulkan::init(
|
||||
|
||||
Reference in New Issue
Block a user