parse input from file
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -7,7 +7,7 @@ use crate::input::{InputState, VirtualButton, DigitalInput, VirtualAxis, AxisInp
|
||||
mod vulkan;
|
||||
mod input;
|
||||
|
||||
const PRINT_KEYBOARD_INPUT: bool = false;
|
||||
const PRINT_KEYBOARD_INPUT: bool = true;
|
||||
|
||||
struct TestGame {
|
||||
input: InputState,
|
||||
@@ -16,6 +16,18 @@ struct TestGame {
|
||||
|
||||
impl Game for TestGame {
|
||||
fn update(self: &mut Self, game_data: &mut GameData) {
|
||||
// User interaction
|
||||
if self.input.button_down("QUIT") {
|
||||
game_data.shutdown = true;
|
||||
}
|
||||
|
||||
if self.input.button_just_pressed("RELOAD_SHADERS") {
|
||||
game_data.recreate_pipeline = true;
|
||||
}
|
||||
|
||||
self.cam_pos.x += self.input.get_axis("FORWARD");
|
||||
|
||||
// Move game objects
|
||||
game_data.push_constants.time = game_data.start_time.elapsed().unwrap().as_millis() as f32 / 1000.0;
|
||||
|
||||
let model = Matrix4::from_angle_z(Rad::from(Deg(game_data.push_constants.time * 100.0)));
|
||||
@@ -40,6 +52,8 @@ impl Game for TestGame {
|
||||
game_data.push_constants.projection = proj.into();
|
||||
game_data.line_push_constants.view = view.into();
|
||||
game_data.line_push_constants.projection = proj.into();
|
||||
|
||||
self.input.frame_end();
|
||||
}
|
||||
|
||||
fn on_window_event(self: &mut Self, game_data: &mut GameData, event: &Event) {
|
||||
@@ -59,13 +73,6 @@ impl Game for TestGame {
|
||||
}
|
||||
|
||||
self.input.on_keyboard_event(input.state, input.scancode, input.modifiers);
|
||||
|
||||
if input.state == ElementState::Released && input.modifiers.ctrl && input.scancode == 19 {
|
||||
game_data.recreate_pipeline = true;
|
||||
}
|
||||
if self.input.button_down("QUIT") {
|
||||
game_data.shutdown = true;
|
||||
}
|
||||
},
|
||||
// Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
|
||||
//
|
||||
@@ -77,13 +84,10 @@ impl Game for TestGame {
|
||||
|
||||
fn main() {
|
||||
let mut game = TestGame {
|
||||
input: InputState::new(),
|
||||
input: InputState::new("config/input.toml"),
|
||||
cam_pos: Point3::new(2.0, 2.0, 2.0)
|
||||
};
|
||||
|
||||
game.input.virtual_buttons.insert("QUIT".to_string(), VirtualButton { digital_inputs: vec![DigitalInput::simple_key(1)] });
|
||||
game.input.virtual_axes.insert("FORWARD_CAM_AXIS".to_string(), VirtualAxis { analog_inputs: vec![AxisInput::Digital(DigitalInput::simple_key(87), DigitalInput::simple_key(83))] });
|
||||
|
||||
vulkan::init(
|
||||
"models/iski51.obj",
|
||||
(-10..10)
|
||||
|
||||
Reference in New Issue
Block a user